1 #include <cxxabi.h> 2 #include <gtest/gtest.h> 3 #include <stdint.h> 4 #include <stdlib.h> 5 6 using namespace testing::ext; 7 8 class ExitCxaAtexitTest : public testing::Test { SetUp()9 void SetUp() override {} TearDown()10 void TearDown() override {} 11 }; 12 13 extern "C" int __cxa_atexit(void (*func)(void*), void* arg, void* dso); 14 extern "C" void __cxa_finalize(void* dso); 15 16 /** 17 * @tc.name: __cxa_atexit_001 18 * @tc.desc: Verify the functionality of the __cxa_atexit and __cxa_finalize functions, ensuring that registered exit 19 * handlers are properly executed when the program exits. 20 * @tc.type: FUNC 21 */ 22 HWTEST_F(ExitCxaAtexitTest, __cxa_atexit_001, TestSize.Level1) 23 { 24 int exitCount = 0; __anon2d6e78590102(void* arg) 25 __cxa_atexit([](void* arg) { ++*static_cast<int*>(arg); }, &exitCount, &exitCount); 26 __cxa_finalize(&exitCount); 27 EXPECT_EQ(exitCount, 1); 28 __cxa_finalize(&exitCount); 29 EXPECT_EQ(exitCount, 1); 30 }