summaryrefslogtreecommitdiffstats
path: root/opengl/tests
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2011-11-07 17:03:54 -0800
committerJamie Gennis <jgennis@google.com>2011-11-08 15:54:36 -0800
commit98c6383580f94bb7ff9cc9a7cc24d8b8519e484a (patch)
tree0e5584031c1275db67e8c423d398b29f445c5c98 /opengl/tests
parent766010858ea7696d64f1b559413670bdd8627595 (diff)
downloadframeworks_native-98c6383580f94bb7ff9cc9a7cc24d8b8519e484a.zip
frameworks_native-98c6383580f94bb7ff9cc9a7cc24d8b8519e484a.tar.gz
frameworks_native-98c6383580f94bb7ff9cc9a7cc24d8b8519e484a.tar.bz2
EGL: implement loading and saving the cache
This change adds support for saving and loading the contents of the EGL cache. It also adds some simple tests for the EGL cache. Change-Id: I18e5e789e0897a0783d29d1c1e64d26de2dd44c4
Diffstat (limited to 'opengl/tests')
-rw-r--r--opengl/tests/EGLTest/Android.mk4
-rw-r--r--opengl/tests/EGLTest/egl_cache_test.cpp110
2 files changed, 114 insertions, 0 deletions
diff --git a/opengl/tests/EGLTest/Android.mk b/opengl/tests/EGLTest/Android.mk
index 92d7eb1..14104d1 100644
--- a/opengl/tests/EGLTest/Android.mk
+++ b/opengl/tests/EGLTest/Android.mk
@@ -7,6 +7,7 @@ LOCAL_MODULE := EGL_test
LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := \
+ egl_cache_test.cpp \
EGL_test.cpp \
LOCAL_SHARED_LIBRARIES := \
@@ -21,9 +22,12 @@ LOCAL_STATIC_LIBRARIES := \
LOCAL_C_INCLUDES := \
bionic \
+ bionic/libc/private \
bionic/libstdc++/include \
external/gtest/include \
external/stlport/stlport \
+ frameworks/base/opengl/libs \
+ frameworks/base/opengl/libs/EGL \
include $(BUILD_EXECUTABLE)
diff --git a/opengl/tests/EGLTest/egl_cache_test.cpp b/opengl/tests/EGLTest/egl_cache_test.cpp
new file mode 100644
index 0000000..c7d9e3e
--- /dev/null
+++ b/opengl/tests/EGLTest/egl_cache_test.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "EGL_test"
+//#define LOG_NDEBUG 0
+
+#include <gtest/gtest.h>
+
+#include <utils/Log.h>
+
+#include "egl_cache.h"
+#include "egl_display.h"
+
+namespace android {
+
+class EGLCacheTest : public ::testing::Test {
+protected:
+ virtual void SetUp() {
+ mCache = egl_cache_t::get();
+ }
+
+ virtual void TearDown() {
+ mCache->setCacheFilename("");
+ mCache->terminate();
+ }
+
+ egl_cache_t* mCache;
+};
+
+TEST_F(EGLCacheTest, UninitializedCacheAlwaysMisses) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ(0xee, buf[0]);
+ ASSERT_EQ(0xee, buf[1]);
+ ASSERT_EQ(0xee, buf[2]);
+ ASSERT_EQ(0xee, buf[3]);
+}
+
+TEST_F(EGLCacheTest, InitializedCacheAlwaysHits) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ('e', buf[0]);
+ ASSERT_EQ('f', buf[1]);
+ ASSERT_EQ('g', buf[2]);
+ ASSERT_EQ('h', buf[3]);
+}
+
+TEST_F(EGLCacheTest, TerminatedCacheAlwaysMisses) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ mCache->terminate();
+ ASSERT_EQ(0, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ(0xee, buf[0]);
+ ASSERT_EQ(0xee, buf[1]);
+ ASSERT_EQ(0xee, buf[2]);
+ ASSERT_EQ(0xee, buf[3]);
+}
+
+class EGLCacheSerializationTest : public EGLCacheTest {
+
+protected:
+
+ virtual void SetUp() {
+ EGLCacheTest::SetUp();
+
+ char* tn = tempnam("/sdcard", "EGL_test-cache-");
+ mFilename = tn;
+ free(tn);
+ }
+
+ virtual void TearDown() {
+ unlink(mFilename.string());
+ EGLCacheTest::TearDown();
+ }
+
+ String8 mFilename;
+};
+
+TEST_F(EGLCacheSerializationTest, ReinitializedCacheContainsValues) {
+ char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ mCache->setCacheFilename(mFilename);
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ mCache->setBlob("abcd", 4, "efgh", 4);
+ mCache->terminate();
+ mCache->initialize(egl_display_t::get(EGL_DEFAULT_DISPLAY));
+ ASSERT_EQ(4, mCache->getBlob("abcd", 4, buf, 4));
+ ASSERT_EQ('e', buf[0]);
+ ASSERT_EQ('f', buf[1]);
+ ASSERT_EQ('g', buf[2]);
+ ASSERT_EQ('h', buf[3]);
+}
+
+}