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