xref: /xnu-10063.121.3/tests/vm/diag_threshold_test_double_limit.c (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /**
2*2c2f96dcSApple OSS Distributions  *  double_limit_test.c
3*2c2f96dcSApple OSS Distributions  *  DiagThresholdTest
4*2c2f96dcSApple OSS Distributions  *
5*2c2f96dcSApple OSS Distributions  * Test the check if reloading a memory diagnostics limit retriggers exceptions
6*2c2f96dcSApple OSS Distributions  * Copyright (c) 2022 Apple Inc. All rights reserved.
7*2c2f96dcSApple OSS Distributions  */
8*2c2f96dcSApple OSS Distributions #include <stdio.h>
9*2c2f96dcSApple OSS Distributions #include "vm/diag_threshold_test.h"
10*2c2f96dcSApple OSS Distributions #include <sys/kern_memorystatus.h>
11*2c2f96dcSApple OSS Distributions static void double_limit_test_execution(struct test_case *test_case, void *param);
12*2c2f96dcSApple OSS Distributions static test_case_t double_limit_test = {
13*2c2f96dcSApple OSS Distributions 	.short_name = "double_limit_test",
14*2c2f96dcSApple OSS Distributions 	.test_name = "Test on which the diagnostics limit limit is set twice and expects two exceptions",
15*2c2f96dcSApple OSS Distributions 	.test_code = double_limit_test_execution,
16*2c2f96dcSApple OSS Distributions 	.result_already_present = FALSE,
17*2c2f96dcSApple OSS Distributions 	.exception_not_expected = FALSE,
18*2c2f96dcSApple OSS Distributions };
19*2c2f96dcSApple OSS Distributions 
20*2c2f96dcSApple OSS Distributions T_GLOBAL_META(
21*2c2f96dcSApple OSS Distributions 	T_META_ENABLED(TARGET_OS_IPHONE),
22*2c2f96dcSApple OSS Distributions 	T_META_NAMESPACE("xnu.vm.100432442"),
23*2c2f96dcSApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
24*2c2f96dcSApple OSS Distributions 	T_META_OWNER("jsolsona"),
25*2c2f96dcSApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("VM")
26*2c2f96dcSApple OSS Distributions 	);
27*2c2f96dcSApple OSS Distributions 
28*2c2f96dcSApple OSS Distributions static void
double_limit_test_execution(struct test_case * test_case,void * param)29*2c2f96dcSApple OSS Distributions double_limit_test_execution(struct test_case *test_case, void *param)
30*2c2f96dcSApple OSS Distributions {
31*2c2f96dcSApple OSS Distributions 	test_context_t *info = (test_context_t *)param;
32*2c2f96dcSApple OSS Distributions 	(void)set_memory_diagnostics_threshold_limits(WORKING_LIMIT, true);
33*2c2f96dcSApple OSS Distributions 	diag_mem_threshold_waste_memory(TEST_LIMIT);
34*2c2f96dcSApple OSS Distributions 	if (FALSE == diag_mem_threshold_wait_for_exception(info)) {
35*2c2f96dcSApple OSS Distributions 		test_case->did_pass = FALSE;
36*2c2f96dcSApple OSS Distributions 		test_case->result_already_present = TRUE;
37*2c2f96dcSApple OSS Distributions 		diag_mem_threshold_log_test("Giving up in wait, terminating\n");
38*2c2f96dcSApple OSS Distributions 		pthread_exit(NULL);
39*2c2f96dcSApple OSS Distributions 	}
40*2c2f96dcSApple OSS Distributions 
41*2c2f96dcSApple OSS Distributions 	dispatch_semaphore_signal(info->executor_ready_for_exceptions);
42*2c2f96dcSApple OSS Distributions 	sleep(1);
43*2c2f96dcSApple OSS Distributions 	(void)set_memory_diagnostics_threshold_limits(WORKING_LIMIT, true);
44*2c2f96dcSApple OSS Distributions 	diag_mem_threshold_log_test("First exception seen, reloading limits and preparing second exception\n");
45*2c2f96dcSApple OSS Distributions 	diag_mem_threshold_waste_memory(TEST_LIMIT);
46*2c2f96dcSApple OSS Distributions 	diag_mem_threshold_log_test("Finished wasting memory, existing\n");
47*2c2f96dcSApple OSS Distributions }
48*2c2f96dcSApple OSS Distributions 
49*2c2f96dcSApple OSS Distributions T_DECL(diag_mem_threshold_double_limit_test,
50*2c2f96dcSApple OSS Distributions     "Test on which the diagnostics limit limit is set twice and expects two exceptions"
51*2c2f96dcSApple OSS Distributions     )
52*2c2f96dcSApple OSS Distributions {
53*2c2f96dcSApple OSS Distributions 	diag_mem_threshold_set_setup(&double_limit_test);
54*2c2f96dcSApple OSS Distributions }
55