1 //===-- Unittests for execve ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/sys/wait/waitpid.h"
10 #include "src/unistd/execve.h"
11 #include "src/unistd/fork.h"
13 #include "test/IntegrationTest/test.h"
18 void fork_and_execv_normal_exit(char **envp
) {
19 pid_t pid
= LIBC_NAMESPACE::fork();
21 const char *path
= "libc_execv_test_normal_exit";
22 char *const argv
[] = {
23 const_cast<char *>("execv_test_normal_exit"),
26 LIBC_NAMESPACE::execve(path
, argv
, envp
);
30 pid_t cpid
= LIBC_NAMESPACE::waitpid(pid
, &status
, 0);
31 ASSERT_TRUE(cpid
> 0);
33 ASSERT_TRUE(WIFEXITED(status
));
36 void fork_and_execv_signal_exit(char **envp
) {
37 pid_t pid
= LIBC_NAMESPACE::fork();
39 const char *path
= "libc_execv_test_signal_exit";
40 char *const argv
[] = {
41 const_cast<char *>("execv_test_normal_exit"),
44 LIBC_NAMESPACE::execve(path
, argv
, envp
);
48 pid_t cpid
= LIBC_NAMESPACE::waitpid(pid
, &status
, 0);
49 ASSERT_TRUE(cpid
> 0);
51 ASSERT_FALSE(WIFEXITED(status
));
52 ASSERT_TRUE(WTERMSIG(status
) == SIGUSR1
);
55 TEST_MAIN(int argc
, char **argv
, char **envp
) {
56 fork_and_execv_normal_exit(envp
);
57 fork_and_execv_signal_exit(envp
);