1*a1e26a70SApple OSS Distributions #include <darwintest.h> 2*a1e26a70SApple OSS Distributions #include <darwintest_utils.h> 3*a1e26a70SApple OSS Distributions 4*a1e26a70SApple OSS Distributions #define STATIC_IF_TEST 5*a1e26a70SApple OSS Distributions #define MARK_AS_FIXUP_TEXT 6*a1e26a70SApple OSS Distributions 7*a1e26a70SApple OSS Distributions #include "../osfmk/kern/static_if_common.c" 8*a1e26a70SApple OSS Distributions 9*a1e26a70SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), T_META_TAG_VM_PREFERRED); 10*a1e26a70SApple OSS Distributions 11*a1e26a70SApple OSS Distributions T_DECL(static_if_boot_arg, "Check the static if boot-arg parser") 12*a1e26a70SApple OSS Distributions { 13*a1e26a70SApple OSS Distributions uint64_t v; 14*a1e26a70SApple OSS Distributions 15*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=2", "key", 0); 16*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 2ull, "parsing key correctly"); 17*a1e26a70SApple OSS Distributions 18*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=2 key=1", "key", 0); 19*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "parsing overrides"); 20*a1e26a70SApple OSS Distributions 21*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("-key", "key", 0); 22*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "parsing -key"); 23*a1e26a70SApple OSS Distributions 24*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key", "key", 0); 25*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "parsing arg-less key"); 26*a1e26a70SApple OSS Distributions 27*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=2 k", "key", 0); 28*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 2ull, "parsing ignoring prefixes at the end"); 29*a1e26a70SApple OSS Distributions 30*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0", "key", 1); 31*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 0ull, "parsing key=0 correctly"); 32*a1e26a70SApple OSS Distributions /* this should be rejected but PE_parse_boot_argn accepts it */ 33*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0b", "key", 1); 34*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 0ull, "be bug to bug compatible with PE_parse_boot_argn"); 35*a1e26a70SApple OSS Distributions 36*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0x", "key", 1); 37*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 0ull, "be bug to bug compatible with PE_parse_boot_argn"); 38*a1e26a70SApple OSS Distributions 39*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0b1010", "key", 1); 40*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 10, "parsing binary correctly"); 41*a1e26a70SApple OSS Distributions 42*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=-0b1010", "key", 1); 43*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, -10, "parsing binary correctly"); 44*a1e26a70SApple OSS Distributions 45*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=012", "key", 1); 46*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 10, "parsing fake octal correctly"); 47*a1e26a70SApple OSS Distributions 48*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=-012", "key", 1); 49*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, -10, "parsing hex correctly"); 50*a1e26a70SApple OSS Distributions 51*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0xa", "key", 1); 52*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 10, "parsing hex correctly"); 53*a1e26a70SApple OSS Distributions 54*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=-0xa", "key", 1); 55*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, -10, "parsing hex correctly"); 56*a1e26a70SApple OSS Distributions 57*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=0xA", "key", 1); 58*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 10, "parsing hex correctly"); 59*a1e26a70SApple OSS Distributions 60*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=-0xA", "key", 1); 61*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, -10, "parsing hex correctly"); 62*a1e26a70SApple OSS Distributions 63*a1e26a70SApple OSS Distributions /* invalid values */ 64*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=09", "key", 1); 65*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "rejecting 09"); 66*a1e26a70SApple OSS Distributions 67*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=8a9", "key", 1); 68*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "rejecting 8a9"); 69*a1e26a70SApple OSS Distributions 70*a1e26a70SApple OSS Distributions v = static_if_boot_arg_uint64("key=a", "key", 1); 71*a1e26a70SApple OSS Distributions T_EXPECT_EQ(v, 1ull, "rejecting a"); 72*a1e26a70SApple OSS Distributions } 73