A shell that runs x86_64 assembly
c
x86-64
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tests_shell.c 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "config.h"
  2. #include <check.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include "asmsh_check.h"
  8. #include "shell.h"
  9. START_TEST(test_init)
  10. {
  11. asmsh_t sh;
  12. ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
  13. asmsh_cleanup(&sh);
  14. }
  15. END_TEST
  16. START_TEST(test_exit)
  17. {
  18. asmsh_t sh;
  19. ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
  20. ck_assert_int_eq(asmsh_exec(&sh, "mov $60, %rax"), 0);
  21. ck_assert_int_eq(asmsh_exec(&sh, "xor %rdi, %rdi"), 0);
  22. ck_assert_int_eq(asmsh_exec(&sh, "syscall"), 1);
  23. asmsh_cleanup(&sh);
  24. ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
  25. ck_assert_int_eq(asmsh_exec(&sh, "mov $60, %rax"), 0);
  26. ck_assert_int_eq(asmsh_exec(&sh, "mov $0x29, %rdi"), 0);
  27. ck_assert_int_eq(asmsh_exec(&sh, "syscall"), 42);
  28. asmsh_cleanup(&sh);
  29. }
  30. END_TEST
  31. START_TEST(test_cmd)
  32. {
  33. asmsh_t sh;
  34. ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
  35. ck_assert_int_eq(asmsh_exec(&sh, ".reg"), 0);
  36. ck_assert_int_eq(asmsh_exec(&sh, ".q"), 1);
  37. asmsh_cleanup(&sh);
  38. }
  39. END_TEST
  40. ASMSH_CHECK_START("Testing shell", "testing shell init/exec functions")
  41. ASMSH_ADD_TEST(test_init);
  42. ASMSH_ADD_TEST(test_exit);
  43. ASMSH_ADD_TEST(test_cmd);
  44. ASMSH_CHECK_END