1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "config.h"
-
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #include "asmsh_check.h"
- #include "shell_cmds.h"
- #include "logger.h"
-
- typedef struct {
- const char *cmd;
- const char *parsed;
- const int argc;
- const char **args;
- } parse_cmds_t;
-
- static const char *args0[]={NULL};
- static const char *args1[]={"hello", "world", NULL};
- static const char *args2[]={"mov", "$0x42,", "%rax", NULL};
- static const parse_cmds_t parse_cmds[] = {
- {".foo",
- ".foo", 0, args0},
- {".a.b hello world",
- ".a.b", 2, args1},
- {".b mov $0x42, %rax",
- ".b", 3, args2},
- };
- START_TEST(parse)
- {
- asmsh_logger_t *log = asmsh_logger_new(ASMSH_TRACE);
- asmsh_logger_setup(log);
- const parse_cmds_t *cmd = &parse_cmds[_i];
- asmsh_cmd_args_t *args = asmsh_cmd_parse(cmd->cmd);
- asmsh_logger_dprint(2, _default_logger);
- ck_assert_ptr_nonnull(args);
- ck_assert_str_eq(args->cmd, cmd->parsed);
- ck_assert_int_eq(args->argc, cmd->argc);
- for(int i=0; i<args->argc; i++)
- {
- ck_assert_str_eq(args->args[i], cmd->args[i]);
- }
- ck_assert_ptr_null(args->args[args->argc]);
- asmsh_cmd_args_free(args);
- }
- END_TEST
-
-
- START_TEST(test_cmds)
- {
- asmsh_t sh;
- ck_assert_int_eq(asmsh_init(&sh, CHILD_PATH), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".h"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".help"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".b"), -1);
- ck_assert_int_eq(asmsh_exec(&sh, ".bytecode syscall"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".bytecode mov $42, %rax"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, "push %rax"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".b"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".flags"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".reset"), 0);
- ck_assert_int_eq(asmsh_exec(&sh, ".b"), -1);
- ck_assert_int_eq(asmsh_exec(&sh, ".xxdsdfsdfsdfsdf"), -1);
- ck_assert_int_eq(asmsh_exec(&sh, ".q"), 1);
- asmsh_cleanup(&sh);
-
- }
- END_TEST
-
- ASMSH_CHECK_START("shell commands tests", "testing shell commands")
- ASMSH_ADD_LOOP(parse, parse_cmds);
- ASMSH_ADD_TEST(test_cmds);
- ASMSH_CHECK_END
|