Commit 31b18a0e by Nicolas Capens

Add EGL initialization unit test.

This test verifies that the swiftshader EGL libraries exists, can be loaded, has its entry functions accessible, and we get the expected vendor/version strings. Change-Id: Ifc29286cfaa83fa4c2412c073d383f2c1b58766f Reviewed-on: https://swiftshader-review.googlesource.com/9168Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 50eaee7e
...@@ -16,8 +16,8 @@ import("//testing/test.gni") ...@@ -16,8 +16,8 @@ import("//testing/test.gni")
test("swiftshader_unittests") { test("swiftshader_unittests") {
deps = [ deps = [
"../../src/OpenGL/libEGL:swiftshader_libEGL", "//third_party/swiftshader/src/OpenGL/libEGL:swiftshader_libEGL",
"../../src/OpenGL/libGLESv2:swiftshader_libGLESv2", "//third_party/swiftshader/src/OpenGL/libGLESv2:swiftshader_libGLESv2",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//testing/gmock", "//testing/gmock",
...@@ -28,4 +28,26 @@ test("swiftshader_unittests") { ...@@ -28,4 +28,26 @@ test("swiftshader_unittests") {
"//gpu/swiftshader_tests_main.cc", "//gpu/swiftshader_tests_main.cc",
"unittests.cpp", "unittests.cpp",
] ]
include_dirs = [
"../../include", # Khronos headers
]
# Make sure we're loading SwiftShader's libraries, not ANGLE's or the system
# provided ones. On Windows an explicit LoadLibrary("swiftshader\lib*.dll")
# is required before making the first EGL or OpenGL ES call.
if (is_win) {
ldflags = [
"/DELAYLOAD:libEGL.dll",
"/DELAYLOAD:libGLESv2.dll",
]
} else if (is_mac) {
ldflags = [
"-Wl,-install_name,@rpath/\$ORIGIN/swiftshader",
]
} else {
ldflags = [
"-Wl,-rpath=\$ORIGIN/swiftshader",
]
}
} }
// These are not the headers you're looking for
#error "Missing googletest submodule. Run git submodule update --init"
\ No newline at end of file
...@@ -13,7 +13,61 @@ ...@@ -13,7 +13,61 @@
// limitations under the License. // limitations under the License.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gmock/gmock.h"
TEST(SwiftShaderCompilationOnly, Unit) { #include <EGL/egl.h>
#include <GLES2/gl2.h>
#if defined(_WIN32)
#include <Windows.h>
#endif
class SwiftShaderTest : public testing::Test
{
protected:
void SetUp() override
{
#if defined(_WIN32)
// The DLLs are delay loaded (see BUILD.gn), so we can load
// the correct ones from the swiftshader subdirectory.
HMODULE libEGL = LoadLibraryA("swiftshader\\libEGL.dll");
EXPECT_NE(NULL, libEGL);
HMODULE libGLESv2 = LoadLibraryA("swiftshader\\libGLESv2.dll");
EXPECT_NE(NULL, libGLESv2);
#endif
}
};
TEST_F(SwiftShaderTest, CompilationOnly)
{
// Empty test to trigger compilation of SwiftShader on build bots // Empty test to trigger compilation of SwiftShader on build bots
} }
TEST_F(SwiftShaderTest, Initalization)
{
EXPECT_EQ(EGL_SUCCESS, eglGetError());
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EXPECT_EQ(EGL_SUCCESS, eglGetError());
EXPECT_NE(EGL_NO_DISPLAY, display);
eglQueryString(display, EGL_VENDOR);
EXPECT_EQ(EGL_NOT_INITIALIZED, eglGetError());
EGLint major;
EGLint minor;
EGLBoolean initialized = eglInitialize(display, &major, &minor);
EXPECT_EQ(EGL_SUCCESS, eglGetError());
EXPECT_EQ((EGLBoolean)EGL_TRUE, initialized);
EXPECT_EQ(1, major);
EXPECT_EQ(4, minor);
const char *vendor = eglQueryString(display, EGL_VENDOR);
EXPECT_EQ(EGL_SUCCESS, eglGetError());
EXPECT_STREQ("Google Inc.", vendor);
const char *version = eglQueryString(display, EGL_VERSION);
EXPECT_EQ(EGL_SUCCESS, eglGetError());
EXPECT_THAT(version, testing::HasSubstr("1.4 SwiftShader "));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment