diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-12-21 12:56:34 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-01-05 15:22:48 +0100 |
commit | 20615a2c15a3b7e0a002d98146d25f29c8631ff3 (patch) | |
tree | 15631f7d72af3d2c320160d18e88f3419b593b3e /platform/android | |
parent | ed4e7a11340e3ee4e553591753bdadd78413b49b (diff) | |
download | qtlocation-mapboxgl-20615a2c15a3b7e0a002d98146d25f29c8631ff3.tar.gz |
[android] improve test runner by allowing selective execution of tests
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/src/test/Main.java | 4 | ||||
-rw-r--r-- | platform/android/src/test/main.jni.cpp | 53 | ||||
-rw-r--r-- | platform/android/tests/README.md | 9 | ||||
-rw-r--r-- | platform/android/tests/docs/CORE_TESTS.md | 21 |
4 files changed, 67 insertions, 20 deletions
diff --git a/platform/android/src/test/Main.java b/platform/android/src/test/Main.java index 2abcf2bfdb..b6f540f666 100644 --- a/platform/android/src/test/Main.java +++ b/platform/android/src/test/Main.java @@ -1,13 +1,13 @@ public class Main { - public native void runAllTests(); + public native void runAllTests(String[] args); public static void main(String[] args) throws Exception { //Load the tests System.loadLibrary("mbgl-test"); //Run the tests - new Main().runAllTests(); + new Main().runAllTests(args); //Exit explicitly otherwise dalvikvm won't quit System.exit(0); diff --git a/platform/android/src/test/main.jni.cpp b/platform/android/src/test/main.jni.cpp index d37b908202..f79d7671cb 100644 --- a/platform/android/src/test/main.jni.cpp +++ b/platform/android/src/test/main.jni.cpp @@ -2,25 +2,51 @@ #include <android/log.h> #include <jni/jni.hpp> +#include <jni/jni.hpp> #include <mbgl/util/logging.hpp> #include <mbgl/test.hpp> +#include <vector> + #pragma clang diagnostic ignored "-Wunused-parameter" #define MAKE_NATIVE_METHOD(name, sig) jni::MakeNativeMethod<decltype(name), name>( #name, sig ) namespace { -/** - * JNI Bound to Main#runAllTests() - */ -void runAllTests(JNIEnv *env, jni::jobject* obj) { - mbgl::Log::Info(mbgl::Event::JNI, "Starting tests"); - mbgl::runTests(0, nullptr); -} +// Main class (entry point for tests from dalvikvm) +struct Main { + static constexpr auto Name() { + return "Main"; + } -} + /** + * JNI Bound to Main#runAllTests() + */ + static void runAllTests(jni::JNIEnv& env, jni::Object<Main>, jni::Array<jni::String> args) { + mbgl::Log::Warning(mbgl::Event::JNI, "Starting tests"); + + // We need to create a copy of the argv data since Java-internals are stored in UTF-16. + std::vector<std::string> data; + // Add a fake first argument to align indices. Google Test expects the first argument to + // start at index 1; index 0 is the name of the executable. + data.push_back("main.jar"); + const int argc = args.Length(env); + for (auto i = 0; i < argc; i++) { + data.emplace_back(jni::Make<std::string>(env, args.Get(env, i))); + } + + // Create an array of char pointers that point back to the data array. + std::vector<const char*> argv; + for (const auto& arg : data) { + argv.push_back(arg.data()); + } + mbgl::runTests(argv.size(), const_cast<char**>(argv.data())); + } +}; + +} // namespace // JNI Bindings to stub the android.util.Log implementation @@ -47,20 +73,19 @@ static jint logger_entry_max_payload_native(JNIEnv* env, jni::jobject* clazz) { // Main entry point extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { - //Load the main library jni bindings + // Load the main library jni bindings mbgl::Log::Info(mbgl::Event::JNI, "Registering main JNI Methods"); mbgl::android::registerNatives(vm); - //Load the test library jni bindings + // Load the test library jni bindings mbgl::Log::Info(mbgl::Event::JNI, "Registering test JNI Methods"); jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6); - //Main class (entry point for tests from dalvikvm) - struct Main { static constexpr auto Name() { return "Main"; } }; - jni::RegisterNatives(env, jni::Class<Main>::Find(env), MAKE_NATIVE_METHOD(runAllTests, "()V")); + jni::RegisterNatives(env, jni::Class<Main>::Find(env), + jni::MakeNativeMethod<decltype(Main::runAllTests), &Main::runAllTests>("runAllTests")); - //Bindings for system classes + // Bindings for system classes struct Log { static constexpr auto Name() { return "android/util/Log"; } }; try { jni::RegisterNatives(env, jni::Class<Log>::Find(env), diff --git a/platform/android/tests/README.md b/platform/android/tests/README.md index 69e75b693b..8c4d29e831 100644 --- a/platform/android/tests/README.md +++ b/platform/android/tests/README.md @@ -3,7 +3,8 @@ ## Testing We currently support the following types of testing on the Mapbox Android SDK: - - [Unit tests](https://github.com/mapbox/mapbox-gl-native/blob/3447-Add-test-documentation/platform/android/tests/docs/UNIT_TESTS.md) using [JUnit](http://developer.android.com/tools/testing-support-library/index.html#AndroidJUnitRunner) - - [UI tests](https://github.com/mapbox/mapbox-gl-native/blob/3447-Add-test-documentation/platform/android/tests/docs/UI_TESTS.md) using [Espresso](http://developer.android.com/tools/testing-support-library/index.html#Espresso) - - [Exerciser](https://github.com/mapbox/mapbox-gl-native/blob/3447-Add-test-documentation/platform/android/tests/docs/EXERCISER_TESTS.md) tests using [Monkey](http://developer.android.com/tools/help/monkey.html) or [Build-in Fuzz test](http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-built-in-fuzz.html) - - [Performance tests](https://github.com/mapbox/mapbox-gl-native/blob/3447-Add-test-documentation/platform/android/tests/docs/PERFORMANCE_TESTS.md) using [Systrace](https://codelabs.developers.google.com/codelabs/android-perf-testing/index.html?index=..%2F..%2Fbabbq-2015&viewga=UA-68632703-1#0) + - [Unit tests](docs/UNIT_TESTS.md) using [JUnit](http://developer.android.com/tools/testing-support-library/index.html#AndroidJUnitRunner) + - [UI tests](docs/UI_TESTS.md) using [Espresso](http://developer.android.com/tools/testing-support-library/index.html#Espresso) + - [Exerciser](docs/EXERCISER_TESTS.md) tests using [Monkey](http://developer.android.com/tools/help/monkey.html) or [Build-in Fuzz test](http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-built-in-fuzz.html) + - [Performance tests](docs/PERFORMANCE_TESTS.md) using [Systrace](https://codelabs.developers.google.com/codelabs/android-perf-testing/index.html?index=..%2F..%2Fbabbq-2015&viewga=UA-68632703-1#0) + - [Core tests](docs/CORE_TESTS.md) using [Google Test](https://github.com/google/googletest) to run the unit tests written for the core rendering component of Mapbox GL
\ No newline at end of file diff --git a/platform/android/tests/docs/CORE_TESTS.md b/platform/android/tests/docs/CORE_TESTS.md new file mode 100644 index 0000000000..b9cd7bcc76 --- /dev/null +++ b/platform/android/tests/docs/CORE_TESTS.md @@ -0,0 +1,21 @@ +# Core Tests + +Core tests run the [unit tests](../../../../test) written for the core rendering component of Mapbox GL. + +## Running the tests + +To run the tests, connect a device to your computer, or launch a virtual device. Then run + +``` +$ make run-android-core-test-XXX +``` + +with `XXX` being the architecture of the device (one of `arm-v5`, `arm-v7`, `arm-v8`, `x86`, `x86-64`, or `mips`). This command first builds the library, creates a test program, zips up the assets required for the unit tests, deploys it on the device, runs the test and unpacks the results again on your computer. + +You can also run individual tests by specifying the name like this: + +``` +$ make run-android-core-test-XXX-TileCover.* +``` + +Everything after the last dash is passed as the [`--gtest_filter` argument](https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-a-subset-of-the-tests) to the Google Test binary. |