Merge branch 'master' of github.com:HarDToBelieve/capstone

This commit is contained in:
Nguyen Anh Quynh 2019-02-12 17:15:37 +08:00
commit b00e4e4cb5
3 changed files with 36 additions and 25 deletions

View File

@ -33,18 +33,19 @@ def get_report_file(toolpath, filepath, getDetails):
elif 'LINE' in line: elif 'LINE' in line:
continue continue
elif 'ERROR' in line and ' --- ' in line: elif 'ERROR' in line and ' --- ' in line:
parts = line.split(' --- ')
try: try:
details.append((failed_tests[counter], line.split(' --- ')[1])) details.append((parts[1], failed_tests[counter], parts[2]))
except IndexError: except IndexError:
details.append(('Unknown test', line.split(' --- ')[1])) details.append(('', 'Unknown test', line.split(' --- ')[1]))
counter += 1 counter += 1
else: else:
continue continue
print '\n[-] There are/is {} failed test(s)'.format(len(details)) print '\n[-] There are/is {} failed test(s)'.format(len(details))
if len(details) > 0 and getDetails: if len(details) > 0 and getDetails:
print '[-] Detailed report for {}:\n'.format(filepath) print '[-] Detailed report for {}:\n'.format(filepath)
for f, d in details: for c, f, d in details:
print '\t[+] {}:\n\t\t{}\n'.format(f, d) print '\t[+] {}: {}\n\t\t{}\n'.format(f, c, d)
print '\n' print '\n'
def get_report_folder(toolpath, folderpath, details): def get_report_folder(toolpath, folderpath, details):

View File

@ -84,14 +84,14 @@ double_dict options[] = {
char *(*function)(csh *, cs_mode, cs_insn*) = NULL; 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)) { 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)) if (strcmp(src1, src2))
fprintf(stderr, " (\"%s\" != \"%s\")", src2, des2); fprintf(stderr, " (\"%s\" != \"%s\")", src1, des2);
else if (strcmp(des1, des2)) else if (strcmp(des1, des2))
fprintf(stderr, " (\"%s\" != \"%s\")", src1, des1); fprintf(stderr, " (\"%s\" != \"%s\")", src2, des1);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
return 0; return 0;
} }
@ -133,11 +133,11 @@ void test_single_MC(csh *handle, char *line)
// printf("====\nCount: %d\nSize_data: %d\n", count, size_data); // printf("====\nCount: %d\nSize_data: %d\n", count, size_data);
// assert_int_equal(size_data, count); // assert_int_equal(size_data, count);
if (count == 0) { 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__); _fail(__FILE__, __LINE__);
} }
if (count > 1) { 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__); _fail(__FILE__, __LINE__);
} }
@ -159,7 +159,7 @@ void test_single_MC(csh *handle, char *line)
// assert_string_equal(tmp, list_data[i]); // 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); 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); tmp_noreg = (char *)malloc(strlen(insn[0].mnemonic) + strlen(insn[0].op_str) + 100);
strcpy(tmp_noreg, insn[0].mnemonic); 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) 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)) { && 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__); _fail(__FILE__, __LINE__);
} }
@ -187,7 +187,8 @@ void test_single_MC(csh *handle, char *line)
free(mc_dec_noreg); free(mc_dec_noreg);
cs_option(*handle, CS_OPT_SYNTAX, 0); 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__); _fail(__FILE__, __LINE__);
free(tmp); 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); list_part_issue_result = split(list_part[1], " ; ", &size_part_issue_result);
if (size_part_cs_result != 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__); _fail(__FILE__, __LINE__);
} }

View File

@ -15,14 +15,17 @@ static int setup_MC(void **state)
char **list_params; char **list_params;
int size_params; int size_params;
int arch, mode; int arch, mode;
int i, index; int i, index, tmp_counter;
if (failed_setup) { if (failed_setup) {
fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n"); fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n");
return -1; 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]); arch = get_value(arches, NUMARCH, list_params[0]);
mode = get_value(modes, NUMMODE, list_params[1]); 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); cs_option(*handle, options[index].first_value, options[index].second_value);
} }
*state = (void *)handle; *state = (void *)handle;
counter ++; counter++;
while (counter < size_lines && list_lines[counter][0] != '0') counter++;
free_strs(list_params, size_params); free_strs(list_params, size_params);
return 0; 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); _cmocka_run_group_tests("Testing issues", tests, number_of_tests, NULL, NULL);
} else { } else {
list_lines = split(content + 2, "\n", &size_lines); list_lines = split(content, "\n", &size_lines);
number_of_tests = size_lines - 1; number_of_tests = 0;
tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * (size_lines - 1)); tests = NULL;
for (i=0; i < size_lines - 1; ++i) { // tests = (struct CMUnitTest *)malloc(sizeof(struct CMUnitTest) * (size_lines - 1));
char *tmp = (char *)malloc(sizeof(char) * 100); for (i=0; i < size_lines - 1; ++i) {
sprintf(tmp, "Line %d", i+2); if (list_lines[i][0] == '#' || list_lines[i][0] == '0') {
tests[i] = (struct CMUnitTest)cmocka_unit_test_setup_teardown(test_MC, setup_MC, teardown_MC); char *tmp = (char *)malloc(sizeof(char) * 100);
tests[i].name = tmp; 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); _cmocka_run_group_tests("Testing", tests, size_lines-1, NULL, NULL);
} }