xref: /xnu-10002.1.13/tests/nvram_tests/nvram_ve_mod.c (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a) !
1 #include <darwintest.h>
2 #include "nvram_helper.h"
3 
4 T_GLOBAL_META(T_META_NAMESPACE("xnu.nvram"),
5     T_META_RADAR_COMPONENT_NAME("xnu"),
6     T_META_RADAR_COMPONENT_VERSION("nvram"));
7 
8 static io_registry_entry_t optionsRef = IO_OBJECT_NULL;
9 
10 // xcrun -sdk iphoneos.internal make -C tests nvram_ve_mod && sudo ./tests/build/sym/nvram_ve_mod
11 
12 // Test that writing, deleting and reseting of entitled variables with entitlement should succeed
13 // To reset nvram, call the test with -r argument:
14 // sudo ./tests/build/sym/nvram_ve_mod -n xnu.nvram.TestEntModRstEnt -- -r
15 T_DECL(TestEntModRstEnt, "Test mod of entitled variables")
16 {
17 	opterr = 0;
18 	optind = 0;
19 #if !(__x86_64__)
20 	char * varToTest = "testEntModRst";
21 
22 	optionsRef = CreateOptionsRef();
23 
24 	TestVarOp(OP_SET, varToTest, DefaultSetVal, KERN_SUCCESS, optionsRef);
25 	TestVarOp(OP_DEL, varToTest, NULL, KERN_SUCCESS, optionsRef);
26 
27 	if (getopt(argc, argv, "r") == 'r') {
28 		TestVarOp(OP_SET, varToTest, DefaultSetVal, KERN_SUCCESS, optionsRef);
29 		TestVarOp(OP_RES, NULL, NULL, KERN_SUCCESS, optionsRef);
30 		TestVarOp(OP_GET, varToTest, NULL, KERN_FAILURE, optionsRef);
31 	} else {
32 		T_PASS("NVram reset not invoked");
33 	}
34 
35 	ReleaseOptionsRef(optionsRef);
36 #else
37 	T_PASS("Test not supported");
38 #endif /* !(__x86_64__) */
39 }
40 
41 #if ((TARGET_OS_OSX) && !(__x86_64__))
42 // Test that writing, deleting and reseting of entitled system variables with entitlement should succeed
43 // To reset nvram, call the test with -r argument:
44 // sudo ./tests/build/sym/nvram_ve_mod -n xnu.nvram.TestEntModRstSysEnt -- -r
45 T_DECL(TestEntModRstSysEnt, "Test mod of entitled system variables")
46 {
47 	opterr = 0;
48 	optind = 0;
49 	char * varToTest = SystemNVRAMGuidString ":" "testEntModRstSys";
50 
51 	optionsRef = CreateOptionsRef();
52 
53 	TestVarOp(OP_SET, varToTest, DefaultSetVal, KERN_SUCCESS, optionsRef);
54 	TestVarOp(OP_DEL, varToTest, NULL, KERN_SUCCESS, optionsRef);
55 
56 	if (getopt(argc, argv, "r") == 'r') {
57 		TestVarOp(OP_SET, varToTest, DefaultSetVal, KERN_SUCCESS, optionsRef);
58 		TestVarOp(OP_RES, NULL, NULL, KERN_SUCCESS, optionsRef);
59 		TestVarOp(OP_GET, varToTest, NULL, KERN_FAILURE, optionsRef);
60 	} else {
61 		T_PASS("NVram reset not invoked");
62 	}
63 
64 	ReleaseOptionsRef(optionsRef);
65 }
66 #endif /* ((TARGET_OS_OSX) && !(__x86_64__)) */
67