@@ -55,7 +55,7 @@ TestInput *test_input_clone(TestInput *test_input)
55
55
return ti ;
56
56
}
57
57
58
- char * test_input_stringify (const TestInput * test_input , const char * postfix )
58
+ char * test_input_stringify (const TestInput * test_input , const char * prefix )
59
59
{
60
60
size_t msg_len = 2048 ;
61
61
char * msg = cs_mem_calloc (sizeof (char ), msg_len );
@@ -75,11 +75,12 @@ char *test_input_stringify(const TestInput *test_input, const char *postfix)
75
75
}
76
76
}
77
77
str_append_no_realloc (opt_seq , sizeof (opt_seq ), "]" );
78
- cs_snprintf (msg , msg_len ,
79
- "%sTestInput { arch: %s, options: %s, addr: 0x%" PRIx64
80
- ", bytes: %s }" ,
81
- postfix , test_input -> arch , opt_seq , test_input -> address ,
82
- byte_seq );
78
+ cs_snprintf (
79
+ msg , msg_len ,
80
+ "%sTestInput { name: %s, arch: %s, options: %s, addr: 0x%" PRIx64
81
+ ", bytes: %s }" ,
82
+ prefix , test_input -> name , test_input -> arch , opt_seq ,
83
+ test_input -> address , byte_seq );
83
84
cs_mem_free (byte_seq );
84
85
return msg ;
85
86
}
@@ -213,6 +214,17 @@ static bool ids_match(uint32_t actual, const char *expected)
213
214
return true;
214
215
}
215
216
217
+ static void _print_insn (csh * handle , cs_insn * insn )
218
+ {
219
+ cm_print_error ("Failed instruction: %s %s" , insn -> mnemonic ,
220
+ insn -> op_str );
221
+ cm_print_error ("(0x%x" , insn -> bytes [0 ]);
222
+ for (int i = 1 ; i < insn -> size ; i ++ ) {
223
+ cm_print_error (", 0x%x" , insn -> bytes [i ]);
224
+ }
225
+ cm_print_error ("%s" , ")\n" );
226
+ }
227
+
216
228
/// Compares the decoded instructions @insns against the @expected values and returns the result.
217
229
void test_expected_compare (csh * handle , TestExpected * expected , cs_insn * insns ,
218
230
size_t insns_count , size_t arch_bits )
@@ -233,53 +245,76 @@ void test_expected_compare(csh *handle, TestExpected *expected, cs_insn *insns,
233
245
str_append_no_realloc (asm_text , sizeof (asm_text ),
234
246
insns [i ].op_str );
235
247
}
248
+
249
+ #define CS_TEST_FAIL (msg ) \
250
+ _print_insn(handle, &insns[i]); \
251
+ fail_msg(msg);
252
+
236
253
if (!compare_asm_text (asm_text , expec_data -> asm_text ,
237
254
arch_bits )) {
238
- fail_msg ("asm-text mismatch\n" );
255
+ CS_TEST_FAIL ("asm-text mismatch\n" );
239
256
}
240
257
241
258
// Not mandatory fields. If not initialized they should still match.
242
259
if (expec_data -> id ) {
243
- assert_true (ids_match ((uint32_t )insns [i ].id ,
244
- expec_data -> id ));
260
+ if (!ids_match ((uint32_t )insns [i ].id , expec_data -> id )) {
261
+ CS_TEST_FAIL ("ids mismatch" );
262
+ }
245
263
}
246
264
if (expec_data -> is_alias != 0 ) {
247
265
if (expec_data -> is_alias > 0 ) {
248
- assert_true (insns [i ].is_alias );
266
+ if (!insns [i ].is_alias ) {
267
+ CS_TEST_FAIL ("should be an alias" );
268
+ }
249
269
} else {
250
- assert_false (insns [i ].is_alias );
270
+ if (insns [i ].is_alias ) {
271
+ CS_TEST_FAIL ("should not be an alias" );
272
+ }
251
273
}
252
274
}
253
275
if (expec_data -> illegal != 0 ) {
254
276
if (expec_data -> illegal > 0 ) {
255
- assert_true (insns [i ].illegal );
277
+ if (!insns [i ].illegal ) {
278
+ CS_TEST_FAIL ("should be illegal" );
279
+ }
256
280
} else {
257
- assert_false (insns [i ].illegal );
281
+ if (insns [i ].illegal ) {
282
+ CS_TEST_FAIL ("should not be illegal" );
283
+ }
258
284
}
259
285
}
260
286
if (expec_data -> size ) {
261
- assert_int_equal (insns [i ].size , expec_data -> size );
287
+ if (insns [i ].size != expec_data -> size ) {
288
+ CS_TEST_FAIL ("size mismatch" );
289
+ }
262
290
}
263
291
if (expec_data -> alias_id ) {
264
- assert_true (ids_match ((uint32_t )insns [i ].alias_id ,
265
- expec_data -> alias_id ));
292
+ if (!ids_match ((uint32_t )insns [i ].alias_id ,
293
+ expec_data -> alias_id )) {
294
+ CS_TEST_FAIL ("alias ids mismatch" );
295
+ }
266
296
}
267
297
if (expec_data -> mnemonic ) {
268
- assert_string_equal (insns [i ].mnemonic ,
269
- expec_data -> mnemonic );
298
+ if (strcmp (insns [i ].mnemonic , expec_data -> mnemonic ) !=
299
+ 0 ) {
300
+ CS_TEST_FAIL ("mnemonics don't match" );
301
+ }
270
302
}
271
303
if (expec_data -> op_str ) {
272
- assert_string_equal (insns [i ].op_str ,
273
- expec_data -> op_str );
304
+ if (strcmp (insns [i ].op_str , expec_data -> op_str ) != 0 ) {
305
+ CS_TEST_FAIL ("operands don't match" );
306
+ }
274
307
}
275
308
if (expec_data -> details ) {
276
309
if (!insns [i ].detail ) {
277
- fprintf (stderr , "detail is NULL\n" );
278
- assert_non_null (insns [i ].detail );
310
+ CS_TEST_FAIL ("detail is NULL" );
311
+ }
312
+ if (!test_expected_detail (handle , & insns [i ],
313
+ expec_data -> details )) {
314
+ CS_TEST_FAIL ("test_expected_detail" );
279
315
}
280
- assert_true (test_expected_detail (handle , & insns [i ],
281
- expec_data -> details ));
282
316
}
317
+ #undef CS_TEST_FAIL
283
318
}
284
319
}
285
320
0 commit comments