1 //===-- Unittests for posix_spawn -----------------------------------------===//
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 "test_binary_properties.h"
11 #include "src/spawn/posix_spawn.h"
12 #include "src/spawn/posix_spawn_file_actions_addopen.h"
13 #include "src/spawn/posix_spawn_file_actions_destroy.h"
14 #include "src/spawn/posix_spawn_file_actions_init.h"
15 #include "src/sys/wait/waitpid.h"
16 #include "test/IntegrationTest/test.h"
24 char arg0
[] = "libc_posix_spawn_test_binary";
30 void spawn_and_wait_for_normal_exit(char **envp
) {
32 posix_spawn_file_actions_t file_actions
;
33 ASSERT_EQ(LIBC_NAMESPACE::posix_spawn_file_actions_init(&file_actions
), 0);
34 LIBC_NAMESPACE::posix_spawn_file_actions_addopen(
35 &file_actions
, CHILD_FD
, "testdata/posix_spawn.test", O_RDONLY
, 0);
36 ASSERT_EQ(LIBC_NAMESPACE::posix_spawn(&cpid
, arg0
, &file_actions
, nullptr,
39 ASSERT_TRUE(cpid
> 0);
41 ASSERT_EQ(LIBC_NAMESPACE::waitpid(cpid
, &status
, 0), cpid
);
42 ASSERT_EQ(LIBC_NAMESPACE::posix_spawn_file_actions_destroy(&file_actions
), 0);
43 ASSERT_TRUE(WIFEXITED(status
));
44 int exit_status
= WEXITSTATUS(status
);
45 ASSERT_EQ(exit_status
, 0);
48 TEST_MAIN(int argc
, char **argv
, char **envp
) {
49 spawn_and_wait_for_normal_exit(envp
);