diff --git a/suite/cstest/include/test_case.h b/suite/cstest/include/test_case.h index eae01fd7bf..e19994f4ad 100644 --- a/suite/cstest/include/test_case.h +++ b/suite/cstest/include/test_case.h @@ -12,11 +12,11 @@ /// Input data for a test case. typedef struct { - uint8_t *bytes; // mandatory - uint32_t bytes_count; // Filled by cyaml - char *arch; // mandatory + uint8_t *bytes; // mandatory + uint32_t bytes_count; // Filled by cyaml + char *arch; // mandatory uint64_t address; - char **options; // mandatory + char **options; // mandatory uint32_t options_count; // Filled by cyaml } TestInput; @@ -56,7 +56,7 @@ static const cyaml_schema_field_t test_input_mapping_schema[] = { /// Data compared to the produced cs_insn. typedef struct { uint32_t id; - char *asm_text; // mandatory + char *asm_text; // mandatory char *op_str; int32_t is_alias; ///< 0 == not given, >0 == true, <0 == false uint64_t alias_id; @@ -73,18 +73,20 @@ static const cyaml_schema_field_t test_insn_data_mapping_schema[] = { TestInsnData, id), CYAML_FIELD_STRING_PTR("asm_text", CYAML_FLAG_POINTER, TestInsnData, asm_text, 0, CYAML_UNLIMITED), - CYAML_FIELD_STRING_PTR("op_str", CYAML_FLAG_POINTER_NULL_STR | CYAML_FLAG_OPTIONAL, TestInsnData, - op_str, 0, CYAML_UNLIMITED), + CYAML_FIELD_STRING_PTR( + "op_str", CYAML_FLAG_POINTER_NULL_STR | CYAML_FLAG_OPTIONAL, + TestInsnData, op_str, 0, CYAML_UNLIMITED), CYAML_FIELD_UINT("is_alias", CYAML_FLAG_OPTIONAL, TestInsnData, is_alias), CYAML_FIELD_INT("alias_id", - CYAML_FLAG_SCALAR_PLAIN | CYAML_FLAG_OPTIONAL, - TestInsnData, alias_id), + CYAML_FLAG_SCALAR_PLAIN | CYAML_FLAG_OPTIONAL, + TestInsnData, alias_id), CYAML_FIELD_STRING_PTR( "mnemonic", CYAML_FLAG_POINTER_NULL_STR | CYAML_FLAG_OPTIONAL, TestInsnData, mnemonic, 0, CYAML_UNLIMITED), - CYAML_FIELD_MAPPING_PTR("details", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, TestInsnData, details, - test_detail_mapping_schema), + CYAML_FIELD_MAPPING_PTR( + "details", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, + TestInsnData, details, test_detail_mapping_schema), CYAML_FIELD_END }; @@ -116,8 +118,8 @@ static const cyaml_schema_field_t test_expected_mapping_schema[] = { typedef struct { TestInput *input; ///< Input data for a test case TestExpected *expected; ///< Expected data of the test case. - bool skip; ///< If set, the test is skipped - char *skip_reason; ///< Reason this test is skipped. + bool skip; ///< If set, the test is skipped + char *skip_reason; ///< Reason this test is skipped. } TestCase; TestCase *test_case_new(); @@ -130,9 +132,10 @@ static const cyaml_schema_field_t test_case_mapping_schema[] = { CYAML_FIELD_MAPPING_PTR("expected", CYAML_FLAG_POINTER, TestCase, expected, test_expected_mapping_schema), CYAML_FIELD_BOOL("skip", CYAML_FLAG_OPTIONAL, TestCase, skip), - CYAML_FIELD_STRING_PTR( - "skip_reason", CYAML_FLAG_POINTER_NULL_STR | CYAML_FLAG_OPTIONAL, - TestCase, skip_reason, 0, CYAML_UNLIMITED), + CYAML_FIELD_STRING_PTR("skip_reason", + CYAML_FLAG_POINTER_NULL_STR | + CYAML_FLAG_OPTIONAL, + TestCase, skip_reason, 0, CYAML_UNLIMITED), CYAML_FIELD_END }; diff --git a/suite/cstest/include/test_compare.h b/suite/cstest/include/test_compare.h index fbf474b29d..748cd7feb5 100644 --- a/suite/cstest/include/test_compare.h +++ b/suite/cstest/include/test_compare.h @@ -21,8 +21,11 @@ typedef int32_t tbool; /// Compares the @actual bool against the @expected tbool: /// It returns with @ret_val, if expected is set but the values mismatch. #define compare_tbool_ret(actual, expected, ret_val) \ - if (expected != 0 && ((actual && expected <= 0) || (!actual && expected >= 0))) { \ - fprintf(stderr, #actual " is %s but expected is %" PRId32 " (=0 unset, >0 true, <0 false)\n", \ + if (expected != 0 && \ + ((actual && expected <= 0) || (!actual && expected >= 0))) { \ + fprintf(stderr, \ + #actual " is %s but expected is %" PRId32 \ + " (=0 unset, >0 true, <0 false)\n", \ actual ? "true" : "false", expected); \ return ret_val; \ } @@ -41,8 +44,10 @@ typedef int32_t tbool; /// Compares two uint8_t values. /// It returns with @ret_val if they mismatch. #define compare_uint8_ret(actual, expected, ret_val) \ - if (((uint8_t) actual) != ((uint8_t) expected)) { \ - fprintf(stderr, #actual " != " #expected ": %" PRId8 " != %" PRId8 "\n", \ + if (((uint8_t)actual) != ((uint8_t)expected)) { \ + fprintf(stderr, \ + #actual " != " #expected ": %" PRId8 " != %" PRId8 \ + "\n", \ actual, expected); \ return ret_val; \ } @@ -61,10 +66,10 @@ typedef int32_t tbool; /// Compares two uint32_t values. /// It returns with @ret_val if they mismatch. #define compare_uint32_ret(actual, expected, ret_val) \ - if (((uint32_t) actual) != ((uint32_t) expected)) { \ + if (((uint32_t)actual) != ((uint32_t)expected)) { \ fprintf(stderr, \ - #actual " != " #expected ": 0x%" PRIx32 " != 0x%" PRIx32 \ - "\n", \ + #actual " != " #expected ": 0x%" PRIx32 \ + " != 0x%" PRIx32 "\n", \ actual, expected); \ return ret_val; \ } @@ -72,10 +77,10 @@ typedef int32_t tbool; /// Compares two uint64_t values. /// It returns with @ret_val if they mismatch. #define compare_uint64_ret(actual, expected, ret_val) \ - if (((uint64_t) actual) != ((uint64_t) expected)) { \ + if (((uint64_t)actual) != ((uint64_t)expected)) { \ fprintf(stderr, \ - #actual " != " #expected ": 0x%" PRIx64 " != 0x%" PRIx64 \ - "\n", \ + #actual " != " #expected ": 0x%" PRIx64 \ + " != 0x%" PRIx64 "\n", \ actual, expected); \ return ret_val; \ } @@ -94,7 +99,7 @@ typedef int32_t tbool; /// Compares two int8_t values. /// It returns with @ret_val if they mismatch. #define compare_int8_ret(actual, expected, ret_val) \ - if (((int8_t) actual) != ((int8_t) expected)) { \ + if (((int8_t)actual) != ((int8_t)expected)) { \ fprintf(stderr, \ #actual " != " #expected ": 0x%" PRIx8 " != 0x%" PRIx8 \ "\n", \ @@ -105,10 +110,10 @@ typedef int32_t tbool; /// Compares two int32_t values. /// It returns with @ret_val if they mismatch. #define compare_int32_ret(actual, expected, ret_val) \ - if (((int32_t) actual) != ((int32_t) expected)) { \ + if (((int32_t)actual) != ((int32_t)expected)) { \ fprintf(stderr, \ - #actual " != " #expected ": 0x%" PRIx32 " != 0x%" PRIx32 \ - "\n", \ + #actual " != " #expected ": 0x%" PRIx32 \ + " != 0x%" PRIx32 "\n", \ actual, expected); \ return ret_val; \ } @@ -116,10 +121,10 @@ typedef int32_t tbool; /// Compares two int64_t values. /// It returns with @ret_val if they mismatch. #define compare_int64_ret(actual, expected, ret_val) \ - if (((int64_t) actual) != ((int64_t) expected)) { \ + if (((int64_t)actual) != ((int64_t)expected)) { \ fprintf(stderr, \ - #actual " != " #expected ": 0x%" PRIx64 " != 0x%" PRIx64 \ - "\n", \ + #actual " != " #expected ": 0x%" PRIx64 \ + " != 0x%" PRIx64 "\n", \ actual, expected); \ return ret_val; \ } @@ -139,12 +144,14 @@ typedef int32_t tbool; #define compare_enum_ret(actual, expected, ret_val) \ if (expected) { \ bool found = false; \ - uint32_t eval = enum_map_bin_search(cs_enum_map, ARR_SIZE(cs_enum_map), expected, &found); \ + uint32_t eval = enum_map_bin_search( \ + cs_enum_map, ARR_SIZE(cs_enum_map), expected, &found); \ if (expected && (actual != eval || !found)) { \ fprintf(stderr, \ #actual " != " #expected ": %" PRId32 \ " != %s%s\n", \ - actual, expected, found ? "" : " <== id not found"); \ + actual, expected, \ + found ? "" : " <== id not found"); \ return ret_val; \ } \ } diff --git a/suite/cstest/include/test_detail.h b/suite/cstest/include/test_detail.h index d3962f39df..aeeaddcac3 100644 --- a/suite/cstest/include/test_detail.h +++ b/suite/cstest/include/test_detail.h @@ -85,6 +85,6 @@ TestDetail *test_detail_clone(TestDetail *detail); void test_detail_free(TestDetail *detail); bool test_expected_detail(csh *handle, const cs_insn *insn, - TestDetail *expected); + TestDetail *expected); #endif // TEST_DETAIL_H diff --git a/suite/cstest/include/test_detail_aarch64.h b/suite/cstest/include/test_detail_aarch64.h index c5fd77b1c6..362789cb80 100644 --- a/suite/cstest/include/test_detail_aarch64.h +++ b/suite/cstest/include/test_detail_aarch64.h @@ -80,7 +80,7 @@ static const cyaml_schema_field_t test_detail_aarch64_op_mapping_schema[] = { CYAML_FIELD_INT("vector_index", CYAML_FLAG_OPTIONAL, TestDetailAArch64Op, vector_index), CYAML_FIELD_BOOL("vector_index_is_set", CYAML_FLAG_OPTIONAL, - TestDetailAArch64Op, vector_index_is_set), + TestDetailAArch64Op, vector_index_is_set), CYAML_FIELD_INT("is_list_member", CYAML_FLAG_OPTIONAL, TestDetailAArch64Op, is_list_member), CYAML_FIELD_END diff --git a/suite/cstest/include/test_mapping.h b/suite/cstest/include/test_mapping.h index 2778ef6aed..ce370bfb3e 100644 --- a/suite/cstest/include/test_mapping.h +++ b/suite/cstest/include/test_mapping.h @@ -191,7 +191,8 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "AARCH64LAYOUT_VL_8D", .val = AARCH64LAYOUT_VL_8D }, { .str = "AARCH64LAYOUT_VL_8H", .val = AARCH64LAYOUT_VL_8H }, { .str = "AARCH64LAYOUT_VL_B", .val = AARCH64LAYOUT_VL_B }, - { .str = "AARCH64LAYOUT_VL_COMPLETE", .val = AARCH64LAYOUT_VL_COMPLETE }, + { .str = "AARCH64LAYOUT_VL_COMPLETE", + .val = AARCH64LAYOUT_VL_COMPLETE }, { .str = "AARCH64LAYOUT_VL_D", .val = AARCH64LAYOUT_VL_D }, { .str = "AARCH64LAYOUT_VL_H", .val = AARCH64LAYOUT_VL_H }, { .str = "AARCH64LAYOUT_VL_Q", .val = AARCH64LAYOUT_VL_Q }, @@ -216,7 +217,8 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "AARCH64_OP_IC", .val = AARCH64_OP_IC }, { .str = "AARCH64_OP_IMM", .val = AARCH64_OP_IMM }, { .str = "AARCH64_OP_IMM_RANGE", .val = AARCH64_OP_IMM_RANGE }, - { .str = "AARCH64_OP_IMPLICIT_IMM_0", .val = AARCH64_OP_IMPLICIT_IMM_0 }, + { .str = "AARCH64_OP_IMPLICIT_IMM_0", + .val = AARCH64_OP_IMPLICIT_IMM_0 }, { .str = "AARCH64_OP_ISB", .val = AARCH64_OP_ISB }, { .str = "AARCH64_OP_MEM", .val = AARCH64_OP_MEM }, { .str = "AARCH64_OP_MEM_IMM", .val = AARCH64_OP_MEM_IMM }, @@ -234,7 +236,8 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "AARCH64_OP_SVCR", .val = AARCH64_OP_SVCR }, { .str = "AARCH64_OP_SVEPREDPAT", .val = AARCH64_OP_SVEPREDPAT }, { .str = "AARCH64_OP_SVEPRFM", .val = AARCH64_OP_SVEPRFM }, - { .str = "AARCH64_OP_SVEVECLENSPECIFIER", .val = AARCH64_OP_SVEVECLENSPECIFIER }, + { .str = "AARCH64_OP_SVEVECLENSPECIFIER", + .val = AARCH64_OP_SVEVECLENSPECIFIER }, { .str = "AARCH64_OP_SYSALIAS", .val = AARCH64_OP_SYSALIAS }, { .str = "AARCH64_OP_SYSIMM", .val = AARCH64_OP_SYSIMM }, { .str = "AARCH64_OP_SYSREG", .val = AARCH64_OP_SYSREG }, @@ -435,15 +438,19 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "PPC_INSN_FORM_BFORM_3_AT", .val = PPC_INSN_FORM_BFORM_3_AT }, { .str = "PPC_INSN_FORM_DCBZL_FORM", .val = PPC_INSN_FORM_DCBZL_FORM }, { .str = "PPC_INSN_FORM_DCB_FORM", .val = PPC_INSN_FORM_DCB_FORM }, - { .str = "PPC_INSN_FORM_DCB_FORM_HINT", .val = PPC_INSN_FORM_DCB_FORM_HINT }, + { .str = "PPC_INSN_FORM_DCB_FORM_HINT", + .val = PPC_INSN_FORM_DCB_FORM_HINT }, { .str = "PPC_INSN_FORM_DFORM_1", .val = PPC_INSN_FORM_DFORM_1 }, { .str = "PPC_INSN_FORM_DFORM_2_R0", .val = PPC_INSN_FORM_DFORM_2_R0 }, { .str = "PPC_INSN_FORM_DFORM_4", .val = PPC_INSN_FORM_DFORM_4 }, { .str = "PPC_INSN_FORM_DFORM_5", .val = PPC_INSN_FORM_DFORM_5 }, { .str = "PPC_INSN_FORM_DFORM_BASE", .val = PPC_INSN_FORM_DFORM_BASE }, - { .str = "PPC_INSN_FORM_DQFORM_RTP5_RA17_MEM", .val = PPC_INSN_FORM_DQFORM_RTP5_RA17_MEM }, - { .str = "PPC_INSN_FORM_DQFORM_XTP5_RA17_MEM", .val = PPC_INSN_FORM_DQFORM_XTP5_RA17_MEM }, - { .str = "PPC_INSN_FORM_DQ_RD6_RS5_DQ12", .val = PPC_INSN_FORM_DQ_RD6_RS5_DQ12 }, + { .str = "PPC_INSN_FORM_DQFORM_RTP5_RA17_MEM", + .val = PPC_INSN_FORM_DQFORM_RTP5_RA17_MEM }, + { .str = "PPC_INSN_FORM_DQFORM_XTP5_RA17_MEM", + .val = PPC_INSN_FORM_DQFORM_XTP5_RA17_MEM }, + { .str = "PPC_INSN_FORM_DQ_RD6_RS5_DQ12", + .val = PPC_INSN_FORM_DQ_RD6_RS5_DQ12 }, { .str = "PPC_INSN_FORM_DSFORM_1", .val = PPC_INSN_FORM_DSFORM_1 }, { .str = "PPC_INSN_FORM_DSS_FORM", .val = PPC_INSN_FORM_DSS_FORM }, { .str = "PPC_INSN_FORM_DXFORM", .val = PPC_INSN_FORM_DXFORM }, @@ -467,22 +474,30 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "PPC_INSN_FORM_VAFORM_1", .val = PPC_INSN_FORM_VAFORM_1 }, { .str = "PPC_INSN_FORM_VAFORM_1A", .val = PPC_INSN_FORM_VAFORM_1A }, { .str = "PPC_INSN_FORM_VAFORM_2", .val = PPC_INSN_FORM_VAFORM_2 }, - { .str = "PPC_INSN_FORM_VNFORM_VTAB5_SD3", .val = PPC_INSN_FORM_VNFORM_VTAB5_SD3 }, + { .str = "PPC_INSN_FORM_VNFORM_VTAB5_SD3", + .val = PPC_INSN_FORM_VNFORM_VTAB5_SD3 }, { .str = "PPC_INSN_FORM_VXFORM_1", .val = PPC_INSN_FORM_VXFORM_1 }, { .str = "PPC_INSN_FORM_VXFORM_2", .val = PPC_INSN_FORM_VXFORM_2 }, { .str = "PPC_INSN_FORM_VXFORM_3", .val = PPC_INSN_FORM_VXFORM_3 }, { .str = "PPC_INSN_FORM_VXFORM_4", .val = PPC_INSN_FORM_VXFORM_4 }, { .str = "PPC_INSN_FORM_VXFORM_5", .val = PPC_INSN_FORM_VXFORM_5 }, - { .str = "PPC_INSN_FORM_VXFORM_BF3_VAB5", .val = PPC_INSN_FORM_VXFORM_BF3_VAB5 }, + { .str = "PPC_INSN_FORM_VXFORM_BF3_VAB5", + .val = PPC_INSN_FORM_VXFORM_BF3_VAB5 }, { .str = "PPC_INSN_FORM_VXFORM_BX", .val = PPC_INSN_FORM_VXFORM_BX }, { .str = "PPC_INSN_FORM_VXFORM_CR", .val = PPC_INSN_FORM_VXFORM_CR }, - { .str = "PPC_INSN_FORM_VXFORM_RD5_MP_VB5", .val = PPC_INSN_FORM_VXFORM_RD5_MP_VB5 }, - { .str = "PPC_INSN_FORM_VXFORM_RD5_N3_VB5", .val = PPC_INSN_FORM_VXFORM_RD5_N3_VB5 }, - { .str = "PPC_INSN_FORM_VXFORM_RD5_XO5_RS5", .val = PPC_INSN_FORM_VXFORM_RD5_XO5_RS5 }, - { .str = "PPC_INSN_FORM_VXFORM_VTB5_RC", .val = PPC_INSN_FORM_VXFORM_VTB5_RC }, + { .str = "PPC_INSN_FORM_VXFORM_RD5_MP_VB5", + .val = PPC_INSN_FORM_VXFORM_RD5_MP_VB5 }, + { .str = "PPC_INSN_FORM_VXFORM_RD5_N3_VB5", + .val = PPC_INSN_FORM_VXFORM_RD5_N3_VB5 }, + { .str = "PPC_INSN_FORM_VXFORM_RD5_XO5_RS5", + .val = PPC_INSN_FORM_VXFORM_RD5_XO5_RS5 }, + { .str = "PPC_INSN_FORM_VXFORM_VTB5_RC", + .val = PPC_INSN_FORM_VXFORM_VTB5_RC }, { .str = "PPC_INSN_FORM_VXRFORM_1", .val = PPC_INSN_FORM_VXRFORM_1 }, - { .str = "PPC_INSN_FORM_VX_RD5_EO5_RS5_PS1_XO9", .val = PPC_INSN_FORM_VX_RD5_EO5_RS5_PS1_XO9 }, - { .str = "PPC_INSN_FORM_VX_RD5_RSP5_PS1_XO9", .val = PPC_INSN_FORM_VX_RD5_RSP5_PS1_XO9 }, + { .str = "PPC_INSN_FORM_VX_RD5_EO5_RS5_PS1_XO9", + .val = PPC_INSN_FORM_VX_RD5_EO5_RS5_PS1_XO9 }, + { .str = "PPC_INSN_FORM_VX_RD5_RSP5_PS1_XO9", + .val = PPC_INSN_FORM_VX_RD5_RSP5_PS1_XO9 }, { .str = "PPC_INSN_FORM_XFLFORM_1", .val = PPC_INSN_FORM_XFLFORM_1 }, { .str = "PPC_INSN_FORM_XFORMMEMOP", .val = PPC_INSN_FORM_XFORMMEMOP }, { .str = "PPC_INSN_FORM_XFORM_16", .val = PPC_INSN_FORM_XFORM_16 }, @@ -490,27 +505,35 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "PPC_INSN_FORM_XFORM_18", .val = PPC_INSN_FORM_XFORM_18 }, { .str = "PPC_INSN_FORM_XFORM_20", .val = PPC_INSN_FORM_XFORM_20 }, { .str = "PPC_INSN_FORM_XFORM_24", .val = PPC_INSN_FORM_XFORM_24 }, - { .str = "PPC_INSN_FORM_XFORM_24_SYNC", .val = PPC_INSN_FORM_XFORM_24_SYNC }, + { .str = "PPC_INSN_FORM_XFORM_24_SYNC", + .val = PPC_INSN_FORM_XFORM_24_SYNC }, { .str = "PPC_INSN_FORM_XFORM_44", .val = PPC_INSN_FORM_XFORM_44 }, { .str = "PPC_INSN_FORM_XFORM_45", .val = PPC_INSN_FORM_XFORM_45 }, { .str = "PPC_INSN_FORM_XFORM_AT3", .val = PPC_INSN_FORM_XFORM_AT3 }, { .str = "PPC_INSN_FORM_XFORM_ATB3", .val = PPC_INSN_FORM_XFORM_ATB3 }, { .str = "PPC_INSN_FORM_XFORM_ATTN", .val = PPC_INSN_FORM_XFORM_ATTN }, - { .str = "PPC_INSN_FORM_XFORM_BASE_R3XO", .val = PPC_INSN_FORM_XFORM_BASE_R3XO }, - { .str = "PPC_INSN_FORM_XFORM_BASE_R3XO_SWAPPED", .val = PPC_INSN_FORM_XFORM_BASE_R3XO_SWAPPED }, + { .str = "PPC_INSN_FORM_XFORM_BASE_R3XO", + .val = PPC_INSN_FORM_XFORM_BASE_R3XO }, + { .str = "PPC_INSN_FORM_XFORM_BASE_R3XO_SWAPPED", + .val = PPC_INSN_FORM_XFORM_BASE_R3XO_SWAPPED }, { .str = "PPC_INSN_FORM_XFORM_HTM0", .val = PPC_INSN_FORM_XFORM_HTM0 }, { .str = "PPC_INSN_FORM_XFORM_HTM1", .val = PPC_INSN_FORM_XFORM_HTM1 }, { .str = "PPC_INSN_FORM_XFORM_HTM2", .val = PPC_INSN_FORM_XFORM_HTM2 }, { .str = "PPC_INSN_FORM_XFORM_HTM3", .val = PPC_INSN_FORM_XFORM_HTM3 }, { .str = "PPC_INSN_FORM_XFORM_ICBT", .val = PPC_INSN_FORM_XFORM_ICBT }, { .str = "PPC_INSN_FORM_XFORM_MBAR", .val = PPC_INSN_FORM_XFORM_MBAR }, - { .str = "PPC_INSN_FORM_XFORM_MTMSR", .val = PPC_INSN_FORM_XFORM_MTMSR }, + { .str = "PPC_INSN_FORM_XFORM_MTMSR", + .val = PPC_INSN_FORM_XFORM_MTMSR }, { .str = "PPC_INSN_FORM_XFORM_SR", .val = PPC_INSN_FORM_XFORM_SR }, { .str = "PPC_INSN_FORM_XFORM_SRIN", .val = PPC_INSN_FORM_XFORM_SRIN }, - { .str = "PPC_INSN_FORM_XFORM_TLBWS", .val = PPC_INSN_FORM_XFORM_TLBWS }, - { .str = "PPC_INSN_FORM_XFORM_XD6_RA5_RB5", .val = PPC_INSN_FORM_XFORM_XD6_RA5_RB5 }, - { .str = "PPC_INSN_FORM_XFORM_XT6_IMM5", .val = PPC_INSN_FORM_XFORM_XT6_IMM5 }, - { .str = "PPC_INSN_FORM_XFORM_XT6_IMM5_VB5", .val = PPC_INSN_FORM_XFORM_XT6_IMM5_VB5 }, + { .str = "PPC_INSN_FORM_XFORM_TLBWS", + .val = PPC_INSN_FORM_XFORM_TLBWS }, + { .str = "PPC_INSN_FORM_XFORM_XD6_RA5_RB5", + .val = PPC_INSN_FORM_XFORM_XD6_RA5_RB5 }, + { .str = "PPC_INSN_FORM_XFORM_XT6_IMM5", + .val = PPC_INSN_FORM_XFORM_XT6_IMM5 }, + { .str = "PPC_INSN_FORM_XFORM_XT6_IMM5_VB5", + .val = PPC_INSN_FORM_XFORM_XT6_IMM5_VB5 }, { .str = "PPC_INSN_FORM_XFXFORM_1", .val = PPC_INSN_FORM_XFXFORM_1 }, { .str = "PPC_INSN_FORM_XFXFORM_3", .val = PPC_INSN_FORM_XFXFORM_3 }, { .str = "PPC_INSN_FORM_XFXFORM_3P", .val = PPC_INSN_FORM_XFXFORM_3P }, @@ -522,34 +545,48 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "PPC_INSN_FORM_XLFORM_4", .val = PPC_INSN_FORM_XLFORM_4 }, { .str = "PPC_INSN_FORM_XLFORM_S", .val = PPC_INSN_FORM_XLFORM_S }, { .str = "PPC_INSN_FORM_XOFORM_1", .val = PPC_INSN_FORM_XOFORM_1 }, - { .str = "PPC_INSN_FORM_XOFORM_RTAB5_L1", .val = PPC_INSN_FORM_XOFORM_RTAB5_L1 }, + { .str = "PPC_INSN_FORM_XOFORM_RTAB5_L1", + .val = PPC_INSN_FORM_XOFORM_RTAB5_L1 }, { .str = "PPC_INSN_FORM_XSFORM_1", .val = PPC_INSN_FORM_XSFORM_1 }, { .str = "PPC_INSN_FORM_XX1FORM", .val = PPC_INSN_FORM_XX1FORM }, { .str = "PPC_INSN_FORM_XX2FORM", .val = PPC_INSN_FORM_XX2FORM }, { .str = "PPC_INSN_FORM_XX2FORM_1", .val = PPC_INSN_FORM_XX2FORM_1 }, { .str = "PPC_INSN_FORM_XX2FORM_2", .val = PPC_INSN_FORM_XX2FORM_2 }, - { .str = "PPC_INSN_FORM_XX2FORM_AT3_XBP5_P2", .val = PPC_INSN_FORM_XX2FORM_AT3_XBP5_P2 }, - { .str = "PPC_INSN_FORM_XX2_BF3_DCMX7_RS6", .val = PPC_INSN_FORM_XX2_BF3_DCMX7_RS6 }, - { .str = "PPC_INSN_FORM_XX2_BF3_XO5_XB6_XO9", .val = PPC_INSN_FORM_XX2_BF3_XO5_XB6_XO9 }, - { .str = "PPC_INSN_FORM_XX2_RD5_XO5_RS6", .val = PPC_INSN_FORM_XX2_RD5_XO5_RS6 }, - { .str = "PPC_INSN_FORM_XX2_RD6_DCMX7_RS6", .val = PPC_INSN_FORM_XX2_RD6_DCMX7_RS6 }, - { .str = "PPC_INSN_FORM_XX2_RD6_UIM5_RS6", .val = PPC_INSN_FORM_XX2_RD6_UIM5_RS6 }, - { .str = "PPC_INSN_FORM_XX2_RD6_XO5_RS6", .val = PPC_INSN_FORM_XX2_RD6_XO5_RS6 }, + { .str = "PPC_INSN_FORM_XX2FORM_AT3_XBP5_P2", + .val = PPC_INSN_FORM_XX2FORM_AT3_XBP5_P2 }, + { .str = "PPC_INSN_FORM_XX2_BF3_DCMX7_RS6", + .val = PPC_INSN_FORM_XX2_BF3_DCMX7_RS6 }, + { .str = "PPC_INSN_FORM_XX2_BF3_XO5_XB6_XO9", + .val = PPC_INSN_FORM_XX2_BF3_XO5_XB6_XO9 }, + { .str = "PPC_INSN_FORM_XX2_RD5_XO5_RS6", + .val = PPC_INSN_FORM_XX2_RD5_XO5_RS6 }, + { .str = "PPC_INSN_FORM_XX2_RD6_DCMX7_RS6", + .val = PPC_INSN_FORM_XX2_RD6_DCMX7_RS6 }, + { .str = "PPC_INSN_FORM_XX2_RD6_UIM5_RS6", + .val = PPC_INSN_FORM_XX2_RD6_UIM5_RS6 }, + { .str = "PPC_INSN_FORM_XX2_RD6_XO5_RS6", + .val = PPC_INSN_FORM_XX2_RD6_XO5_RS6 }, { .str = "PPC_INSN_FORM_XX3FORM", .val = PPC_INSN_FORM_XX3FORM }, { .str = "PPC_INSN_FORM_XX3FORM_1", .val = PPC_INSN_FORM_XX3FORM_1 }, { .str = "PPC_INSN_FORM_XX3FORM_2", .val = PPC_INSN_FORM_XX3FORM_2 }, - { .str = "PPC_INSN_FORM_XX3FORM_AT3_XAB6", .val = PPC_INSN_FORM_XX3FORM_AT3_XAB6 }, - { .str = "PPC_INSN_FORM_XX3FORM_AT3_XABP5_P1", .val = PPC_INSN_FORM_XX3FORM_AT3_XABP5_P1 }, + { .str = "PPC_INSN_FORM_XX3FORM_AT3_XAB6", + .val = PPC_INSN_FORM_XX3FORM_AT3_XAB6 }, + { .str = "PPC_INSN_FORM_XX3FORM_AT3_XABP5_P1", + .val = PPC_INSN_FORM_XX3FORM_AT3_XABP5_P1 }, { .str = "PPC_INSN_FORM_XX3FORM_RC", .val = PPC_INSN_FORM_XX3FORM_RC }, { .str = "PPC_INSN_FORM_XX4FORM", .val = PPC_INSN_FORM_XX4FORM }, - { .str = "PPC_INSN_FORM_X_BF3_DCMX7_RS5", .val = PPC_INSN_FORM_X_BF3_DCMX7_RS5 }, - { .str = "PPC_INSN_FORM_X_BF3_L1_RS5_RS5", .val = PPC_INSN_FORM_X_BF3_L1_RS5_RS5 }, - { .str = "PPC_INSN_FORM_X_BF3_RS5_RS5", .val = PPC_INSN_FORM_X_BF3_RS5_RS5 }, + { .str = "PPC_INSN_FORM_X_BF3_DCMX7_RS5", + .val = PPC_INSN_FORM_X_BF3_DCMX7_RS5 }, + { .str = "PPC_INSN_FORM_X_BF3_L1_RS5_RS5", + .val = PPC_INSN_FORM_X_BF3_L1_RS5_RS5 }, + { .str = "PPC_INSN_FORM_X_BF3_RS5_RS5", + .val = PPC_INSN_FORM_X_BF3_RS5_RS5 }, { .str = "PPC_INSN_FORM_X_RD6_IMM8", .val = PPC_INSN_FORM_X_RD6_IMM8 }, { .str = "PPC_INSN_FORM_Z23FORM_1", .val = PPC_INSN_FORM_Z23FORM_1 }, { .str = "PPC_INSN_FORM_Z23FORM_3", .val = PPC_INSN_FORM_Z23FORM_3 }, { .str = "PPC_INSN_FORM_Z23FORM_8", .val = PPC_INSN_FORM_Z23FORM_8 }, - { .str = "PPC_INSN_FORM_Z23FORM_RTAB5_CY2", .val = PPC_INSN_FORM_Z23FORM_RTAB5_CY2 }, + { .str = "PPC_INSN_FORM_Z23FORM_RTAB5_CY2", + .val = PPC_INSN_FORM_Z23FORM_RTAB5_CY2 }, { .str = "PPC_OP_IMM", .val = PPC_OP_IMM }, { .str = "PPC_OP_MEM", .val = PPC_OP_MEM }, { .str = "PPC_OP_REG", .val = PPC_OP_REG }, @@ -598,7 +635,8 @@ static const cs_enum_id_map cs_enum_map[] = { { .str = "PPC_PRED_Z_MINUS", .val = PPC_PRED_Z_MINUS }, { .str = "PPC_PRED_Z_PLUS", .val = PPC_PRED_Z_PLUS }, { .str = "PPC_PRED_Z_RESERVED", .val = PPC_PRED_Z_RESERVED }, - { .str = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", .val = 0xffffff }, // For testing + { .str = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", + .val = 0xffffff }, // For testing }; -#endif // TEST_MAPPING_H +#endif // TEST_MAPPING_H diff --git a/suite/cstest/include/test_run.h b/suite/cstest/include/test_run.h index 4082518516..c21700cf26 100644 --- a/suite/cstest/include/test_run.h +++ b/suite/cstest/include/test_run.h @@ -36,9 +36,9 @@ static const cyaml_config_t cyaml_config = { }; typedef struct { - size_t arch_bits; ///< Bits of the architecture. - TestCase *tcase; ///< The test case to check. - csh handle; ///< The Capstone instance for this test. Setup and teared down by the cmocka handlers. + size_t arch_bits; ///< Bits of the architecture. + TestCase *tcase; ///< The test case to check. + csh handle; ///< The Capstone instance for this test. Setup and teared down by the cmocka handlers. } UnitTestState; TestRunResult cstest_run_tests(char **test_file_paths, uint32_t path_count, diff --git a/suite/cstest/src/helper.c b/suite/cstest/src/helper.c index a45759c7a6..f3eccd550a 100644 --- a/suite/cstest/src/helper.c +++ b/suite/cstest/src/helper.c @@ -26,7 +26,7 @@ void add_str(char **src, const char *format, ...) vsprintf(tmp, format, args); va_end(args); - len1 = strlen(*src); + len1 = strlen(*src); len2 = strlen(tmp); *src = (char *)realloc(*src, sizeof(char) * (len1 + len2 + 10)); @@ -55,17 +55,19 @@ void replace_hex(char *src, size_t src_len) tmp_tmp = strndup(tmp, orig_found - tmp); while (*found != '\0' && isxdigit(*found)) { valid = 1; - if (*found >= 'a' && *found <='f') - value = value*0x10 + (*found - 'a' + 10); + if (*found >= 'a' && *found <= 'f') + value = value * 0x10 + (*found - 'a' + 10); else if (*found >= 'A' && *found <= 'F') value = value * 0x10 + (*found - 'A' + 10); else - value = value*0x10 + (*found - '0'); + value = value * 0x10 + (*found - '0'); found++; } - if (valid == 1) add_str(&result, "%s%llu", tmp_tmp, value); - else add_str(&result, "%s0x", tmp_tmp); + if (valid == 1) + add_str(&result, "%s%llu", tmp_tmp, value); + else + add_str(&result, "%s0x", tmp_tmp); tmp = found; free(tmp_tmp); } @@ -74,7 +76,8 @@ void replace_hex(char *src, size_t src_len) if (strlen(result) >= src_len) { free(result); free(origin); - fprintf(stderr, "[ Error ] --- Buffer Overflow in replace_hex()\n"); + fprintf(stderr, + "[ Error ] --- Buffer Overflow in replace_hex()\n"); _fail(__FILE__, __LINE__); } @@ -99,9 +102,9 @@ void replace_negative(char *src, size_t src_len, size_t arch_bits) while ((found = strstr(tmp, "-")) != NULL) { orig_found = found; - found ++; + found++; valid = 0; - + value = strdup("-"); cnt = 2; @@ -110,7 +113,7 @@ void replace_negative(char *src, size_t src_len, size_t arch_bits) value = (char *)realloc(value, cnt + 1); value[cnt - 1] = *found; value[cnt] = '\0'; - cnt ++; + cnt++; found++; } @@ -128,8 +131,8 @@ void replace_negative(char *src, size_t src_len, size_t arch_bits) add_str(&result, "%s%lu", tmp_tmp, tmp_long); } - } - else add_str(&result, "%s-", tmp_tmp); + } else + add_str(&result, "%s-", tmp_tmp); tmp = found; free(value); @@ -138,7 +141,8 @@ void replace_negative(char *src, size_t src_len, size_t arch_bits) add_str(&result, "%s", tmp); if (strlen(result) >= src_len) { - fprintf(stderr, "[ Error ] --- Buffer Overflow in replace_negative()\n"); + fprintf(stderr, + "[ Error ] --- Buffer Overflow in replace_negative()\n"); free(result); free(origin); _fail(__FILE__, __LINE__); @@ -157,8 +161,10 @@ void trim_str(char *str) start = 0; end = strlen(str) - 1; j = 0; - while (start < strlen(str) && isspace(str[start])) start++; - while (end >= 0 && isspace(str[end])) end--; + while (start < strlen(str) && isspace(str[start])) + start++; + while (end >= 0 && isspace(str[end])) + end--; for (i = start; i <= end; ++i) tmp[j++] = str[i]; @@ -192,4 +198,3 @@ void str_to_lower(char *str) for (size_t i = 0; i < strlen(str); ++i) str[i] = tolower(str[i]); } - diff --git a/suite/cstest/src/test_case.c b/suite/cstest/src/test_case.c index 3dd6bd5e5e..098c10836b 100644 --- a/suite/cstest/src/test_case.c +++ b/suite/cstest/src/test_case.c @@ -40,8 +40,8 @@ TestInput *test_input_clone(TestInput *test_input) ti->address = test_input->address; for (size_t i = 0; i < test_input->options_count; i++) { - ti->options = cs_mem_realloc(ti->options, - sizeof(char *) * (ti->options_count + 1)); + ti->options = cs_mem_realloc( + ti->options, sizeof(char *) * (ti->options_count + 1)); ti->options[i] = cs_strdup(test_input->options[i]); ti->options_count++; } @@ -58,7 +58,7 @@ char *test_input_stringify(const TestInput *test_input, const char *postfix) char *msg = cs_mem_calloc(sizeof(char), msg_len); char *byte_seq = byte_seq_to_str(test_input->bytes, test_input->bytes_count); - char opt_seq[128] = {0}; + char opt_seq[128] = { 0 }; append_to_str(opt_seq, sizeof(opt_seq), "["); for (size_t i = 0; i < test_input->options_count; ++i) { append_to_str(opt_seq, sizeof(opt_seq), test_input->options[i]); @@ -69,8 +69,8 @@ char *test_input_stringify(const TestInput *test_input, const char *postfix) append_to_str(opt_seq, sizeof(opt_seq), "]"); cs_snprintf(msg, msg_len, "%sTestInput { arch: %s, options: %s, addr: 0x%" PRIx64 - ", bytes: %s }", postfix, - test_input->arch, opt_seq, test_input->address, + ", bytes: %s }", + postfix, test_input->arch, opt_seq, test_input->address, byte_seq); cs_mem_free(byte_seq); return msg; @@ -105,10 +105,12 @@ TestInsnData *test_insn_data_clone(TestInsnData *test_insn_data) tid->mnemonic = test_insn_data->mnemonic ? cs_strdup(test_insn_data->mnemonic) : NULL; - tid->op_str = test_insn_data->op_str ? cs_strdup(test_insn_data->op_str) : - NULL; - tid->asm_text = test_insn_data->asm_text ? cs_strdup(test_insn_data->asm_text) : - NULL; + tid->op_str = test_insn_data->op_str ? + cs_strdup(test_insn_data->op_str) : + NULL; + tid->asm_text = test_insn_data->asm_text ? + cs_strdup(test_insn_data->asm_text) : + NULL; if (test_insn_data->details) { tid->details = test_detail_clone(test_insn_data->details); } @@ -203,11 +205,13 @@ void test_expected_compare(csh *handle, TestExpected *expected, cs_insn *insns, // Either all in op_str or split in mnemonic and op_str char asm_text[256] = { 0 }; if (insns[i].mnemonic[0] != '\0') { - append_to_str(asm_text, sizeof(asm_text), insns[i].mnemonic); + append_to_str(asm_text, sizeof(asm_text), + insns[i].mnemonic); append_to_str(asm_text, sizeof(asm_text), " "); } if (insns[i].op_str[0] != '\0') { - append_to_str(asm_text, sizeof(asm_text), insns[i].op_str); + append_to_str(asm_text, sizeof(asm_text), + insns[i].op_str); } if (!compare_asm_text(asm_text, expec_data->asm_text, arch_bits)) { @@ -226,20 +230,24 @@ void test_expected_compare(csh *handle, TestExpected *expected, cs_insn *insns, } } if (expec_data->alias_id != 0) { - assert_int_equal(insns[i].alias_id, expec_data->alias_id); + assert_int_equal(insns[i].alias_id, + expec_data->alias_id); } if (expec_data->mnemonic) { - assert_string_equal(insns[i].mnemonic, expec_data->mnemonic); + assert_string_equal(insns[i].mnemonic, + expec_data->mnemonic); } if (expec_data->op_str) { - assert_string_equal(insns[i].op_str, expec_data->op_str); + assert_string_equal(insns[i].op_str, + expec_data->op_str); } if (expec_data->details) { if (!insns[i].detail) { fprintf(stderr, "detail is NULL\n"); assert_non_null(insns[i].detail); } - assert_true(test_expected_detail(handle, &insns[i], expec_data->details)); + assert_true(test_expected_detail(handle, &insns[i], + expec_data->details)); } } } diff --git a/suite/cstest/src/test_detail.c b/suite/cstest/src/test_detail.c index 3a6ab96d0a..426b9e9316 100644 --- a/suite/cstest/src/test_detail.c +++ b/suite/cstest/src/test_detail.c @@ -5,117 +5,138 @@ #include "test_compare.h" #include -TestDetail *test_detail_new() { - return cs_mem_calloc(sizeof(TestDetail), 1); +TestDetail *test_detail_new() +{ + return cs_mem_calloc(sizeof(TestDetail), 1); } -TestDetail *test_detail_clone(TestDetail *detail) { - assert(detail); - TestDetail *clone = test_detail_new(); - - clone->regs_read = detail->regs_read_count > 0 ? cs_mem_calloc(sizeof(char *), detail->regs_read_count) : NULL; - clone->regs_read_count = detail->regs_read_count; - for (size_t i = 0; i < detail->regs_read_count; ++i) { - clone->regs_read[i] = strdup(detail->regs_read[i]); - } - - clone->regs_write = detail->regs_write_count > 0 ? cs_mem_calloc(sizeof(char *), detail->regs_write_count) : NULL; - clone->regs_write_count = detail->regs_write_count; - for (size_t i = 0; i < detail->regs_write_count; ++i) { - clone->regs_write[i] = strdup(detail->regs_write[i]); - } - - clone->groups = detail->groups_count > 0 ? cs_mem_calloc(sizeof(char *), detail->groups_count) : NULL; - clone->groups_count = detail->groups_count; - for (size_t i = 0; i < detail->groups_count; ++i) { - clone->groups[i] = strdup(detail->groups[i]); - } - - if (detail->aarch64) { - clone->aarch64 = test_detail_aarch64_clone(detail->aarch64); - } - - if (detail->arm) { - clone->arm = test_detail_arm_clone(detail->arm); - } - - if (detail->ppc) { - clone->ppc = test_detail_ppc_clone(detail->ppc); - } - - return clone; +TestDetail *test_detail_clone(TestDetail *detail) +{ + assert(detail); + TestDetail *clone = test_detail_new(); + + clone->regs_read = + detail->regs_read_count > 0 ? + cs_mem_calloc(sizeof(char *), detail->regs_read_count) : + NULL; + clone->regs_read_count = detail->regs_read_count; + for (size_t i = 0; i < detail->regs_read_count; ++i) { + clone->regs_read[i] = strdup(detail->regs_read[i]); + } + + clone->regs_write = detail->regs_write_count > 0 ? + cs_mem_calloc(sizeof(char *), + detail->regs_write_count) : + NULL; + clone->regs_write_count = detail->regs_write_count; + for (size_t i = 0; i < detail->regs_write_count; ++i) { + clone->regs_write[i] = strdup(detail->regs_write[i]); + } + + clone->groups = + detail->groups_count > 0 ? + cs_mem_calloc(sizeof(char *), detail->groups_count) : + NULL; + clone->groups_count = detail->groups_count; + for (size_t i = 0; i < detail->groups_count; ++i) { + clone->groups[i] = strdup(detail->groups[i]); + } + + if (detail->aarch64) { + clone->aarch64 = test_detail_aarch64_clone(detail->aarch64); + } + + if (detail->arm) { + clone->arm = test_detail_arm_clone(detail->arm); + } + + if (detail->ppc) { + clone->ppc = test_detail_ppc_clone(detail->ppc); + } + + return clone; } -void test_detail_free(TestDetail *detail) { - if (!detail) { - return; - } - - for (size_t i = 0; i < detail->regs_read_count; ++i) { - cs_mem_free(detail->regs_read[i]); - } - cs_mem_free(detail->regs_read); - - for (size_t i = 0; i < detail->regs_write_count; ++i) { - cs_mem_free(detail->regs_write[i]); - } - cs_mem_free(detail->regs_write); - - for (size_t i = 0; i < detail->groups_count; ++i) { - cs_mem_free(detail->groups[i]); - } - cs_mem_free(detail->groups); - - if (detail->aarch64) { - test_detail_aarch64_free(detail->aarch64); - } - if (detail->arm) { - test_detail_arm_free(detail->arm); - } - if (detail->ppc) { - test_detail_ppc_free(detail->ppc); - } - - cs_mem_free(detail); +void test_detail_free(TestDetail *detail) +{ + if (!detail) { + return; + } + + for (size_t i = 0; i < detail->regs_read_count; ++i) { + cs_mem_free(detail->regs_read[i]); + } + cs_mem_free(detail->regs_read); + + for (size_t i = 0; i < detail->regs_write_count; ++i) { + cs_mem_free(detail->regs_write[i]); + } + cs_mem_free(detail->regs_write); + + for (size_t i = 0; i < detail->groups_count; ++i) { + cs_mem_free(detail->groups[i]); + } + cs_mem_free(detail->groups); + + if (detail->aarch64) { + test_detail_aarch64_free(detail->aarch64); + } + if (detail->arm) { + test_detail_arm_free(detail->arm); + } + if (detail->ppc) { + test_detail_ppc_free(detail->ppc); + } + + cs_mem_free(detail); } bool test_expected_detail(csh *handle, const cs_insn *insn, - TestDetail *expected) { - assert(handle && insn && insn->detail && expected); - cs_detail *actual = insn->detail; + TestDetail *expected) +{ + assert(handle && insn && insn->detail && expected); + cs_detail *actual = insn->detail; cs_regs regs_read, regs_write; uint8_t regs_read_count, regs_write_count; - cs_regs_access(*handle, insn, regs_read, ®s_read_count, regs_write, ®s_write_count); - - if (expected->regs_read_count > 0) { - compare_uint32_ret(regs_read_count, expected->regs_read_count, false); - for (size_t i = 0; i < regs_read_count; ++i) { - compare_reg_ret(*handle, regs_read[i], expected->regs_read[i], false); - } - } - - if (expected->regs_write_count > 0) { - compare_uint32_ret(regs_write_count, expected->regs_write_count, false); - for (size_t i = 0; i < regs_write_count; ++i) { - compare_reg_ret(*handle, regs_write[i], expected->regs_write[i], false); - } - } - - if (expected->groups_count > 0) { - compare_uint32_ret(actual->groups_count, expected->groups_count, false); - for (size_t i = 0; i < actual->groups_count; ++i) { - compare_reg_ret(*handle, actual->groups[i], expected->groups[i], false); - } - } - - if (expected->aarch64) { - return test_expected_aarch64(handle, &actual->aarch64, expected->aarch64); - } - if (expected->arm) { - return test_expected_arm(handle, &actual->arm, expected->arm); - } - if (expected->ppc) { - return test_expected_ppc(handle, &actual->ppc, expected->ppc); - } - return true; + cs_regs_access(*handle, insn, regs_read, ®s_read_count, regs_write, + ®s_write_count); + + if (expected->regs_read_count > 0) { + compare_uint32_ret(regs_read_count, expected->regs_read_count, + false); + for (size_t i = 0; i < regs_read_count; ++i) { + compare_reg_ret(*handle, regs_read[i], + expected->regs_read[i], false); + } + } + + if (expected->regs_write_count > 0) { + compare_uint32_ret(regs_write_count, expected->regs_write_count, + false); + for (size_t i = 0; i < regs_write_count; ++i) { + compare_reg_ret(*handle, regs_write[i], + expected->regs_write[i], false); + } + } + + if (expected->groups_count > 0) { + compare_uint32_ret(actual->groups_count, expected->groups_count, + false); + for (size_t i = 0; i < actual->groups_count; ++i) { + compare_reg_ret(*handle, actual->groups[i], + expected->groups[i], false); + } + } + + if (expected->aarch64) { + return test_expected_aarch64(handle, &actual->aarch64, + expected->aarch64); + } + if (expected->arm) { + return test_expected_arm(handle, &actual->arm, expected->arm); + } + if (expected->ppc) { + return test_expected_ppc(handle, &actual->ppc, expected->ppc); + } + return true; } diff --git a/suite/cstest/src/test_detail_aarch64.c b/suite/cstest/src/test_detail_aarch64.c index d92818183d..e3bf83a80d 100644 --- a/suite/cstest/src/test_detail_aarch64.c +++ b/suite/cstest/src/test_detail_aarch64.c @@ -35,7 +35,7 @@ TestDetailAArch64 *test_detail_aarch64_clone(TestDetailAArch64 *detail) clone->operands_count = detail->operands_count; if (detail->operands_count > 0) { clone->operands = cs_mem_calloc(sizeof(TestDetailAArch64Op), - detail->operands_count); + detail->operands_count); } for (size_t i = 0; i < detail->operands_count; ++i) { clone->operands[i] = @@ -167,7 +167,8 @@ bool test_expected_aarch64(csh *handle, cs_aarch64 *actual, compare_enum_ret(op->vas, eop->vas, false); compare_tbool_ret(op->is_vreg, eop->is_vreg, false); if (eop->vector_index_is_set) { - compare_int32_ret(op->vector_index, eop->vector_index, false); + compare_int32_ret(op->vector_index, eop->vector_index, + false); } compare_tbool_ret(op->is_list_member, eop->is_list_member, diff --git a/suite/cstest/src/test_detail_arm.c b/suite/cstest/src/test_detail_arm.c index 7731adf08e..5bc966e9f4 100644 --- a/suite/cstest/src/test_detail_arm.c +++ b/suite/cstest/src/test_detail_arm.c @@ -116,7 +116,8 @@ bool test_expected_arm(csh *handle, cs_arm *actual, TestDetailARM *expected) compare_uint8_ret(actual->op_count, expected->operands_count, false); if (expected->vector_size) { - compare_int_ret(actual->vector_size, expected->vector_size, false); + compare_int_ret(actual->vector_size, expected->vector_size, + false); } compare_enum_ret(actual->vector_data, expected->vector_data, false); compare_enum_ret(actual->cps_flag, expected->cps_flag, false); @@ -125,7 +126,8 @@ bool test_expected_arm(csh *handle, cs_arm *actual, TestDetailARM *expected) compare_enum_ret(actual->vcc, expected->vcc, false); compare_enum_ret(actual->mem_barrier, expected->mem_barrier, false); if (expected->pred_mask) { - compare_uint8_ret(actual->pred_mask, expected->pred_mask, false); + compare_uint8_ret(actual->pred_mask, expected->pred_mask, + false); } compare_tbool_ret(actual->usermode, expected->usermode, false); compare_tbool_ret(actual->update_flags, expected->update_flags, false); @@ -162,24 +164,24 @@ bool test_expected_arm(csh *handle, cs_arm *actual, TestDetailARM *expected) compare_enum_ret(op->sysop.reg.mclasssysreg, eop->sys_reg, false); if (eop->sys_sysm) { - compare_uint16_ret(op->sysop.sysm, eop->sys_sysm, - false); + compare_uint16_ret(op->sysop.sysm, + eop->sys_sysm, false); } if (eop->sys_msr_mask) { - compare_uint8_ret(op->sysop.msr_mask, eop->sys_msr_mask, - false); + compare_uint8_ret(op->sysop.msr_mask, + eop->sys_msr_mask, false); } break; case ARM_OP_BANKEDREG: compare_enum_ret(op->sysop.reg.bankedreg, eop->sys_reg, false); if (eop->sys_sysm) { - compare_uint16_ret(op->sysop.sysm, eop->sys_sysm, - false); + compare_uint16_ret(op->sysop.sysm, + eop->sys_sysm, false); } if (eop->sys_msr_mask) { - compare_uint8_ret(op->sysop.msr_mask, eop->sys_msr_mask, - false); + compare_uint8_ret(op->sysop.msr_mask, + eop->sys_msr_mask, false); } break; case ARM_OP_SPSR: @@ -188,22 +190,22 @@ bool test_expected_arm(csh *handle, cs_arm *actual, TestDetailARM *expected) eop->sys_psr_bits, eop->sys_psr_bits_count, false); if (eop->sys_sysm) { - compare_uint16_ret(op->sysop.sysm, eop->sys_sysm, - false); + compare_uint16_ret(op->sysop.sysm, + eop->sys_sysm, false); } if (eop->sys_msr_mask) { - compare_uint8_ret(op->sysop.msr_mask, eop->sys_msr_mask, - false); + compare_uint8_ret(op->sysop.msr_mask, + eop->sys_msr_mask, false); } break; case ARM_OP_SYSM: if (eop->sys_sysm) { - compare_uint16_ret(op->sysop.sysm, eop->sys_sysm, - false); + compare_uint16_ret(op->sysop.sysm, + eop->sys_sysm, false); } if (eop->sys_msr_mask) { - compare_uint8_ret(op->sysop.msr_mask, eop->sys_msr_mask, - false); + compare_uint8_ret(op->sysop.msr_mask, + eop->sys_msr_mask, false); } break; case ARM_OP_MEM: @@ -219,7 +221,8 @@ bool test_expected_arm(csh *handle, cs_arm *actual, TestDetailARM *expected) compare_enum_ret(op->shift.type, eop->shift_type, false); if (eop->shift_value) { - compare_uint32_ret(op->shift.value, eop->shift_value, false); + compare_uint32_ret(op->shift.value, eop->shift_value, + false); } if (eop->neon_lane) { compare_uint8_ret(op->neon_lane, eop->neon_lane, false); diff --git a/suite/cstest/src/test_run.c b/suite/cstest/src/test_run.c index a478251558..43c18aba4e 100644 --- a/suite/cstest/src/test_run.c +++ b/suite/cstest/src/test_run.c @@ -108,8 +108,8 @@ static bool parse_input_options(const TestInput *input, cs_arch *arch, for (size_t i = 0; i < input->options_count; ++i) { opt_str = options[i]; val = enum_map_bin_search(test_mode_map, - ARR_SIZE(test_mode_map), opt_str, - &mode_found); + ARR_SIZE(test_mode_map), opt_str, + &mode_found); if (mode_found) { *mode |= val; goto next_option;