]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/xnu_quick_test/helpers/launch.c
xnu-2782.40.9.tar.gz
[apple/xnu.git] / tools / tests / xnu_quick_test / helpers / launch.c
CommitLineData
2d21ac55
A
1/*
2 * Part of the execve tests. This program should not be compiled fat. xnu_quick_test
3 * will call the various single-architecture builds of this program as helpers to test
4 * the exec() transitions it cannot test itself.
5 *
6 * When running on a 64-bit machine (x86_64 or PPC64), the 32-bit version of
7 * xnu_quick_test will fork and exec a 64-bit helper process that performs
8 * the following tests.
9 * 1. 64 bit process forking() 64-bit child, child execing() 64-bit file(4GB pagezero)
10 * 2. 64 bit process forking() 64-bit child, child execing() 64-bit file (4KB pagezero)
11 * 3. 64 bit process forking() 64-bit child, child execing() 32-bit file
12 *
13 * The 64-bit version of xnu_quick_test will fork and exec a 32-bit process
14 * that performs the following tests.
15 * 4. 32 bit process forking() 32-bit child, child execing() 32-bit file
16 * 5. 32 bit process forking() 32-bit child, child execing() 64 bit file (4GB pagezero)
17 * 6. 32 bit process forking() 32-bit child, child execing() 64 bit file (4KB pagezero)
18 */
19
20#include <stdio.h>
316670eb 21#include <unistd.h>
2d21ac55
A
22#include <sys/types.h>
23#include <sys/syscall.h>
24
25extern int do_execve_test(char * path, char * argv[], void * envp, int killwait);
26extern int get_bits(void);
27
39236c6e 28int g_testbots_active = 0;
2d21ac55
A
29int main(int argc, const char * argv[])
30{
31 int my_err, my_status;
32 pid_t my_pid, my_wait_pid;
33 char * errmsg = NULL;
34 char * argvs[2] = {"", NULL};
35 int bits = get_bits(); /* Gets actual processor bit-ness. */
36
37#if defined(__i386__)
38 /*
39 * This is the helper binary for the x86_64 version of xnu_quick_test. xnu_quick_test
40 * forks and execs this code to test exec()ing from a 32-bit binary.
41 */
42 errmsg = "execve failed: from i386 forking and exec()ing i386 process.\n";
43 argvs[0] = "sleep-i386";
44 if (do_execve_test("helpers/sleep-i386", argvs, NULL, 0)) goto test_failed_exit;
45
46 errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4G pagezero.\n";
47 argvs[0] = "sleep-x86_64-4G";
48 if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 0)) goto test_failed_exit;
49
50 errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4K pagezero.\n";
51 argvs[0] = "sleep-x86_64-4K";
52 if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 0)) goto test_failed_exit;
53#endif
54
55
56#if defined(__x86_64__)
57 /*
58 * This is the helper binary for the i386 version of xnu_quick_test. xnu_quick_test
59 * forks and execs this code to test exec()ing from a 64-bit binary.
60 */
61 errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4G pagezero.\n";
62 argvs[0] = "sleep-x86_64-4G";
63 if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 1)) goto test_failed_exit;
64
65 errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4K Pagezero.\n";
66 argvs[0] = "sleep-x86_64-4K";
67 if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 1)) goto test_failed_exit;
68
69 errmsg = "execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\n";
70 argvs[0] = "sleep-i386";
71 if (do_execve_test("helpers/sleep-i386", argvs, NULL, 1)) goto test_failed_exit;
72#endif
73
74
b0d623f7
A
75 /*
76 * We are ourselves launched with do_execve_test, which wants a chance to
77 * send a SIGKILL
78 */
79 sleep(4);
2d21ac55
A
80 return 0;
81
82test_failed_exit:
83 if (errmsg)
84 printf("%s", errmsg);
85 return -1;
86}
87