1 #include <r_debug.h>
2 #include "minunit.h"
3 #if __linux__
4 #include <sys/user.h>
5 
6 #ifndef offsetof
7 #define offsetof(type, field) ((size_t) &((type *)0)->field)
8 #endif
9 
10 #endif //__linux__
11 
test_r_debug_use(void)12 bool test_r_debug_use(void) {
13 	RDebug *dbg;
14 	bool res;
15 
16 	dbg = r_debug_new (true);
17 	mu_assert_notnull (dbg, "r_debug_new () failed");
18 
19 	res = r_debug_use (dbg, "null");
20 	mu_assert_eq (res, true, "r_debug_use () failed");
21 
22 	r_debug_free (dbg);
23 	mu_end;
24 }
25 
test_r_debug_reg_offset(void)26 bool test_r_debug_reg_offset(void) {
27 #if __linux__
28 #ifdef __x86_64__
29 #define FPREGS struct user_fpregs_struct
30 	FPREGS regs;
31 	mu_assert_eq (sizeof (regs.cwd), 2, "cwd size");
32 	mu_assert_eq (offsetof (FPREGS, cwd), 0, "cwd offset");
33 
34 	mu_assert_eq (sizeof (regs.rip), 8, "rip size");
35 	mu_assert_eq (offsetof (FPREGS, rip), 8, "rip offset");
36 
37 	mu_assert_eq (sizeof (regs.mxcsr), 4, "mxcsr size");
38 	mu_assert_eq (offsetof (FPREGS, mxcsr), 24, "mxcsr offset");
39 
40 	mu_assert_eq (sizeof (regs.mxcr_mask), 4, "mxcr_mask size");
41 	mu_assert_eq (offsetof (FPREGS, mxcr_mask), 28, "mxcr_mask offset");
42 
43 	mu_assert_eq (sizeof (regs.st_space[0]) * 2, 8, "st0 size");
44 	mu_assert_eq (offsetof (FPREGS, st_space[0]), 32, "st0 offset");
45 
46 	mu_assert_eq (sizeof (regs.xmm_space[0]) * 4, 16, "xmm0 size");
47 	mu_assert_eq (offsetof (FPREGS, xmm_space[0]), 160, "xmm0 offset");
48 
49 	mu_assert_eq (offsetof (FPREGS, padding[0]), 416, "x64");
50 #endif //__x86_64__
51 #endif //__linux__
52 	mu_end;
53 }
54 
all_tests()55 int all_tests() {
56 	mu_run_test (test_r_debug_use);
57 	mu_run_test (test_r_debug_reg_offset);
58 	return tests_passed != tests_run;
59 }
60 
main(int argc,char ** argv)61 int main(int argc, char **argv) {
62 	return all_tests ();
63 }
64