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