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