brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 9e10ef1 Raw
53 lines · cpp
1//===-- Unittests for posix_spawn -----------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "test_binary_properties.h"10 11#include "hdr/stdint_proxy.h"12#include "src/spawn/posix_spawn.h"13#include "src/spawn/posix_spawn_file_actions_addopen.h"14#include "src/spawn/posix_spawn_file_actions_destroy.h"15#include "src/spawn/posix_spawn_file_actions_init.h"16#include "src/sys/wait/waitpid.h"17#include "test/IntegrationTest/test.h"18 19#include <fcntl.h>20#include <spawn.h>21#include <stddef.h>22#include <sys/wait.h>23 24char arg0[] = "libc_posix_spawn_test_binary";25char *argv[] = {26    arg0,27    nullptr,28};29 30void spawn_and_wait_for_normal_exit(char **envp) {31  pid_t cpid;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,37                                        argv, envp),38            0);39  ASSERT_TRUE(cpid > 0);40  int status;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);46}47 48TEST_MAIN([[maybe_unused]] int argc, [[maybe_unused]] char **argv,49          char **envp) {50  spawn_and_wait_for_normal_exit(envp);51  return 0;52}53