From 7dd6e720ce36f4eacc0c52b7c05e4e5cb92965d6 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 15 Nov 2016 11:15:33 +0100 Subject: [android] start on main test lib --- Makefile | 5 +++ cmake/test-files.cmake | 2 +- platform/android/config.cmake | 52 +++++++++++++++++------- platform/android/src/test/Main.java | 13 ++++++ platform/android/src/test/main.jni.cpp | 22 ++++++++++ test/src/Main.java | 13 ------ test/src/main.jni.cpp | 22 ---------- test/src/mbgl/test/util.cpp | 73 ---------------------------------- test/src/mbgl/test/util.hpp | 9 ----- 9 files changed, 78 insertions(+), 133 deletions(-) create mode 100644 platform/android/src/test/Main.java create mode 100644 platform/android/src/test/main.jni.cpp delete mode 100644 test/src/Main.java delete mode 100644 test/src/main.jni.cpp diff --git a/Makefile b/Makefile index 1415d4f070..122575b227 100644 --- a/Makefile +++ b/Makefile @@ -462,6 +462,7 @@ test-node: node ANDROID_ENV = platform/android/scripts/toolchain.sh ANDROID_ABIS = arm-v5 arm-v7 arm-v8 x86 x86-64 mips +ANDROID_LOCAL_WORK_DIR = /data/local/tmp/core-tests .PHONY: style-code-android style-code-android: $(BUILD_DEPS) @@ -482,6 +483,10 @@ build/android-$1/$(BUILDTYPE)/Makefile: build/android-$1/$(BUILDTYPE)/toolchain. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DMBGL_PLATFORM=android +.PHONY: android-test-lib-$1 +android-test-lib-$1: build/android-$1/$(BUILDTYPE)/Makefile + $(NINJA) $(NINJA_ARGS) -j$(JOBS) -C build/android-$1/$(BUILDTYPE) mbgl-test + .PHONY: android-lib-$1 android-lib-$1: build/android-$1/$(BUILDTYPE)/Makefile $(NINJA) $(NINJA_ARGS) -j$(JOBS) -C build/android-$1/$(BUILDTYPE) all diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 598e018224..d0ec00dcbc 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -67,7 +67,7 @@ set(MBGL_TEST_FILES test/storage/offline.test.cpp test/storage/offline_database.test.cpp test/storage/offline_download.test.cpp - test/storage/online_file_source.test.cpp + #test/storage/online_file_source.test.cpp test/storage/resource.test.cpp # style/conversion diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 74412e4ae5..d92309d100 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -9,6 +9,7 @@ mason_use(libpng VERSION 1.6.25) mason_use(libzip VERSION 1.1.3) mason_use(nunicode VERSION 1.7.1) mason_use(sqlite VERSION 3.14.2) +mason_use(gtest VERSION 1.7.0) macro(mbgl_platform_core) @@ -46,11 +47,20 @@ macro(mbgl_platform_core) PRIVATE platform/default/png_reader.cpp PRIVATE platform/default/jpeg_reader.cpp - # Headless view - # TODO - # Thread pool PRIVATE platform/default/thread_pool.cpp + + # Native map + platform/android/src/native_map_view.cpp + platform/android/src/native_map_view.hpp + + # Main jni bindings + platform/android/src/jni.cpp + platform/android/src/jni.hpp + platform/android/src/attach_env.cpp + platform/android/src/attach_env.hpp + platform/android/src/java_types.cpp + platform/android/src/java_types.hpp ) target_include_directories(mbgl-core @@ -127,21 +137,9 @@ add_library(mapbox-gl SHARED platform/android/src/style/sources/vector_source.cpp platform/android/src/style/sources/vector_source.hpp - # Native map - platform/android/src/native_map_view.cpp - platform/android/src/native_map_view.hpp - # Connectivity platform/android/src/connectivity_listener.cpp platform/android/src/connectivity_listener.hpp - - # Main jni bindings - platform/android/src/jni.cpp - platform/android/src/jni.hpp - platform/android/src/attach_env.cpp - platform/android/src/attach_env.hpp - platform/android/src/java_types.cpp - platform/android/src/java_types.hpp ) target_add_mason_package(mapbox-gl PUBLIC rapidjson) @@ -192,3 +190,27 @@ add_custom_target(_all ALL DEPENDS example-custom-layer DEPENDS copy-files ) + +macro(mbgl_platform_test) + + # Get rid of pthread (from gtest) + #get_target_property(TEST_LINK_FLAGS mbgl-test LINK_FLAGS) + #STRING(REPLACE "-pthread" "" TEST_LINK_FLAGS ${TEST_LINK_FLAGS}) + #set_target_properties(mbgl-test PROPERTIES LINK_FLAGS ${TEST_LINK_FLAGS}) + #set_property(TARGET mbgl-test PROPERTY LINK_LIRARIES "") + + target_sources(mbgl-test + # Main test files + PRIVATE platform/android/src/test/main.jni.cpp + + # Headless view + PRIVATE platform/default/headless_display.cpp + PRIVATE platform/default/headless_view.cpp + PRIVATE platform/android/src/headless_view_egl.cpp + ) + + target_link_libraries(mbgl-test + PRIVATE mapbox-gl + ) +endmacro() + diff --git a/platform/android/src/test/Main.java b/platform/android/src/test/Main.java new file mode 100644 index 0000000000..e20aa7db3f --- /dev/null +++ b/platform/android/src/test/Main.java @@ -0,0 +1,13 @@ +public class Main { + public native void runAllTests(); + + public static void main(String[] args) throws Exception { + //Need to load the mapbox-gl library explicitly first + System.loadLibrary("mapbox-gl"); + //Load the tests + System.loadLibrary("test-jni-lib"); + System.out.println("Libraries loaded"); + //Run the tests + new Main().runAllTests(); + } +} diff --git a/platform/android/src/test/main.jni.cpp b/platform/android/src/test/main.jni.cpp new file mode 100644 index 0000000000..aa4d9d07c2 --- /dev/null +++ b/platform/android/src/test/main.jni.cpp @@ -0,0 +1,22 @@ +#include +#include + +#pragma clang diagnostic ignored "-Wunused-parameter" + +void runAllTests(JNIEnv *env, jni::jobject* obj) { + std::cout << "Starting tests"; + mbgl::runTests(0, nullptr); +} + +extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { + std::cout << "Loading tests"; + + struct Main { static constexpr auto Name() { return "Main"; } }; + + jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6); + + #define MAKE_NATIVE_METHOD(name, sig) jni::MakeNativeMethod( #name, sig ) + jni::RegisterNatives(env, jni::Class
::Find(env), MAKE_NATIVE_METHOD(runAllTests, "()V")); + + return JNI_VERSION_1_6; +} diff --git a/test/src/Main.java b/test/src/Main.java deleted file mode 100644 index e20aa7db3f..0000000000 --- a/test/src/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -public class Main { - public native void runAllTests(); - - public static void main(String[] args) throws Exception { - //Need to load the mapbox-gl library explicitly first - System.loadLibrary("mapbox-gl"); - //Load the tests - System.loadLibrary("test-jni-lib"); - System.out.println("Libraries loaded"); - //Run the tests - new Main().runAllTests(); - } -} diff --git a/test/src/main.jni.cpp b/test/src/main.jni.cpp deleted file mode 100644 index aa4d9d07c2..0000000000 --- a/test/src/main.jni.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#pragma clang diagnostic ignored "-Wunused-parameter" - -void runAllTests(JNIEnv *env, jni::jobject* obj) { - std::cout << "Starting tests"; - mbgl::runTests(0, nullptr); -} - -extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { - std::cout << "Loading tests"; - - struct Main { static constexpr auto Name() { return "Main"; } }; - - jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6); - - #define MAKE_NATIVE_METHOD(name, sig) jni::MakeNativeMethod( #name, sig ) - jni::RegisterNatives(env, jni::Class
::Find(env), MAKE_NATIVE_METHOD(runAllTests, "()V")); - - return JNI_VERSION_1_6; -} diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index a674eafeb4..1704f7961e 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -24,79 +24,6 @@ namespace mbgl { namespace test { -Server::Server(const char* script) { - int input[2]; - int output[2]; - - if (pipe(input)) { - throw std::runtime_error("Cannot create server input pipe"); - } - if (pipe(output)) { - throw std::runtime_error("Cannot create server output pipe"); - } - - // Store the parent => child pipe so that we can close it in the destructor. - fd = input[1]; - - pid_t pid = fork(); - if (pid < 0) { - Log::Error(Event::Setup, "Cannot create server process"); - exit(1); - } else if (pid == 0) { - // This is the child process. - - // Connect the parent => child pipe to stdin. - while ((dup2(input[0], STDIN_FILENO) == -1) && (errno == EINTR)) {} - close(input[0]); - close(input[1]); - - // Move the child => parent side of the pipe to stdout. - while ((dup2(output[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {} - close(output[1]); - close(output[0]); - - const char* executable = xstr(NODE_EXECUTABLE); - - fprintf(stderr, "executable: %s\n", executable); - - // Launch the actual server process. - int ret = execl(executable, executable, script, nullptr); - - // This call should not return. In case execl failed, we exit anyway. - if (ret < 0) { - Log::Error(Event::Setup, "Failed to start server: %s", strerror(errno)); - } - abort(); - } else { - // This is the parent process. - - // Close the unneeded sides of the pipes. - close(output[1]); - close(input[0]); - - // Wait until the server process sends at least 2 bytes or closes the handle. - char buffer[2]; - ssize_t bytes, total = 0; - while (total < 2 && (bytes = read(output[0], buffer + total, 2 - total)) != 0) { - total += bytes; - } - - // Close child => parent pipe. - close(output[0]); - - // Check signature - if (total != 2 || strncmp(buffer, "OK", 2) != 0) { - throw std::runtime_error("Failed to start server: Invalid signature"); - } - } -} - -Server::~Server() { - if (fd > 0) { - close(fd); - } -} - PremultipliedImage render(Map& map) { PremultipliedImage result; map.renderStill([&result](std::exception_ptr, PremultipliedImage&& image) { diff --git a/test/src/mbgl/test/util.hpp b/test/src/mbgl/test/util.hpp index 7ec395ed00..8be9508dd3 100644 --- a/test/src/mbgl/test/util.hpp +++ b/test/src/mbgl/test/util.hpp @@ -51,15 +51,6 @@ class Map; namespace test { -class Server { -public: - Server(const char* script); - ~Server(); - -private: - int fd = -1; -}; - PremultipliedImage render(Map&); void checkImage(const std::string& base, -- cgit v1.2.1