static void test_file(const char *filename) { int size, i; char **list_str; char *content, *tmp; struct CMUnitTest *tests; int issue_num, number_of_tests; printf("[+] TARGET: %s\n", filename); content = readfile(filename); counter = 0; failed_setup = 0; function = NULL; if (strstr(filename, "issue")) { number_of_tests = 0; list_lines = split(content, "\n", &size_lines); tests = NULL; for (i = 0; i < size_lines; ++i) { if ((!strncmp(list_lines[i], "// !# issue", 11) && e_flag == 1) || (!strncmp(list_lines[i], "!# issue", 8) && e_flag == 0)) { tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1)); tests[number_of_tests] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_issue, setup_issue, teardown_issue); tests[number_of_tests].name = strdup(list_lines[i]); number_of_tests ++; } } _cmocka_run_group_tests("Testing issues", tests, number_of_tests, NULL, NULL); } else { list_lines = split(content, "\n", &size_lines); number_of_tests = 0; tests = NULL; for (i = 1; i < size_lines; ++i) { if ((!strncmp(list_lines[i], "// 0x", 5) && e_flag == 1) || (!strncmp(list_lines[i], "0x", 2) && e_flag == 0)) { tmp = (char *)malloc(sizeof(char) * 100); sprintf(tmp, "Line %d", i+1); tests = (struct CMUnitTest *)realloc(tests, sizeof(struct CMUnitTest) * (number_of_tests + 1)); tests[number_of_tests] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_MC, setup_MC, teardown_MC); tests[number_of_tests].name = tmp; number_of_tests ++; } } _cmocka_run_group_tests("Testing MC", tests, number_of_tests, NULL, NULL); } printf("[+] DONE: %s\n", filename); printf("[!] Noted:\n[ ERROR ] --- \"<capstone result>\" != \"<user result>\"\n"); printf("\n\n"); free_strs(list_lines, size_lines); }
/* * Runs group of tests and clears tests at the end */ static int _runTestGroup(char **pzGroupTitle, Array_t *tests) { if (tests->iCnt == 0) return SQLITE_OK; if (!*pzGroupTitle) *pzGroupTitle = "SQL Tests"; int result = _cmocka_run_group_tests(*pzGroupTitle, (void *) tests->items, tests->iCnt, _testGroupSetup, _testGroupTeardown ); Array_clear(tests); return result; }