3 #include <sys/sysctl.h>
5 #include <darwintest.h>
8 #include "test_utils.h"
11 #define SET_TREATMENT_ID set_treatment_id_entitled
12 #define SET_TREATMENT_ID_DESCR "Can set treatment id with entitlement"
14 #define SET_TREATMENT_ID set_treatment_id_unentitled
15 #define SET_TREATMENT_ID_DESCR "Can't set treatment id without entitlement"
18 T_DECL(SET_TREATMENT_ID
, "Verifies that EXPERIMENT sysctls can only be set with the entitlement", T_META_ASROOT(false))
20 #define TEST_STR "testing"
21 #define IDENTIFIER_LENGTH 36
25 char val
[IDENTIFIER_LENGTH
+ 1] = {0};
26 size_t len
= sizeof(val
);
27 char new_val
[IDENTIFIER_LENGTH
+ 1] = {0};
29 if (!is_development_kernel()) {
30 T_SKIP("skipping test on release kernel");
33 strlcpy(new_val
, TEST_STR
, sizeof(new_val
));
36 ret
= sysctlbyname("kern.trial_treatment_id", val
, &len
, new_val
, strlen(new_val
));
40 memset(new_val
, 0, sizeof(new_val
));
41 T_ASSERT_POSIX_SUCCESS(ret
, "set kern.trial_treatment_id");
42 /* Cleanup. Set it back to the empty string. */
43 ret
= sysctlbyname("kern.trial_treatment_id", val
, &len
, new_val
, 1);
44 T_QUIET
; T_ASSERT_POSIX_SUCCESS(ret
, "reset kern.trial_treatment_id");
46 T_ASSERT_POSIX_FAILURE(ret
, EPERM
, "set kern.trial_treatment_id");
51 /* Check min and max value limits on numeric factors */
52 T_DECL(experiment_factor_numeric_limits
,
53 "Can only set factors within the legal range.",
56 #define kMinVal 5 /* The min value allowed for the testing factor. */
57 #define kMaxVal 10 /* The max value allowed for the testing factor. */
60 unsigned int current_val
;
61 size_t len
= sizeof(current_val
);
65 new_val
= kMinVal
- 1;
66 ret
= sysctlbyname("kern.testing_experiment_factor", ¤t_val
, &len
, &new_val
, sizeof(new_val
));
68 T_ASSERT_POSIX_FAILURE(ret
, EINVAL
, "set kern.testing_experiment_factor below range.");
70 new_val
= kMaxVal
+ 1;
71 ret
= sysctlbyname("kern.testing_experiment_factor", ¤t_val
, &len
, &new_val
, sizeof(new_val
));
73 T_ASSERT_POSIX_FAILURE(ret
, EINVAL
, "set kern.testing_experiment_factor above range.");
76 ret
= sysctlbyname("kern.testing_experiment_factor", ¤t_val
, &len
, &new_val
, sizeof(new_val
));
77 T_ASSERT_POSIX_SUCCESS(ret
, "set kern.testing_experiment_factor at top of range.");
80 ret
= sysctlbyname("kern.testing_experiment_factor", ¤t_val
, &len
, &new_val
, sizeof(new_val
));
81 T_ASSERT_POSIX_SUCCESS(ret
, "set kern.testing_experiment_factor at bottom of range.");