diff options
author | alk3pInjection <webmaster@raspii.tech> | 2023-09-19 11:54:48 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2023-09-19 11:54:48 +0800 |
commit | 1f228a245c017c29af2cc6b4940d54a1bde1ccf5 (patch) | |
tree | e5d6b84320a919b32b5e6d6bf7685b06e6e85265 /services/gpuservice/tests/unittests/GpuServiceTest.cpp | |
parent | 49c3334ee7df733514a7eaf6add950324a77f53d (diff) | |
parent | ca7349a398d992d359e7b05f5a15cd5a3e37e6bb (diff) |
Merge tag 'LA.QSSI.13.0.r1-11500.01-qssi.0' into tachibana-mr1tachibana-mr1
"LA.QSSI.13.0.r1-11500.01-qssi.0"
Change-Id: Ic650a04d35ae3e9f8442cfd11e5a3c966fad882d
Diffstat (limited to 'services/gpuservice/tests/unittests/GpuServiceTest.cpp')
-rw-r--r-- | services/gpuservice/tests/unittests/GpuServiceTest.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/services/gpuservice/tests/unittests/GpuServiceTest.cpp b/services/gpuservice/tests/unittests/GpuServiceTest.cpp new file mode 100644 index 0000000000..62b3e53f53 --- /dev/null +++ b/services/gpuservice/tests/unittests/GpuServiceTest.cpp @@ -0,0 +1,52 @@ +#undef LOG_TAG +#define LOG_TAG "gpuservice_unittest" + +#include "gpuservice/GpuService.h" + +#include <gtest/gtest.h> +#include <log/log_main.h> + +#include <chrono> +#include <thread> + +namespace android { +namespace { + +class GpuServiceTest : public testing::Test { +public: + GpuServiceTest() { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); + } + + ~GpuServiceTest() { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); + } + +}; + + +/* +* The behaviour before this test + fixes was UB caused by threads accessing deallocated memory. +* +* This test creates the service (which initializes the culprit threads), +* deallocates it immediately and sleeps. +* +* GpuService's destructor gets called and joins the threads. +* If we haven't crashed by the time the sleep time has elapsed, we're good +* Let the test pass. +*/ +TEST_F(GpuServiceTest, onInitializeShouldNotCauseUseAfterFree) { + sp<GpuService> service = new GpuService(); + service.clear(); + std::this_thread::sleep_for(std::chrono::seconds(3)); + + // If we haven't crashed yet due to threads accessing freed up memory, let the test pass + EXPECT_TRUE(true); +} + +} // namespace +} // namespace android |