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