A dynamic tracer for Linux

arch-x86_64_test.c 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <linux/ptrace.h>
  2. #include <stdint.h>
  3. #include "unittest.h"
  4. #include "arch.h"
  5. #include "type.h"
  6. static int arch_x86_64_sizeof(void *_null)
  7. {
  8. unittest_eq(type_sizeof(&t_s8), sizeof(int8_t));
  9. unittest_eq(type_sizeof(&t_u8), sizeof(uint8_t));
  10. unittest_eq(type_sizeof(&t_s16), sizeof(int16_t));
  11. unittest_eq(type_sizeof(&t_u16), sizeof(uint16_t));
  12. unittest_eq(type_sizeof(&t_s32), sizeof(int32_t));
  13. unittest_eq(type_sizeof(&t_u32), sizeof(uint32_t));
  14. unittest_eq(type_sizeof(&t_s64), sizeof(int64_t));
  15. unittest_eq(type_sizeof(&t_u64), sizeof(uint64_t));
  16. return 0;
  17. }
  18. UNITTEST(arch_x86_64_sizeof);
  19. static int arch_x86_64_pt_regs(void *_null)
  20. {
  21. unittest_eq(type_offsetof(&t_pt_regs, "r15"), offsetof(struct pt_regs, r15));
  22. unittest_eq(type_offsetof(&t_pt_regs, "r14"), offsetof(struct pt_regs, r14));
  23. unittest_eq(type_offsetof(&t_pt_regs, "r13"), offsetof(struct pt_regs, r13));
  24. unittest_eq(type_offsetof(&t_pt_regs, "r12"), offsetof(struct pt_regs, r12));
  25. unittest_eq(type_offsetof(&t_pt_regs, "rbp"), offsetof(struct pt_regs, rbp));
  26. unittest_eq(type_offsetof(&t_pt_regs, "rbx"), offsetof(struct pt_regs, rbx));
  27. unittest_eq(type_offsetof(&t_pt_regs, "r11"), offsetof(struct pt_regs, r11));
  28. unittest_eq(type_offsetof(&t_pt_regs, "r10"), offsetof(struct pt_regs, r10));
  29. unittest_eq(type_offsetof(&t_pt_regs, "r9"), offsetof(struct pt_regs, r9));
  30. unittest_eq(type_offsetof(&t_pt_regs, "r8"), offsetof(struct pt_regs, r8));
  31. unittest_eq(type_offsetof(&t_pt_regs, "rax"), offsetof(struct pt_regs, rax));
  32. unittest_eq(type_offsetof(&t_pt_regs, "rcx"), offsetof(struct pt_regs, rcx));
  33. unittest_eq(type_offsetof(&t_pt_regs, "rdx"), offsetof(struct pt_regs, rdx));
  34. unittest_eq(type_offsetof(&t_pt_regs, "rsi"), offsetof(struct pt_regs, rsi));
  35. unittest_eq(type_offsetof(&t_pt_regs, "rdi"), offsetof(struct pt_regs, rdi));
  36. unittest_eq(type_offsetof(&t_pt_regs, "orig_rax"), offsetof(struct pt_regs, orig_rax));
  37. unittest_eq(type_offsetof(&t_pt_regs, "rip"), offsetof(struct pt_regs, rip));
  38. unittest_eq(type_offsetof(&t_pt_regs, "cs"), offsetof(struct pt_regs, cs));
  39. unittest_eq(type_offsetof(&t_pt_regs, "eflags"), offsetof(struct pt_regs, eflags));
  40. unittest_eq(type_offsetof(&t_pt_regs, "rsp"), offsetof(struct pt_regs, rsp));
  41. unittest_eq(type_offsetof(&t_pt_regs, "ss"), offsetof(struct pt_regs, ss));
  42. unittest_eq(type_alignof(&t_pt_regs), __alignof__(struct pt_regs));
  43. unittest_eq(type_sizeof(&t_pt_regs), sizeof(struct pt_regs));
  44. return 0;
  45. }
  46. UNITTEST(arch_x86_64_pt_regs);
  47. int main(void)
  48. {
  49. struct unittest_ctx ctx = {
  50. .keep_going = 1,
  51. .verbose = 1,
  52. .ctx = NULL,
  53. };
  54. return unittests_run(&ctx) ? 1 : 0;
  55. }