]> git.saurik.com Git - apple/xnu.git/blame - tests/vm_set_max_addr_test.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / tests / vm_set_max_addr_test.c
CommitLineData
d9a64523
A
1#include <sys/wait.h>
2#include <spawn.h>
3#include <spawn_private.h>
4
5#include <mach/mach_init.h>
6#include <mach/mach_vm.h>
7
8#include <darwintest.h>
9#include <darwintest_utils.h>
10
11extern char * testpath;
12
13T_DECL(set_max_addr,
14 "Description",
15 T_META_NAMESPACE("xnu.vm"),
16 T_META_CHECK_LEAKS(false))
17{
18#if (defined(__arm64__) && defined(__LP64__))
19 int result = 0;
20 int code = 0;
21 int child_pid = 0;
22 int status = 0;
23 char * command_path = "./vm_set_max_addr_helper";
24 char * command_args[] = { command_path, NULL };
25 posix_spawnattr_t attrp;
26
27 result = posix_spawnattr_init(&attrp);
28 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_init");
29
30 result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL);
31 T_ASSERT_POSIX_SUCCESS(result, "posix_spawn");
32
33 result = waitpid(child_pid, &status, 0);
34 T_ASSERT_POSIX_SUCCESS(result, "waitpid");
35
36 code = WEXITSTATUS(status);
37 T_ASSERT_NE_INT(code, 0, "Child should have failed");
38
39 result = posix_spawnattr_set_max_addr_np(&attrp, ~0ULL);
40 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_set_max_addr_np");
41
42 result = posix_spawn(&child_pid, command_path, NULL, &attrp, command_args, NULL);
43 T_ASSERT_POSIX_SUCCESS(result, "posix_spawn");
44
45 result = waitpid(child_pid, &status, 0);
46 T_ASSERT_POSIX_SUCCESS(result, "waitpid");
47
48 code = WEXITSTATUS(status);
49 T_ASSERT_EQ_INT(code, 0, "Child should have succeeded");
50
51 posix_spawnattr_destroy(&attrp);
52 T_ASSERT_POSIX_SUCCESS(result, "posix_spawnattr_destroy");
53#else /* !defined(__arm64__) || !defined(__LP64__) */
54 T_SKIP("Not supported on this architecture");
55#endif /* (defined(__arm64__) && defined(__LP64__)) */
56}
57