• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <errno.h>
2 #include <gtest/gtest.h>
3 #include <stdlib.h>
4 
5 using namespace testing::ext;
6 
7 class ExitQuickExitTest : public testing::Test {
SetUp()8     void SetUp() override {}
TearDown()9     void TearDown() override {}
10 };
11 
12 /**
13  * @tc.name: quick_exit_001
14  * @tc.desc: Verify that the parent process can correctly wait for the child process to exit and retrieve its exit
15  *           status after the child process calls quick_exit.
16  * @tc.type: FUNC
17  */
18 HWTEST_F(ExitQuickExitTest, quick_exit_001, TestSize.Level1)
19 {
20     int status;
21     pid_t pid = fork();
22     if (pid == 0) {
23         sleep(1);
24         quick_exit(EXIT_SUCCESS);
25     } else if (pid > 0) {
26         while ((pid = wait(&status)) == -1) {
27             if (errno != EINTR) {
28                 exit(EXIT_FAILURE);
29             }
30         }
31         if (WIFEXITED(status)) {
32             EXPECT_EQ(WEXITSTATUS(status), EXIT_SUCCESS);
33         }
34     } else {
35         exit(EXIT_FAILURE);
36     }
37 }