From 9f51a86ba3eeb798733a9b9df9f31f5c25005525 Mon Sep 17 00:00:00 2001 From: HarDToBelieve Date: Tue, 12 Feb 2019 16:07:24 +0700 Subject: [PATCH] fixing --- suite/cstest/report.py | 9 +++++---- suite/cstest/src/capstone_test.c | 21 +++++++++++---------- suite/cstest/src/main.c | 31 ++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/suite/cstest/report.py b/suite/cstest/report.py index 7fa0d045..07bee602 100755 --- a/suite/cstest/report.py +++ b/suite/cstest/report.py @@ -33,18 +33,19 @@ def get_report_file(toolpath, filepath, getDetails): elif 'LINE' in line: continue elif 'ERROR' in line and ' --- ' in line: + parts = line.split(' --- ') try: - details.append((failed_tests[counter], line.split(' --- ')[1])) + details.append((parts[1], failed_tests[counter], parts[2])) except IndexError: - details.append(('Unknown test', line.split(' --- ')[1])) + details.append(('', 'Unknown test', line.split(' --- ')[1])) counter += 1 else: continue print '\n[-] There are/is {} failed test(s)'.format(len(details)) if len(details) > 0 and getDetails: print '[-] Detailed report for {}:\n'.format(filepath) - for f, d in details: - print '\t[+] {}:\n\t\t{}\n'.format(f, d) + for c, f, d in details: + print '\t[+] {}: {}\n\t\t{}\n'.format(f, c, d) print '\n' def get_report_folder(toolpath, folderpath, details): diff --git a/suite/cstest/src/capstone_test.c b/suite/cstest/src/capstone_test.c index 90b213dc..4fcf4f8f 100644 --- a/suite/cstest/src/capstone_test.c +++ b/suite/cstest/src/capstone_test.c @@ -84,14 +84,14 @@ double_dict options[] = { char *(*function)(csh *, cs_mode, cs_insn*) = NULL; -static int quadruple_compare(const char *src1, const char *src2, const char *des1, const char *des2) +static int quadruple_compare(const char *src1, const char *src2, const char *des1, const char *des2, const char *opcode) { if (strcmp(src1, des2) && strcmp(src2, des2) && strcmp(src1, des1) && strcmp(src1, des2)) { - fprintf(stderr,"[ ERROR ] --- \"%s\" != \"%s\"", src1, des2); + fprintf(stderr,"[ ERROR ] --- %s --- \"%s\" != \"%s\"", src2, des2, opcode); if (strcmp(src1, src2)) - fprintf(stderr, " (\"%s\" != \"%s\")", src2, des2); + fprintf(stderr, " (\"%s\" != \"%s\")", src1, des2); else if (strcmp(des1, des2)) - fprintf(stderr, " (\"%s\" != \"%s\")", src1, des1); + fprintf(stderr, " (\"%s\" != \"%s\")", src2, des1); fprintf(stderr, "\n"); return 0; } @@ -133,11 +133,11 @@ void test_single_MC(csh *handle, char *line) // printf("====\nCount: %d\nSize_data: %d\n", count, size_data); // assert_int_equal(size_data, count); if (count == 0) { - fprintf(stderr, "[ ERROR ] --- Failed to disassemble given code!\n"); + fprintf(stderr, "[ ERROR ] --- %s --- Failed to disassemble given code!\n", list_part[0]); _fail(__FILE__, __LINE__); } if (count > 1) { - fprintf(stderr, "[ ERROR ] --- Multiple instructions(%d) disassembling doesn't support!\n", count); + fprintf(stderr, "[ ERROR ] --- %s --- Multiple instructions(%d) disassembling doesn't support!\n", list_part[0], count); _fail(__FILE__, __LINE__); } @@ -159,7 +159,7 @@ void test_single_MC(csh *handle, char *line) // assert_string_equal(tmp, list_data[i]); - if (cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME) == CS_ERR_OK) { + if ( cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME) == CS_ERR_OK ) { count_noreg = cs_disasm(*handle, code, size_byte, offset, 0, &insn); tmp_noreg = (char *)malloc(strlen(insn[0].mnemonic) + strlen(insn[0].op_str) + 100); strcpy(tmp_noreg, insn[0].mnemonic); @@ -177,7 +177,7 @@ void test_single_MC(csh *handle, char *line) if (strcmp(tmp, mc_hex) && strcmp(cs_hex, mc_hex) && strcmp(tmp, mc_dec) && strcmp(tmp, mc_hex) && strcmp(tmp_noreg, mc_hex_noreg) && strcmp(cs_hex_noreg, mc_hex_noreg) && strcmp(tmp_noreg, mc_dec_noreg) && strcmp(tmp_noreg, mc_hex_noreg)) { - fprintf(stderr, "[ ERROR ] --- \"%s\" != \"%s\"\n", tmp, list_data[0]); + fprintf(stderr, "[ ERROR ] --- %s --- \"%s\" != \"%s\"\n", list_part[0], cs_hex, list_data[0]); _fail(__FILE__, __LINE__); } @@ -187,7 +187,8 @@ void test_single_MC(csh *handle, char *line) free(mc_dec_noreg); cs_option(*handle, CS_OPT_SYNTAX, 0); - } else if (!quadruple_compare(tmp, cs_hex, mc_dec, mc_hex)) + } + else if (!quadruple_compare(tmp, cs_hex, mc_dec, mc_hex, list_part[0])) _fail(__FILE__, __LINE__); free(tmp); @@ -335,7 +336,7 @@ void test_single_issue(csh *handle, cs_mode mode, char *line, int detail) list_part_issue_result = split(list_part[1], " ; ", &size_part_issue_result); if (size_part_cs_result != size_part_issue_result) { - fprintf(stderr, "[ ERROR ] --- Number of details doesn't match\n"); + fprintf(stderr, "[ ERROR ] --- %s --- Number of details doesn't match\n", list_part[0]); _fail(__FILE__, __LINE__); } diff --git a/suite/cstest/src/main.c b/suite/cstest/src/main.c index 92276f00..b838fd8e 100644 --- a/suite/cstest/src/main.c +++ b/suite/cstest/src/main.c @@ -15,14 +15,17 @@ static int setup_MC(void **state) char **list_params; int size_params; int arch, mode; - int i, index; + int i, index, tmp_counter; if (failed_setup) { fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n"); return -1; } - list_params = split(list_lines[0], ", ", &size_params); + tmp_counter = 0; + while (tmp_counter < size_lines && list_lines[tmp_counter][0] != '#') tmp_counter++; // get issue line + + list_params = split(list_lines[tmp_counter] + 2, ", ", &size_params); arch = get_value(arches, NUMARCH, list_params[0]); mode = get_value(modes, NUMMODE, list_params[1]); @@ -46,7 +49,8 @@ static int setup_MC(void **state) cs_option(*handle, options[index].first_value, options[index].second_value); } *state = (void *)handle; - counter ++; + counter++; + while (counter < size_lines && list_lines[counter][0] != '0') counter++; free_strs(list_params, size_params); return 0; } @@ -169,15 +173,20 @@ static void test_file(const char *filename) } _cmocka_run_group_tests("Testing issues", tests, number_of_tests, NULL, NULL); } else { - list_lines = split(content + 2, "\n", &size_lines); - number_of_tests = size_lines - 1; + list_lines = split(content, "\n", &size_lines); + number_of_tests = 0; - tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * (size_lines - 1)); - for (i=0; i < size_lines - 1; ++i) { - char *tmp = (char *)malloc(sizeof(char) * 100); - sprintf(tmp, "Line %d", i+2); - tests[i] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_MC, setup_MC, teardown_MC); - tests[i].name = tmp; + tests = NULL; +// tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * (size_lines - 1)); + for (i=0; i < size_lines - 1; ++i) { + if (list_lines[i][0] == '#' || list_lines[i][0] == '0') { + char *tmp = (char *)malloc(sizeof(char) * 100); + sprintf(tmp, "Line %d", i+2); + 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", tests, size_lines-1, NULL, NULL); }