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_cmds.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "config.h"
  2. #include <check.h>
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include "asmsh_check.h"
  7. #include "shell_cmds.h"
  8. #include "logger.h"
  9. typedef struct {
  10. const char *cmd;
  11. const char *parsed;
  12. const int argc;
  13. const char **args;
  14. } parse_cmds_t;
  15. static const char *args0[]={NULL};
  16. static const char *args1[]={"hello", "world", NULL};
  17. static const char *args2[]={"mov", "$0x42,", "%rax", NULL};
  18. static const parse_cmds_t parse_cmds[] = {
  19. {".foo",
  20. ".foo", 0, args0},
  21. {".a.b hello world",
  22. ".a.b", 2, args1},
  23. {".b mov $0x42, %rax",
  24. ".b", 3, args2},
  25. };
  26. START_TEST(parse)
  27. {
  28. asmsh_logger_t *log = asmsh_logger_new(ASMSH_TRACE);
  29. asmsh_logger_setup(log);
  30. const parse_cmds_t *cmd = &parse_cmds[_i];
  31. asmsh_cmd_args_t *args = asmsh_cmd_parse(cmd->cmd);
  32. asmsh_logger_dprint(2, _default_logger);
  33. ck_assert_ptr_nonnull(args);
  34. ck_assert_str_eq(args->cmd, cmd->parsed);
  35. ck_assert_int_eq(args->argc, cmd->argc);
  36. for(int i=0; i<args->argc; i++)
  37. {
  38. ck_assert_str_eq(args->args[i], cmd->args[i]);
  39. }
  40. ck_assert_ptr_null(args->args[args->argc]);
  41. asmsh_cmd_args_free(args);
  42. }
  43. END_TEST
  44. START_TEST(test_cmds)
  45. {
  46. asmsh_t sh;
  47. ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
  48. ck_assert_int_eq(asmsh_exec(&sh, ".h"), 0);
  49. ck_assert_int_eq(asmsh_exec(&sh, ".help"), 0);
  50. ck_assert_int_eq(asmsh_exec(&sh, ".b"), -1);
  51. ck_assert_int_eq(asmsh_exec(&sh, ".bytecode syscall"), 0);
  52. ck_assert_int_eq(asmsh_exec(&sh, ".bytecode mov $42, %rax"), 0);
  53. ck_assert_int_eq(asmsh_exec(&sh, "push %rax"), 0);
  54. ck_assert_int_eq(asmsh_exec(&sh, ".b"), 0);
  55. ck_assert_int_eq(asmsh_exec(&sh, ".flags"), 0);
  56. ck_assert_int_eq(asmsh_exec(&sh, ".reset"), 0);
  57. ck_assert_int_eq(asmsh_exec(&sh, ".b"), -1);
  58. ck_assert_int_eq(asmsh_exec(&sh, ".xxdsdfsdfsdfsdf"), -1);
  59. ck_assert_int_eq(asmsh_exec(&sh, ".q"), 1);
  60. asmsh_cleanup(&sh);
  61. }
  62. END_TEST
  63. ASMSH_CHECK_START("shell commands tests", "testing shell commands")
  64. ASMSH_ADD_LOOP(parse, parse_cmds);
  65. ASMSH_ADD_TEST(test_cmds);
  66. ASMSH_CHECK_END