1 /**
2 * diag_threshold_test_no_retrigger_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
12 static void diag_threshold_test_no_retrigger_execution(struct test_case *test_case, void *param);
13 T_GLOBAL_META(
14 T_META_ENABLED(TARGET_OS_IPHONE),
15 T_META_NAMESPACE("xnu.vm.100432442"),
16 T_META_RADAR_COMPONENT_NAME("xnu"),
17 T_META_OWNER("jsolsona"),
18 T_META_RADAR_COMPONENT_VERSION("VM")
19 );
20
21 static test_case_t diag_threshold_test_no_retrigger_test = {
22 .short_name = "diag_threshold_test_no_retrigger_test",
23 .test_name = "Set a limit, consume memory, free, and expect no other exception",
24 .test_code = diag_threshold_test_no_retrigger_execution,
25 .result_already_present = FALSE,
26 .exception_not_expected = TRUE,
27 };
28
29
30 static void
diag_threshold_test_no_retrigger_execution(struct test_case * test_case,void * param)31 diag_threshold_test_no_retrigger_execution(struct test_case *test_case, void *param)
32 {
33 test_context_t *info = (test_context_t *)param;
34 (void)set_memory_diagnostics_threshold_limits(WORKING_LIMIT, true);
35 diag_mem_threshold_waste_memory(TEST_LIMIT);
36 if (FALSE == diag_mem_threshold_wait_for_exception(info)) {
37 test_case->did_pass = FALSE;
38 test_case->result_already_present = TRUE;
39 diag_mem_threshold_log_test("Giving up in wait, terminating\n");
40 pthread_exit(NULL);
41 }
42
43 dispatch_semaphore_signal(info->executor_ready_for_exceptions);
44 sleep(1);
45 diag_mem_threshold_log_test("First exception seen, consuming again and not expecting exception\n");
46 diag_mem_threshold_waste_memory(TEST_LIMIT);
47 diag_mem_threshold_log_test("Finished wasting memory, existing\n");
48 }
49
50 T_DECL(diag_threshold_test_no_retrigger_test,
51 "Set a limit, consume memory, free, and expect no other exception", T_META_TAG_VM_PREFERRED)
52 {
53 diag_mem_threshold_set_setup(&diag_threshold_test_no_retrigger_test);
54 }
55