#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
extern int do_execve_test(char * path, char * argv[], void * envp, int killwait);
extern int get_bits(void);
int g_testbots_active = 0;
int main(int argc, const char * argv[])
{
int my_err, my_status;
pid_t my_pid, my_wait_pid;
char * errmsg = NULL;
char * argvs[2] = {"", NULL};
int bits = get_bits();
#if defined(__i386__)
errmsg = "execve failed: from i386 forking and exec()ing i386 process.\n";
argvs[0] = "sleep-i386";
if (do_execve_test("helpers/sleep-i386", argvs, NULL, 0)) goto test_failed_exit;
errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4G pagezero.\n";
argvs[0] = "sleep-x86_64-4G";
if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 0)) goto test_failed_exit;
errmsg = "execve failed: from i386 forking and exec()ing x86_64 process w/ 4K pagezero.\n";
argvs[0] = "sleep-x86_64-4K";
if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 0)) goto test_failed_exit;
#endif
#if defined(__x86_64__)
errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4G pagezero.\n";
argvs[0] = "sleep-x86_64-4G";
if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 1)) goto test_failed_exit;
errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4K Pagezero.\n";
argvs[0] = "sleep-x86_64-4K";
if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 1)) goto test_failed_exit;
errmsg = "execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\n";
argvs[0] = "sleep-i386";
if (do_execve_test("helpers/sleep-i386", argvs, NULL, 1)) goto test_failed_exit;
#endif
sleep(4);
return 0;
test_failed_exit:
if (errmsg)
printf("%s", errmsg);
return -1;
}