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