int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { int i; int ret; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite(suite_name); if (!suite) { ms_error("Could not find suite '%s'. Available suites are:", suite_name); liblinphone_tester_list_suites(); return -1; } else if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); if (!test) { ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); // do not use suite_name here, since this method is case sentisitive liblinphone_tester_list_suite_tests(suite->pName); return -2; } else { CU_ErrorCode err= CU_basic_run_test(suite, test); if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); } } else { CU_basic_run_suite(suite); } } else { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } ret=CU_get_number_of_tests_failed()!=0; /* Redisplay list of failed tests on end */ if (CU_get_number_of_failure_records()){ CU_basic_show_failures(CU_get_failure_list()); printf("\n"); } CU_cleanup_registry(); return ret; }
/* MAIN */ int main(void) { CU_pSuite ste = NULL; if (CUE_SUCCESS != CU_initialize_registry()) { return CU_get_error(); } ste = CU_add_suite("sllist_suite", init_sllist_suite, clean_sllist1_suite); if (NULL == ste) { CU_cleanup_registry(); return CU_get_error(); } ADD_TEST(CU_add_test(ste, "Verify insert...", t_insert)); // CU_console_run_tests(); CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_suite(ste); CU_basic_show_failures(CU_get_failure_list()); CU_cleanup_registry(); printf("\n"); return CU_get_error(); }
int main (int argc, char* argv[]) { if (CU_initialize_registry() != CUE_SUCCESS) { printf("Failed to initialize registry!\n"); exit(-1); } CU_pSuite suite = CU_add_suite("suite for makeMemory", NULL, NULL); if (suite == NULL) { printf("Failed to add suite!\n"); exit(-1); } // add tests CU_TestInfo tests[] = { { "test func----registryMemoryType()", registerMemoryType_ShouldReturnMinusOninvalidParam }, { "test func----registerMemoryType()", registerMemoryType_ShouldReturnPositiveOnSuccess }, { "test func----registerMemoryType()", registerMemoryType_ShouldReturnZeroOnSameType }, { "test func----registerMemoryType()", registryMemoryType_ShouldRegisterOnExceedsSize }, { "test func----registerMemoryType()", registerMemoryType_ShouldInAscendentOrder }, { "test func----registerUniqueType()", registerUniqueType_ShouldWorkRight }, { "test func----makeMemoryBlock()", makeMemoryBlock_ShouldReturnNullOnNegativeBytes }, { "test func----makeMemoryBlock()", makeMemoryBlock_ShouldSetHeadToFormer }, { "test func----freeMemoryChain()", freeMemoryChain_ShoudSetHeadToNullAfterFree }, { "test func----freeMemoryChain()", freeMemoryChain_ShouldHaveNoSideEffectOnTwiceFree }, { "test func----findMemoryBlock()", findMemoryBlock_ShouldReturnNullForNonePositiveParam }, { "test func----findMemoryBlock()", findMemoryBlock_ShouldReturnNullForTypeNotContained }, { "test func----findMemoryBlock()", findMemoryBlock_ShouldFindNextMemoryBlockOfType } }; for (unsigned i = 0; i < (sizeof(tests) / sizeof(tests[0])); ++i) if (CU_add_test(suite, tests[i].pName, tests[i].pTestFunc) == NULL) { printf("attempt to add tests, failed!\n"); exit(-1); } if (CU_basic_run_suite(suite) != CUE_SUCCESS) { printf("Failed to run suite!\n"); exit(-1); } CU_cleanup_registry(); freeMemoryChain(); return 0; }
/* MAIN */ int main(void) { fprintf(stderr, "I'm here!\n"); CU_pSuite ste = NULL; if (CUE_SUCCESS != CU_initialize_registry()) { return CU_get_error(); } ste = CU_add_suite("mutable_string_suite", init_mutable_string_suite, clean_mutable_string_suite); if (NULL == ste) { CU_cleanup_registry(); return CU_get_error(); } if (CU_get_error() != CUE_SUCCESS) { fprintf(stderr, "Error creating suite: (%d)%s\n", CU_get_error(), CU_get_error_msg()); } ADD_TEST(CU_add_test(ste, "Verify mutable_string_init()...", t_mutable_string_init)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_init_with_value()...", t_mutable_string_init_with_value)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_resize()...", t_mutable_string_resize)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_assign()...", t_mutable_string_assign)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_append()...", t_mutable_string_append)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_copy()...", t_mutable_string_copy)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_append_mutable_string()...", t_mutable_string_append_mutable_string)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_append_char()...", t_mutable_string_append_char)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_char_at()...", t_mutable_string_char_at)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_substring()...", t_mutable_string_substring)); ADD_TEST(CU_add_test(ste, "Verify mutable_string_int64/32/16()...", t_mutable_string_parse_int)); // if (CU_get_error() != CUE_SUCCESS) { fprintf(stderr, "Error creating suite: (%d)%s\n", CU_get_error(), CU_get_error_msg()); // } // CU_console_run_tests(); CU_basic_set_mode(CU_BRM_VERBOSE); CU_ErrorCode run_errors = CU_basic_run_suite(ste); if (run_errors != CUE_SUCCESS) { fprintf(stderr, "Error running tests: (%d)%s\n", run_errors, CU_get_error_msg()); } CU_basic_show_failures(CU_get_failure_list()); CU_cleanup_registry(); printf("\n"); printf("I'm done!\n"); return CU_get_error(); }
int main(void) { CU_pSuite pSuite = NULL; /* initialize the CUnit test registry */ if ( CUE_SUCCESS != CU_initialize_registry() ) return CU_get_error(); /* add a suite to the registry */ pSuite = CU_add_suite( "revcomp_test_suite", init_suite, clean_suite ); if ( NULL == pSuite ) { CU_cleanup_registry(); return CU_get_error(); } /* add the tests to the suite */ if ( (NULL == CU_add_test(pSuite, "test_initseq", test_initseq)) || (NULL == CU_add_test(pSuite, "test_growseq", test_growseq)) || (NULL == CU_add_test(pSuite, "test_reverse_str", test_reverse_str)) || (NULL == CU_add_test(pSuite, "test_complement", test_complement)) ) { CU_cleanup_registry(); return CU_get_error(); } // Run all tests using the basic interface CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_suite(pSuite); printf("\n"); CU_basic_show_failures(CU_get_failure_list()); printf("\n\n"); /* // Run all tests using the automated interface CU_automated_run_tests(); CU_list_tests_to_file(); // Run all tests using the console interface CU_console_run_tests(); */ /* Clean up registry and return */ CU_cleanup_registry(); return CU_get_error(); }
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { int i; int ret; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite_by_name(suite_name, CU_get_registry()); if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); CU_ErrorCode err= CU_basic_run_test(suite, test); if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); } else CU_basic_run_suite(suite); } else { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } ret=CU_get_number_of_tests_failed()!=0; CU_cleanup_registry(); return ret; }
int mediastreamer2_tester_run_tests(const char *suite_name, const char *test_name) { int i; /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); for (i = 0; i < mediastreamer2_tester_nb_test_suites(); i++) { run_test_suite(test_suite[i]); } #if HAVE_CU_GET_SUITE if (suite_name){ CU_pSuite suite; CU_basic_set_mode(CU_BRM_VERBOSE); suite=CU_get_suite(suite_name); if (test_name) { CU_pTest test=CU_get_test_by_name(test_name, suite); CU_basic_run_test(suite, test); } else CU_basic_run_suite(suite); } else #endif { #if HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); } else #endif { /* Run all tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); } } CU_cleanup_registry(); return CU_get_error(); }
/* Run test suite */ int main(void) { CU_pSuite ps_board = NULL; CU_pSuite ps_game = NULL; CU_pSuite ps_move = NULL; /* initialise CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) { return CU_get_error(); } /* Add suites */ if(!(ps_board = CU_add_suite("board.h tests", NULL, NULL))) { CU_cleanup_registry(); return CU_get_error(); } if(!(ps_game = CU_add_suite("game.h tests", NULL, NULL))) { CU_cleanup_registry(); return CU_get_error(); } if(!(ps_move = CU_add_suite("move.h tests", NULL, NULL))) { CU_cleanup_registry(); return CU_get_error(); } /* Add tests to the ps_board suite */ CU_add_test(ps_board, "test_board_init", test_board_init); CU_add_test(ps_board, "test_board_set_point", test_board_set_point); CU_add_test(ps_board, "test_board_get_point", test_board_get_point); /* Add tests to the ps_game suite */ CU_add_test(ps_game, "test_winner_is", test_winner_is); CU_add_test(ps_game, "test_get_current_player", test_get_current_player); CU_add_test(ps_game, "test_get_last_player", test_get_last_player); CU_add_test(ps_game, "test_human_player", test_human_player); CU_add_test(ps_game, "test_computer_player", test_computer_player); CU_add_test(ps_game, "test_get_user_input", test_get_user_input); CU_add_test(ps_game, "test_get_window", test_get_window); /* Add tests to the ps_move suite */ CU_add_test(ps_move, "test_valid_move", test_valid_move); CU_add_test(ps_move, "test_valid_moves_left", test_valid_moves_left); CU_add_test(ps_move, "test_make_move", test_make_move); CU_add_test(ps_move, "test_get_reasoned_move", test_get_reasoned_move); CU_add_test(ps_move, "test_undo_move", test_undo_move); CU_add_test(ps_move, "test_get_score", test_get_score); CU_add_test(ps_move, "test_get_strength", test_get_strength); CU_add_test(ps_move, "test_min_value", test_min_value); /* Set the basic run mode and run all suites */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_suite(ps_board); CU_basic_run_suite(ps_game); CU_basic_run_suite(ps_move); /* Cleanup and exit */ CU_cleanup_registry(); return CU_get_error(); }
/* Required calls to CUnit. Test will be registered */ int main(int argc, char **argv){ /* Initialize and build a Testsuite */ CU_pSuite pSuite = NULL; if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); /* Creation of the main test suite */ pSuite = CU_add_suite("Dynamic C-Heap Structures", init_test_dyn_str, clean_test_dyn_str); if (NULL == pSuite){ CU_cleanup_registry(); return CU_get_error(); } /* Add tests */ if((NULL == CU_add_test(pSuite, "Creation of structs", test_init)) || (NULL == CU_add_test(pSuite, "Voidpointer test", test_voidp)) || (NULL == CU_add_test(pSuite, "Sizeof test", test_sizeof)) || (NULL == CU_add_test(pSuite, "Member adding test 1", test_creation_normal1)) || (NULL == CU_add_test(pSuite, "Member adding test 2", test_creation_normal2)) || (NULL == CU_add_test(pSuite, "Member adding test with alignment", test_creation_aligned)) || (NULL == CU_add_test(pSuite, "Member adding test with nested structs", test_creation_nested)) || (NULL == CU_add_test(pSuite, "Second member adding test with nested structs", test_creation_nested_2)) || (NULL == CU_add_test(pSuite, "Padding test with alignment", test_padding_aligned)) || (NULL == CU_add_test(pSuite, "Padding test with platform alignment", test_padding_normal))) { CU_cleanup_registry(); return CU_get_error(); } printf("\nSome sizeof considerations...\n"); printf("sizeof(nested_1) :%ld\n", sizeof(struct nested_1)); printf("sizeof(nested_2) :%ld\n", sizeof(struct nested_2)); printf("sizeof(nested_3) :%ld\n", sizeof(struct nested_3)); printf("sizeof(nested_3_part_1) :%ld\n", sizeof(struct nested_3_part_1)); printf("sizeof(nested_3_part_2) :%ld\n", sizeof(struct nested_3_part_2)); printf("sizeof(nested_4) :%ld\n", sizeof(struct nested_4)); /* misc configuration */ CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_suite(pSuite); if (CU_get_number_of_tests_failed()) return EXIT_FAILURE; CU_cleanup_registry(); return CU_get_error(); }
/* The main() function for setting up and running the tests. * Returns a CUE_SUCCESS on successful running, another * CUnit error code on failure. */ int main(int argc, char **argv) { int c; /* Character received from getopt */ int i = 0; int suite_id = -1; /* By default run everything */ int test_id = -1; /* By default run all tests in the suite */ int pci_bus_id = -1; /* By default PC bus ID is not specified */ int pci_device_id = 0; /* By default PC device ID is zero */ int display_devices = 0;/* By default not to display devices' info */ CU_pSuite pSuite = NULL; CU_pTest pTest = NULL; int test_device_index; int display_list = 0; int force_run = 0; for (i = 0; i < MAX_CARDS_SUPPORTED; i++) drm_amdgpu[i] = -1; /* Parse command line string */ opterr = 0; /* Do not print error messages from getopt */ while ((c = getopt(argc, argv, options)) != -1) { switch (c) { case 'l': display_list = 1; break; case 's': suite_id = atoi(optarg); break; case 't': test_id = atoi(optarg); break; case 'b': pci_bus_id = atoi(optarg); break; case 'd': sscanf(optarg, "%x", &pci_device_id); break; case 'p': display_devices = 1; break; case 'r': open_render_node = 1; break; case 'f': force_run = 1; break; case '?': case 'h': fprintf(stderr, usage, argv[0]); exit(EXIT_SUCCESS); default: fprintf(stderr, usage, argv[0]); exit(EXIT_FAILURE); } } if (amdgpu_open_devices(open_render_node) <= 0) { perror("Cannot open AMDGPU device"); exit(EXIT_FAILURE); } if (drm_amdgpu[0] < 0) { perror("Cannot open AMDGPU device"); exit(EXIT_FAILURE); } if (display_devices) { amdgpu_print_devices(); amdgpu_close_devices(); exit(EXIT_SUCCESS); } if (pci_bus_id > 0 || pci_device_id) { /* A device was specified to run the test */ test_device_index = amdgpu_find_device(pci_bus_id, pci_device_id); if (test_device_index >= 0) { /* Most tests run on device of drm_amdgpu[0]. * Swap the chosen device to drm_amdgpu[0]. */ i = drm_amdgpu[0]; drm_amdgpu[0] = drm_amdgpu[test_device_index]; drm_amdgpu[test_device_index] = i; } else { fprintf(stderr, "The specified GPU device does not exist.\n"); exit(EXIT_FAILURE); } } /* Initialize test suites to run */ /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) { amdgpu_close_devices(); return CU_get_error(); } /* Register suites. */ if (CU_register_suites(suites) != CUE_SUCCESS) { fprintf(stderr, "suite registration failed - %s\n", CU_get_error_msg()); CU_cleanup_registry(); amdgpu_close_devices(); exit(EXIT_FAILURE); } /* Run tests using the CUnit Basic interface */ CU_basic_set_mode(CU_BRM_VERBOSE); /* Disable suites and individual tests based on misc. conditions */ amdgpu_disable_suites(); if (display_list) { display_test_suites(); goto end; } if (suite_id != -1) { /* If user specify particular suite? */ pSuite = CU_get_suite_by_index((unsigned int) suite_id, CU_get_registry()); if (pSuite) { if (force_run) CU_set_suite_active(pSuite, CU_TRUE); if (test_id != -1) { /* If user specify test id */ pTest = CU_get_test_by_index( (unsigned int) test_id, pSuite); if (pTest) { if (force_run) CU_set_test_active(pTest, CU_TRUE); CU_basic_run_test(pSuite, pTest); } else { fprintf(stderr, "Invalid test id: %d\n", test_id); CU_cleanup_registry(); amdgpu_close_devices(); exit(EXIT_FAILURE); } } else CU_basic_run_suite(pSuite); } else { fprintf(stderr, "Invalid suite id : %d\n", suite_id); CU_cleanup_registry(); amdgpu_close_devices(); exit(EXIT_FAILURE); } } else CU_basic_run_tests(); end: CU_cleanup_registry(); amdgpu_close_devices(); return CU_get_error(); }