summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Duong <joshuaduong@google.com>2022-04-07 09:44:19 -0700
committerJoshua Duong <joshuaduong@google.com>2022-04-12 09:11:21 -0700
commit8da31f587dc24407af520e17afe82b328eff2017 (patch)
tree2a9ff8db0595e9b3109cb4ce6ba304f2e5576e38
parentff4eb6b51150f263a7e90b4275858e455a365ab9 (diff)
downloadvulkan-cereal-8da31f587dc24407af520e17afe82b328eff2017.tar.gz
Remove main function from VirtioGpuTimelines_unittest.cpp.
This fixes a segfault on linux when running Vulkan_unittests. VirtioGpuTimelines_unittest's main is interfering with the entry point in host-common/testing/MockAndroidAgentFactory.cpp. So get rid of these custom main functions and simply inject the mock agents whereever it is needed. Bug: b/224794781 Test: Vulkan_unittests Change-Id: Ic3278aed8a68903c686ad2f3c669b833fd93f910
-rw-r--r--host-common/HostAddressSpace_unittest.cpp7
-rw-r--r--host-common/address_space_graphics_unittests.cpp7
-rw-r--r--host-common/testing/MockAndroidAgentFactory.cpp35
-rw-r--r--host-common/testing/MockAndroidAgentFactory.h16
-rw-r--r--stream-servers/CMakeLists.txt4
-rw-r--r--stream-servers/tests/DefaultFramebufferBlit_unittest.cpp8
-rw-r--r--stream-servers/tests/FrameBuffer_unittest.cpp8
-rw-r--r--stream-servers/tests/GLSnapshotRendering_unittest.cpp8
-rw-r--r--stream-servers/tests/VirtioGpuTimelines_unittest.cpp5
-rw-r--r--stream-servers/tests/Vulkan_unittest.cpp8
10 files changed, 45 insertions, 61 deletions
diff --git a/host-common/HostAddressSpace_unittest.cpp b/host-common/HostAddressSpace_unittest.cpp
index fbbd6abd..26cc9570 100644
--- a/host-common/HostAddressSpace_unittest.cpp
+++ b/host-common/HostAddressSpace_unittest.cpp
@@ -17,6 +17,7 @@
#include "host-common/AndroidAgentFactory.h"
#include "host-common/address_space_device.h"
#include "host-common/address_space_device.hpp"
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include <gtest/gtest.h>
@@ -24,11 +25,13 @@ namespace android {
class HostAddressSpaceTest : public ::testing::Test {
protected:
- static void SetUpTestCase() {
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
emulation::goldfish_address_space_set_vm_operations(getConsoleAgents()->vm);
}
- static void TearDownTestCase() { }
+ static void TearDownTestSuite() { }
void SetUp() override {
mDevice = HostAddressSpaceDevice::get();
diff --git a/host-common/address_space_graphics_unittests.cpp b/host-common/address_space_graphics_unittests.cpp
index 82b653df..32c76717 100644
--- a/host-common/address_space_graphics_unittests.cpp
+++ b/host-common/address_space_graphics_unittests.cpp
@@ -29,6 +29,7 @@
#include "host-common/address_space_device.hpp" // for goldfish...
#include "host-common/address_space_graphics.h" // for AddressS...
#include "host-common/address_space_graphics_types.h" // for asg_context
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include "testing/HostAddressSpace.h" // for HostAddr...
#include "host-common/globals.h" // for android_hw
@@ -550,11 +551,13 @@ public:
};
protected:
- static void SetUpTestCase() {
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
goldfish_address_space_set_vm_operations(getConsoleAgents()->vm);
}
- static void TearDownTestCase() { }
+ static void TearDownTestSuite() { }
void SetUp() override {
android_hw->hw_gltransport_asg_writeBufferSize = 524288;
diff --git a/host-common/testing/MockAndroidAgentFactory.cpp b/host-common/testing/MockAndroidAgentFactory.cpp
index a17783ad..e0ac989d 100644
--- a/host-common/testing/MockAndroidAgentFactory.cpp
+++ b/host-common/testing/MockAndroidAgentFactory.cpp
@@ -17,14 +17,6 @@
#include "gtest/gtest.h"
-#ifdef _WIN32
-using android::emulation::WindowsFlags;
-bool WindowsFlags::sIsParentProcess = true;
-HANDLE WindowsFlags::sChildRead = nullptr;
-HANDLE WindowsFlags::sChildWrite = nullptr;
-char WindowsFlags::sFileLockPath[MAX_PATH] = {};
-#endif
-
extern "C" const QAndroidVmOperations* const gMockQAndroidVmOperations;
extern "C" const QAndroidEmulatorWindowAgent* const
gMockQAndroidEmulatorWindowAgent;
@@ -50,30 +42,3 @@ MockAndroidConsoleFactory::android_get_QAndroidEmulatorWindowAgent() const {
}
} // namespace emulation
} // namespace android
-
-
-// The gtest entry point that will configure the mock agents.
-int main(int argc, char** argv) {
-#ifdef _WIN32
-#define _READ_STR "--read"
-#define _WRITE_STR "--write"
-#define _FILE_PATH_STR "--file-lock-path"
- for (int i = 1; i < argc; i++) {
- if (!strcmp("--child", argv[i])) {
- WindowsFlags::sIsParentProcess = false;
- } else if (!strncmp(_READ_STR, argv[i], strlen(_READ_STR))) {
- sscanf(argv[i], _READ_STR "=%p", &WindowsFlags::sChildRead);
- } else if (!strncmp(_WRITE_STR, argv[i], strlen(_WRITE_STR))) {
- sscanf(argv[i], _WRITE_STR "=%p", &WindowsFlags::sChildWrite);
- } else if (!strncmp(_FILE_PATH_STR, argv[i], strlen(_FILE_PATH_STR))) {
- sscanf(argv[i], _FILE_PATH_STR "=%s",
- WindowsFlags::sFileLockPath);
- }
- }
-#endif
- ::testing::InitGoogleTest(&argc, argv);
- fprintf(stderr, " -- Injecting mock agents. -- \n");
- android::emulation::injectConsoleAgents(
- android::emulation::MockAndroidConsoleFactory());
- return RUN_ALL_TESTS();
-}
diff --git a/host-common/testing/MockAndroidAgentFactory.h b/host-common/testing/MockAndroidAgentFactory.h
index 8f931d10..b37afc63 100644
--- a/host-common/testing/MockAndroidAgentFactory.h
+++ b/host-common/testing/MockAndroidAgentFactory.h
@@ -13,10 +13,6 @@
// limitations under the License.
#pragma once
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
#include <stdio.h>
#include "host-common/AndroidAgentFactory.h"
@@ -43,17 +39,5 @@ public:
};
-
-#ifdef _WIN32
-// A set of flags that are only relevant for windows based unit tests
-class WindowsFlags {
- public:
- static bool sIsParentProcess;
- static HANDLE sChildRead;
- static HANDLE sChildWrite;
- static char sFileLockPath[MAX_PATH];
-};
-#endif
-
} // namespace emulation
} // namespace android
diff --git a/stream-servers/CMakeLists.txt b/stream-servers/CMakeLists.txt
index 42c12908..8208c92e 100644
--- a/stream-servers/CMakeLists.txt
+++ b/stream-servers/CMakeLists.txt
@@ -213,7 +213,8 @@ target_link_libraries(
gfxstream_backend_static
stream-server-testing-support
gfxstream-base-testing-support
- gfxstream-host-common-testing-support)
+ gfxstream-host-common-testing-support
+ gtest_main)
gtest_discover_tests(OpenglRender_snapshot_unittests)
# Vulkan tests##################################################################
@@ -235,6 +236,7 @@ target_link_libraries(
gfxstream-base-testing-support
gfxstream-host-common-testing-support
gtest
+ gtest_main
gmock)
gtest_discover_tests(Vulkan_unittests)
diff --git a/stream-servers/tests/DefaultFramebufferBlit_unittest.cpp b/stream-servers/tests/DefaultFramebufferBlit_unittest.cpp
index 3003b04c..8fb34005 100644
--- a/stream-servers/tests/DefaultFramebufferBlit_unittest.cpp
+++ b/stream-servers/tests/DefaultFramebufferBlit_unittest.cpp
@@ -13,6 +13,7 @@
// limitations under the License.
#include <gtest/gtest.h>
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include "Standalone.h"
#include "GLTestUtils.h"
@@ -172,6 +173,13 @@ static constexpr float kDrawColorGreen[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
class CombinedFramebufferBlit : public ::testing::Test, public ::testing::WithParamInterface<ClearColorParam> {
protected:
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
+ }
+
+ static void TearDownTestSuite() { }
+
virtual void SetUp() override {
mApp.reset(new ClearColor(GetParam()));
}
diff --git a/stream-servers/tests/FrameBuffer_unittest.cpp b/stream-servers/tests/FrameBuffer_unittest.cpp
index f4266b6f..d211953f 100644
--- a/stream-servers/tests/FrameBuffer_unittest.cpp
+++ b/stream-servers/tests/FrameBuffer_unittest.cpp
@@ -19,6 +19,7 @@
#include "base/testing/TestSystem.h"
#include "host-common/AndroidAgentFactory.h"
#include "host-common/multi_display_agent.h"
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include "host-common/window_agent.h"
#include "host-common/MultiDisplay.h"
#include "snapshot/TextureLoader.h"
@@ -53,6 +54,13 @@ public:
protected:
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
+ }
+
+ static void TearDownTestSuite() { }
+
virtual void SetUp() override {
// setupStandaloneLibrarySearchPaths();
emugl::setGLObjectCounter(android::base::GLObjectCounter::get());
diff --git a/stream-servers/tests/GLSnapshotRendering_unittest.cpp b/stream-servers/tests/GLSnapshotRendering_unittest.cpp
index 34449841..ab39e851 100644
--- a/stream-servers/tests/GLSnapshotRendering_unittest.cpp
+++ b/stream-servers/tests/GLSnapshotRendering_unittest.cpp
@@ -17,6 +17,7 @@
#include "Standalone.h"
#include "HelloTriangle.h"
#include "host-common/AndroidAgentFactory.h"
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include <gtest/gtest.h>
@@ -60,6 +61,13 @@ protected:
template <typename T>
class SnapshotGlRenderingSampleTest : public ::testing::Test {
protected:
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
+ }
+
+ static void TearDownTestSuite() { }
+
virtual void SetUp() override {
// setupStandaloneLibrarySearchPaths();
emugl::set_emugl_window_operations(*getConsoleAgents()->emu);
diff --git a/stream-servers/tests/VirtioGpuTimelines_unittest.cpp b/stream-servers/tests/VirtioGpuTimelines_unittest.cpp
index 8b3a8d47..a5aa1489 100644
--- a/stream-servers/tests/VirtioGpuTimelines_unittest.cpp
+++ b/stream-servers/tests/VirtioGpuTimelines_unittest.cpp
@@ -140,8 +140,3 @@ TEST_F(VirtioGpuTimelinesTest, TasksAndFencesOnMultipleContexts) {
check.Call(3);
mVirtioGpuTimelines->notifyTaskCompletion(taskId3);
}
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-} \ No newline at end of file
diff --git a/stream-servers/tests/Vulkan_unittest.cpp b/stream-servers/tests/Vulkan_unittest.cpp
index 44c337d9..708fb2ec 100644
--- a/stream-servers/tests/Vulkan_unittest.cpp
+++ b/stream-servers/tests/Vulkan_unittest.cpp
@@ -25,6 +25,7 @@
#include "base/System.h"
#include "base/testing/TestSystem.h"
#include "host-common/AndroidAgentFactory.h"
+#include "host-common/testing/MockAndroidAgentFactory.h"
#include "Standalone.h"
@@ -416,6 +417,13 @@ static void teardownVulkanTest(const VulkanDispatch* vk,
class VulkanTest : public ::testing::Test {
protected:
+ static void SetUpTestSuite() {
+ android::emulation::injectConsoleAgents(
+ android::emulation::MockAndroidConsoleFactory());
+ }
+
+ static void TearDownTestSuite() { }
+
void SetUp() override {
goldfish_vk::init_vulkan_dispatch_from_system_loader(
dlOpenFuncForTesting,