aboutsummaryrefslogtreecommitdiff
path: root/src/cmocka.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2020-10-05 13:49:41 +0200
committerAndreas Schneider <asn@cryptomilk.org>2020-10-12 08:25:26 +0200
commit1003e764721d82c09bb3584b244e50cd657c8de9 (patch)
tree3da1cb786ec56cf666d0a07181e7196da67f7a92 /src/cmocka.c
parentae89bfa145ebcb3d92c9cc96e681974689b17dee (diff)
downloadcmocka-1003e764721d82c09bb3584b244e50cd657c8de9.tar.gz
cmocka-1003e764721d82c09bb3584b244e50cd657c8de9.tar.xz
cmocka-1003e764721d82c09bb3584b244e50cd657c8de9.zip
cmocka: Remove deprecated functions and cmockery legacy support
Diffstat (limited to 'src/cmocka.c')
-rw-r--r--src/cmocka.c391
1 files changed, 0 insertions, 391 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 0783c4d..479587a 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -3274,394 +3274,3 @@ int _cmocka_run_group_tests(const char *group_name,
return (int)(total_failed + total_errors);
}
-
-/****************************************************************************
- * DEPRECATED TEST RUNNER
- ****************************************************************************/
-
-int _run_test(
- const char * const function_name, const UnitTestFunction Function,
- void ** const volatile state, const UnitTestFunctionType function_type,
- const void* const heap_check_point) {
- const ListNode * const volatile check_point = (const ListNode*)
- (heap_check_point ?
- heap_check_point : check_point_allocated_blocks());
- void *current_state = NULL;
- volatile int rc = 1;
- int handle_exceptions = 1;
-#ifdef _WIN32
- handle_exceptions = !IsDebuggerPresent();
-#endif /* _WIN32 */
-#ifdef UNIT_TESTING_DEBUG
- handle_exceptions = 0;
-#endif /* UNIT_TESTING_DEBUG */
-
- cm_error_message_enabled = 0;
-
- if (handle_exceptions) {
-#ifndef _WIN32
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
- default_signal_functions[i] = signal(
- exception_signals[i], exception_handler);
- }
-#else /* _WIN32 */
- previous_exception_filter = SetUnhandledExceptionFilter(
- exception_filter);
-#endif /* !_WIN32 */
- }
-
- if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
- print_message("[ RUN ] %s\n", function_name);
- }
- initialize_testing(function_name);
- global_running_test = 1;
- if (cm_setjmp(global_run_test_env) == 0) {
- Function(state ? state : &current_state);
- fail_if_leftover_values(function_name);
-
- /* If this is a setup function then ignore any allocated blocks
- * only ensure they're deallocated on tear down. */
- if (function_type != UNIT_TEST_FUNCTION_TYPE_SETUP) {
- fail_if_blocks_allocated(check_point, function_name);
- }
-
- global_running_test = 0;
-
- if (function_type == UNIT_TEST_FUNCTION_TYPE_TEST) {
- print_message("[ OK ] %s\n", function_name);
- }
- rc = 0;
- } else {
- global_running_test = 0;
- print_message("[ FAILED ] %s\n", function_name);
- }
- teardown_testing(function_name);
-
- if (handle_exceptions) {
-#ifndef _WIN32
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(exception_signals); i++) {
- signal(exception_signals[i], default_signal_functions[i]);
- }
-#else /* _WIN32 */
- if (previous_exception_filter) {
- SetUnhandledExceptionFilter(previous_exception_filter);
- previous_exception_filter = NULL;
- }
-#endif /* !_WIN32 */
- }
-
- return rc;
-}
-
-
-int _run_tests(const UnitTest * const tests, const size_t number_of_tests) {
- /* Whether to execute the next test. */
- int run_next_test = 1;
- /* Whether the previous test failed. */
- int previous_test_failed = 0;
- /* Whether the previous setup failed. */
- int previous_setup_failed = 0;
- /* Check point of the heap state. */
- const ListNode * const check_point = check_point_allocated_blocks();
- /* Current test being executed. */
- size_t current_test = 0;
- /* Number of tests executed. */
- size_t tests_executed = 0;
- /* Number of failed tests. */
- size_t total_failed = 0;
- /* Number of setup functions. */
- size_t setups = 0;
- /* Number of teardown functions. */
- size_t teardowns = 0;
- size_t i;
- /*
- * A stack of test states. A state is pushed on the stack
- * when a test setup occurs and popped on tear down.
- */
- TestState* test_states =
- (TestState*)malloc(number_of_tests * sizeof(*test_states));
- /* The number of test states which should be 0 at the end */
- long number_of_test_states = 0;
- /* Names of the tests that failed. */
- const char** failed_names = (const char**)malloc(number_of_tests *
- sizeof(*failed_names));
- void **current_state = NULL;
-
- /* Count setup and teardown functions */
- for (i = 0; i < number_of_tests; i++) {
- const UnitTest * const test = &tests[i];
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_SETUP) {
- setups++;
- }
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_TEARDOWN) {
- teardowns++;
- }
- }
-
- print_message("[==========] Running %"PRIdS " test(s).\n",
- number_of_tests - setups - teardowns);
-
- /* Make sure uintmax_t is at least the size of a pointer. */
- assert_true(sizeof(uintmax_t) >= sizeof(void*));
-
- while (current_test < number_of_tests) {
- const ListNode *test_check_point = NULL;
- TestState *current_TestState;
- const UnitTest * const test = &tests[current_test++];
- if (!test->function) {
- continue;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- if (! previous_setup_failed) {
- run_next_test = 1;
- }
- break;
- case UNIT_TEST_FUNCTION_TYPE_SETUP: {
- /* Checkpoint the heap before the setup. */
- current_TestState = &test_states[number_of_test_states++];
- current_TestState->check_point = check_point_allocated_blocks();
- test_check_point = current_TestState->check_point;
- current_state = &current_TestState->state;
- *current_state = NULL;
- run_next_test = 1;
- break;
- }
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- /* Check the heap based on the last setup checkpoint. */
- assert_true(number_of_test_states);
- current_TestState = &test_states[--number_of_test_states];
- test_check_point = current_TestState->check_point;
- current_state = &current_TestState->state;
- break;
- default:
- print_error("Invalid unit test function type %d\n",
- test->function_type);
- exit_test(1);
- break;
- }
-
- if (run_next_test) {
- int failed = _run_test(test->name, test->function, current_state,
- test->function_type, test_check_point);
- if (failed) {
- failed_names[total_failed] = test->name;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- previous_test_failed = failed;
- total_failed += failed;
- tests_executed ++;
- break;
-
- case UNIT_TEST_FUNCTION_TYPE_SETUP:
- if (failed) {
- total_failed ++;
- tests_executed ++;
- /* Skip forward until the next test or setup function. */
- run_next_test = 0;
- previous_setup_failed = 1;
- }
- previous_test_failed = 0;
- break;
-
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- /* If this test failed. */
- if (failed && !previous_test_failed) {
- total_failed ++;
- }
- break;
- default:
-#ifndef _HPUX
- assert_null("BUG: shouldn't be here!");
-#endif
- break;
- }
- }
- }
-
- print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
- print_error("[ PASSED ] %"PRIdS " test(s).\n", tests_executed - total_failed);
-
- if (total_failed > 0) {
- print_error("[ FAILED ] %"PRIdS " test(s), listed below:\n", total_failed);
- for (i = 0; i < total_failed; i++) {
- print_error("[ FAILED ] %s\n", failed_names[i]);
- }
- } else {
- print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
- }
-
- if (number_of_test_states != 0) {
- print_error("[ ERROR ] Mismatched number of setup %"PRIdS " and "
- "teardown %"PRIdS " functions\n", setups, teardowns);
- total_failed = (size_t)-1;
- }
-
- free(test_states);
- free((void*)failed_names);
-
- fail_if_blocks_allocated(check_point, "run_tests");
- return (int)total_failed;
-}
-
-int _run_group_tests(const UnitTest * const tests, const size_t number_of_tests)
-{
- UnitTestFunction setup = NULL;
- const char *setup_name = NULL;
- size_t num_setups = 0;
- UnitTestFunction teardown = NULL;
- const char *teardown_name = NULL;
- size_t num_teardowns = 0;
- size_t current_test = 0;
- size_t i;
-
- /* Number of tests executed. */
- size_t tests_executed = 0;
- /* Number of failed tests. */
- size_t total_failed = 0;
- /* Check point of the heap state. */
- const ListNode * const check_point = check_point_allocated_blocks();
- const char **failed_names = NULL;
- void **current_state = NULL;
- TestState group_state = {
- .check_point = NULL,
- };
-
- if (number_of_tests == 0) {
- return -1;
- }
-
- failed_names = (const char **)malloc(number_of_tests *
- sizeof(*failed_names));
- if (failed_names == NULL) {
- return -2;
- }
-
- /* Find setup and teardown function */
- for (i = 0; i < number_of_tests; i++) {
- const UnitTest * const test = &tests[i];
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP) {
- if (setup == NULL) {
- setup = test->function;
- setup_name = test->name;
- num_setups = 1;
- } else {
- print_error("[ ERROR ] More than one group setup function detected\n");
- exit_test(1);
- }
- }
-
- if (test->function_type == UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN) {
- if (teardown == NULL) {
- teardown = test->function;
- teardown_name = test->name;
- num_teardowns = 1;
- } else {
- print_error("[ ERROR ] More than one group teardown function detected\n");
- exit_test(1);
- }
- }
- }
-
- print_message("[==========] Running %"PRIdS " test(s).\n",
- number_of_tests - num_setups - num_teardowns);
-
- if (setup != NULL) {
- int failed;
-
- group_state.check_point = check_point_allocated_blocks();
- current_state = &group_state.state;
- *current_state = NULL;
- failed = _run_test(setup_name,
- setup,
- current_state,
- UNIT_TEST_FUNCTION_TYPE_SETUP,
- group_state.check_point);
- if (failed) {
- failed_names[total_failed] = setup_name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
-
- while (current_test < number_of_tests) {
- int run_test = 0;
- const UnitTest * const test = &tests[current_test++];
- if (test->function == NULL) {
- continue;
- }
-
- switch (test->function_type) {
- case UNIT_TEST_FUNCTION_TYPE_TEST:
- run_test = 1;
- break;
- case UNIT_TEST_FUNCTION_TYPE_SETUP:
- case UNIT_TEST_FUNCTION_TYPE_TEARDOWN:
- case UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP:
- case UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN:
- break;
- default:
- print_error("Invalid unit test function type %d\n",
- test->function_type);
- break;
- }
-
- if (run_test) {
- int failed;
-
- failed = _run_test(test->name,
- test->function,
- current_state,
- test->function_type,
- NULL);
- if (failed) {
- failed_names[total_failed] = test->name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
- }
-
- if (teardown != NULL) {
- int failed;
-
- failed = _run_test(teardown_name,
- teardown,
- current_state,
- UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
- group_state.check_point);
- if (failed) {
- failed_names[total_failed] = teardown_name;
- }
-
- total_failed += failed;
- tests_executed++;
- }
-
- print_message("[==========] %"PRIdS " test(s) run.\n", tests_executed);
- print_error("[ PASSED ] %"PRIdS " test(s).\n", tests_executed - total_failed);
-
- if (total_failed) {
- print_error("[ FAILED ] %"PRIdS " test(s), listed below:\n", total_failed);
- for (i = 0; i < total_failed; i++) {
- print_error("[ FAILED ] %s\n", failed_names[i]);
- }
- } else {
- print_error("\n %"PRIdS " FAILED TEST(S)\n", total_failed);
- }
-
- free((void*)failed_names);
- fail_if_blocks_allocated(check_point, "run_group_tests");
-
- return (int)total_failed;
-}