• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <signal.h>
3 #include <unistd.h>
4 using namespace testing::ext;
5 
6 class ExitAbortTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: abort_001
13  * @tc.desc: Verify that calling the abort function in a child process leads to expected termination with the
14  *           SIGABRT signal.
15  * @tc.type: FUNC
16  **/
17 HWTEST_F(ExitAbortTest, abort_001, TestSize.Level1)
18 {
19     pid_t pid = fork();
20     if (pid == -1) {
21         perror("Error forking process");
22     } else if (pid == 0) {
23         abort();
24     } else {
25         int status;
26         waitpid(pid, &status, 0);
27         if (WIFSIGNALED(status)) {
28             int sigNum = WTERMSIG(status);
29             EXPECT_EQ(SIGABRT, sigNum);
30         }
31     }
32 }
33