diff options
| author | 2019-09-04 18:54:34 +0000 | |
|---|---|---|
| committer | 2019-09-04 18:54:34 +0000 | |
| commit | 548308f8289d979d7dbd6a89387fb94932295a08 (patch) | |
| tree | d6e1fb07d507ed863fdee1c90e8770646778e1fb | |
| parent | 275fb46d01ceeced378b409776eb49044ae15523 (diff) | |
| parent | 9fa2cb6c5af15e5386c4632aed4847057c08340b (diff) | |
Merge "[ANativeWindow] Add test infrastructure for apex apis"
| -rw-r--r-- | libs/gui/TEST_MAPPING | 7 | ||||
| -rw-r--r-- | libs/nativewindow/ANativeWindow.cpp | 8 | ||||
| -rw-r--r-- | libs/nativewindow/TEST_MAPPING | 7 | ||||
| -rw-r--r-- | libs/nativewindow/include/apex/window.h | 34 | ||||
| -rw-r--r-- | libs/nativewindow/include/system/window.h | 3 | ||||
| -rw-r--r-- | libs/nativewindow/libnativewindow.map.txt | 1 | ||||
| -rw-r--r-- | libs/nativewindow/tests/ANativeWindowTest.cpp | 72 | ||||
| -rw-r--r-- | libs/nativewindow/tests/Android.bp | 13 | ||||
| -rw-r--r-- | libs/nativewindow/tests/c_compatibility.c | 1 |
9 files changed, 143 insertions, 3 deletions
diff --git a/libs/gui/TEST_MAPPING b/libs/gui/TEST_MAPPING new file mode 100644 index 0000000000..1c435304a8 --- /dev/null +++ b/libs/gui/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "imports": [ + { + "path": "frameworks/native/libs/nativewindow" + } + ] +} diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp index 1751443419..4c59e6ce98 100644 --- a/libs/nativewindow/ANativeWindow.cpp +++ b/libs/nativewindow/ANativeWindow.cpp @@ -266,3 +266,11 @@ int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) { int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) { return native_window_set_auto_prerotation(window, autoPrerotation); } + +/************************************************************************************************** + * apex-stable + **************************************************************************************************/ + +int ANativeWindow_getLastDequeueDuration(ANativeWindow* window) { + return query(window, NATIVE_WINDOW_LAST_DEQUEUE_DURATION); +} diff --git a/libs/nativewindow/TEST_MAPPING b/libs/nativewindow/TEST_MAPPING new file mode 100644 index 0000000000..3d7f3c28f4 --- /dev/null +++ b/libs/nativewindow/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "libnativewindow_test" + } + ] +} diff --git a/libs/nativewindow/include/apex/window.h b/libs/nativewindow/include/apex/window.h new file mode 100644 index 0000000000..0260cbcfb4 --- /dev/null +++ b/libs/nativewindow/include/apex/window.h @@ -0,0 +1,34 @@ +/* + * Copyright 2019 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. + */ + +#pragma once + +#include <nativebase/nativebase.h> + +// apex is a superset of the NDK +#include <android/native_window.h> + +__BEGIN_DECLS + +/** + * Retrieves how long it took for the last time a buffer was dequeued. + * + * \return a negative value on error, otherwise returns the duration in + * microseconds. + */ +int ANativeWindow_getLastDequeueDuration(ANativeWindow* window); + +__END_DECLS diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index 8cbf0a4244..78354bba6b 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -41,7 +41,8 @@ #include <unistd.h> #include <stdbool.h> -// system/window.h is a superset of the vndk +// system/window.h is a superset of the vndk and apex apis +#include <apex/window.h> #include <vndk/window.h> diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt index 119a07dad7..7fe4df0606 100644 --- a/libs/nativewindow/libnativewindow.map.txt +++ b/libs/nativewindow/libnativewindow.map.txt @@ -22,6 +22,7 @@ LIBNATIVEWINDOW { ANativeWindow_getBuffersDataSpace; # introduced=28 ANativeWindow_getFormat; ANativeWindow_getHeight; + ANativeWindow_getLastDequeueDuration; # apex # introduced=30 ANativeWindow_getWidth; ANativeWindow_lock; ANativeWindow_query; # vndk diff --git a/libs/nativewindow/tests/ANativeWindowTest.cpp b/libs/nativewindow/tests/ANativeWindowTest.cpp new file mode 100644 index 0000000000..a80da24a47 --- /dev/null +++ b/libs/nativewindow/tests/ANativeWindowTest.cpp @@ -0,0 +1,72 @@ +/* + * Copyright 2019 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 "ANativeWindow_test" +//#define LOG_NDEBUG 0 + +#include <gtest/gtest.h> +#include <gui/BufferItemConsumer.h> +#include <gui/BufferQueue.h> +#include <gui/Surface.h> +#include <log/log.h> +#include <sync/sync.h> +// We need to use the private system apis since not everything is visible to +// apexes yet. +#include <system/window.h> + +using namespace android; + +class ANativeWindowTest : public ::testing::Test { +protected: + void SetUp() override { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + ALOGV("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); + BufferQueue::createBufferQueue(&mProducer, &mConsumer); + mItemConsumer = new BufferItemConsumer(mConsumer, GRALLOC_USAGE_SW_READ_OFTEN); + mWindow = new Surface(mProducer); + const int success = native_window_api_connect(mWindow.get(), NATIVE_WINDOW_API_CPU); + EXPECT_EQ(0, success); + } + + void TearDown() override { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + ALOGV("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); + const int success = native_window_api_disconnect(mWindow.get(), NATIVE_WINDOW_API_CPU); + EXPECT_EQ(0, success); + } + sp<IGraphicBufferProducer> mProducer; + sp<IGraphicBufferConsumer> mConsumer; + sp<BufferItemConsumer> mItemConsumer; + sp<ANativeWindow> mWindow; +}; + +TEST_F(ANativeWindowTest, getLastDequeueDuration_noDequeue_returnsZero) { + int result = ANativeWindow_getLastDequeueDuration(mWindow.get()); + EXPECT_EQ(0, result); +} + +TEST_F(ANativeWindowTest, getLastDequeueDuration_withDequeue_returnsTime) { + ANativeWindowBuffer* buffer; + int fd; + int result = ANativeWindow_dequeueBuffer(mWindow.get(), &buffer, &fd); + close(fd); + EXPECT_EQ(0, result); + + result = ANativeWindow_getLastDequeueDuration(mWindow.get()); + EXPECT_GT(result, 0); +} diff --git a/libs/nativewindow/tests/Android.bp b/libs/nativewindow/tests/Android.bp index 20071be668..cdb3d2054f 100644 --- a/libs/nativewindow/tests/Android.bp +++ b/libs/nativewindow/tests/Android.bp @@ -15,13 +15,22 @@ // cc_test { - name: "AHardwareBufferTest", + name: "libnativewindow_test", + test_suites: [ + "device-tests", + ], shared_libs: [ + "libgui", + "liblog", "libnativewindow", + "libsync", + "libutils", "android.hardware.graphics.common@1.0", ], srcs: [ "AHardwareBufferTest.cpp", - "c_compatibility.c"], + "ANativeWindowTest.cpp", + "c_compatibility.c", + ], cflags: ["-Wall", "-Werror"], } diff --git a/libs/nativewindow/tests/c_compatibility.c b/libs/nativewindow/tests/c_compatibility.c index befd88fd07..aa9b4f7e78 100644 --- a/libs/nativewindow/tests/c_compatibility.c +++ b/libs/nativewindow/tests/c_compatibility.c @@ -16,6 +16,7 @@ #include <android/hardware_buffer.h> #include <android/native_window.h> +#include <apex/window.h> #include <vndk/hardware_buffer.h> #include <vndk/window.h> |