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