]> git.saurik.com Git - apple/libc.git/blob - tests/darwin_bsd.c
Libc-1353.41.1.tar.gz
[apple/libc.git] / tests / darwin_bsd.c
1 #include <darwintest.h>
2
3 #include "../libdarwin/bsd.c"
4
5 static struct test_case {
6 const char *args;
7 const char *argname;
8 const char *argvalue;
9 } test_cases[] = {
10 {"-x -a b=3 y=42", "-a", ""},
11 {"-x -a b=3 y=42", "b", "3"},
12 {"-x -a b=2 ba=3 y=42", "b", "2"},
13 {"-x -a ba=3 b=2 y=42", "b", "2"},
14 {"-x -a b=2 ba=3 y=42", "ba", "3"},
15 {"-x -a ba=3 b=2 y=42", "ba", "3"},
16 {"-x -ab -aa y=42", "-a", NULL},
17 {"-x b=96 y=42", "bx", NULL},
18 {"-x ab=96 y=42", "a", NULL},
19 };
20
21 T_DECL(parse_boot_arg_value, "Parsing boot args")
22 {
23 for (int i = 0; i < (int)(sizeof(test_cases)/sizeof(test_cases[0])); i++) {
24 struct test_case *test_case = &test_cases[i];
25 T_LOG("\"%s\": Looking for \"%s\", expecting \"%s\"",
26 test_case->args, test_case->argname, test_case->argvalue);
27
28 char *argbuff = strdup(test_case->args);
29
30 char result[256] = "NOT_FOUND";
31 bool found = _parse_boot_arg_value(argbuff, test_case->argname,
32 result,sizeof(result));
33
34 if (test_case->argvalue) {
35 T_EXPECT_EQ(found, true, "Should find argument");
36 T_EXPECT_EQ_STR(result, test_case->argvalue, "Should find correct result");
37 } else {
38 T_EXPECT_EQ(found, false, "Should not find argument");
39 }
40
41 free(argbuff);
42 }
43 }
44
45 T_DECL(os_parse_boot_arg, "Getting boot args")
46 {
47 int64_t value = 0;
48 T_EXPECT_EQ(os_parse_boot_arg_int("notarealthing", &value), false, NULL);
49
50 T_MAYFAIL;
51 T_EXPECT_EQ(os_parse_boot_arg_int("debug", &value), true, NULL);
52 T_EXPECT_GT(value, 0LL, "non-zero debug= value");
53
54 char buf[64] = {};
55
56 T_EXPECT_EQ(os_parse_boot_arg_string("notarealthing", buf, sizeof(buf)), false, NULL);
57
58 T_MAYFAIL;
59 T_EXPECT_EQ(os_parse_boot_arg_string("debug", buf, sizeof(buf)), true, NULL);
60 T_EXPECT_GT(strlen(buf), 0UL, "non-empty debug= value");
61 }