1 /**
2 * simple_test.c
3 * DiagThresholdTest
4 *
5 * Test that enable and disables diagnostics threshold limits
6 * Copyright (c) 2022 Apple Inc. All rights reserved.
7 */
8
9 #include <stdio.h>
10 #include "vm/diag_threshold_test.h"
11 #include <sys/kern_memorystatus.h>
12
13 static void enable_disable_threshold_test_execution(struct test_case *test_case, void *param);
14 T_GLOBAL_META(
15 T_META_ENABLED(TARGET_OS_IPHONE),
16 T_META_NAMESPACE("xnu.vm.100432442"),
17 T_META_RADAR_COMPONENT_NAME("xnu"),
18 T_META_OWNER("jsolsona"),
19 T_META_RADAR_COMPONENT_VERSION("VM")
20 );
21
22
23 static test_case_t diag_mem_threshold_no_limit_cross_test = {
24 .short_name = "enable_disable_threshold_test",
25 .test_name = "This test tests a threshold, disables it and consumes memory to validate the limit is gone",
26 .test_code = enable_disable_threshold_test_execution,
27 .result_already_present = FALSE,
28 .exception_not_expected = TRUE,
29 };
30
31
32 static void
enable_disable_threshold_test_execution(__unused struct test_case * test_case,void * param)33 enable_disable_threshold_test_execution(__unused struct test_case *test_case, void *param)
34 {
35 test_context_t *info = (test_context_t *)param;
36 dispatch_semaphore_signal(info->executor_ready_for_exceptions);
37 (void)set_memory_diagnostics_threshold_limits(WORKING_LIMIT, true);
38 (void)set_memory_diagnostics_threshold_limits(-1, true);
39 diag_mem_threshold_waste_memory(WORKING_LIMIT - (1024 * 1024));
40 }
41
42 T_DECL(diag_mem_enable_disable_threshold_test,
43 "This test tests a threshold, disables it and consumes memory to validate the limit is gone",
44 T_META_TAG_VM_PREFERRED)
45 {
46 diag_mem_threshold_set_setup(&diag_mem_threshold_no_limit_cross_test);
47 }
48