• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Capstone testing regression */
2 /* By Do Minh Tuan <tuanit96@gmail.com>, 02-2019 */
3 
4 
5 #ifndef CAPSTONE_TEST_H
6 #define CAPSTONE_TEST_H
7 
8 #include <stdarg.h>
9 #include <stddef.h>
10 #include <setjmp.h>
11 #include <cmocka.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <capstone/capstone.h>
15 #include "helper.h"
16 #include "factory.h"
17 
18 #define cs_assert_err(expect, err)									\
19 	do {																\
20 		cs_err __err = err;												\
21 		if (__err != expect) {											\
22 			fail_msg("%s",cs_strerror(__err));							\
23 		}																\
24 	} while (0)
25 
26 
27 #define cs_assert_success(err) cs_assert_err(CS_ERR_OK, err)
28 
29 
30 #define cs_assert_fail(err)											\
31 	do {																\
32 		cs_err __err = err;												\
33 		if (__err == CS_ERR_OK) {										\
34 			fail_msg("%s",cs_strerror(__err));							\
35 		}																\
36 	} while (0)
37 
38 #define NUMARCH 9
39 #define NUMMODE 33
40 #define NUMOPTION 41
41 #define MAXMEM 1024
42 
43 typedef struct {
44 	const char *str;
45 	unsigned int value;
46 } single_dict;
47 
48 typedef struct {
49 	const char *str;
50 	unsigned int first_value;
51 	unsigned int second_value;
52 } double_dict;
53 
54 extern single_dict arches[];
55 extern single_dict modes[];
56 extern double_dict options[];
57 extern char *(*function)(csh *, cs_mode, cs_insn*);
58 
59 int get_index(double_dict d[], unsigned size, const char *str);
60 int get_value(single_dict d[], unsigned size, const char *str);
61 void test_single_MC(csh *handle, int mc_mode, char *line);
62 void test_single_issue(csh *handle, cs_mode mode, char *line, int detail);
63 int set_function(int arch);
64 
65 #endif /* CAPSTONE_TEST_H */
66