• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <sys/types.h>
3 #include <sys/wait.h>
4 #include <unistd.h>
5 
6 using namespace testing::ext;
7 
8 constexpr int BUF_SIZE = 128;
9 
10 class UnistdExitTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: _Exit_001
17  * @tc.desc: Ensure that the basic operations of the file can function properly.
18  * @tc.type: FUNC
19  * */
20 HWTEST_F(UnistdExitTest, _Exit_001, TestSize.Level1)
21 {
22     int pipefd[2];
23     ASSERT_NE(-1, pipe(pipefd));
24     pid_t pid = fork();
25     if (pid == 0) {
26         close(pipefd[0]);
27         write(pipefd[1], "before exit", sizeof("before exit"));
28         close(pipefd[1]);
29         _Exit(0);
30         write(pipefd[1], "after exit", sizeof("after exit"));
31     } else {
32         close(pipefd[1]);
33         char buffer[BUF_SIZE];
34         read(pipefd[0], buffer, sizeof(buffer));
35         close(pipefd[0]);
36         EXPECT_STREQ("before exit", buffer);
37     }
38 }