A shell that runs x86_64 assembly
c
x86-64
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tests_shell.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. START_TEST(test_embed)
  41. {
  42. asmsh_t sh;
  43. ck_assert_int_eq(asmsh_init(&sh, NULL), 0);
  44. ck_assert_int_eq(asmsh_exec(&sh, "mov $60, %rax"), 0);
  45. ck_assert_int_eq(asmsh_exec(&sh, "xor %rdi, %rdi"), 0);
  46. ck_assert_int_eq(asmsh_exec(&sh, "syscall"), 1);
  47. asmsh_cleanup(&sh);
  48. }
  49. END_TEST
  50. ASMSH_CHECK_START("Testing shell", "testing shell init/exec functions")
  51. ASMSH_ADD_TEST(test_init);
  52. ASMSH_ADD_TEST(test_exit);
  53. ASMSH_ADD_TEST(test_cmd);
  54. ASMSH_ADD_TEST(test_embed);
  55. ASMSH_CHECK_END