From 1b58e87f154bf7d3d5f38ef32cc4b171362f73a2 Mon Sep 17 00:00:00 2001 From: zmiao Date: Tue, 19 Nov 2019 20:45:30 +0200 Subject: [render-test] Wrap test data inside RenderTestRunner App + Add a new test app (#15887) * [render-test] Wrap test resources inside app * [render-test] Add test app * fix test app failure * [render-test]add callback + add javaObjectWrapper --- render-test/android-manifest.json | 7 ++-- render-test/android/README.md | 8 +---- render-test/android/app/build.gradle | 4 +++ .../java/android/app/NativeActivityTest.java | 29 +++++++++++++++ .../androidTest/java/android/app/TestState.java | 5 +++ .../android/app/src/main/AndroidManifest.xml | 2 +- render-test/android/app/src/main/assets/to_zip.txt | 15 ++++++++ render-test/android/render_test_setup.sh | 42 ---------------------- render-test/include/mbgl/render_test.hpp | 5 ++- render-test/manifest_parser.cpp | 25 ++++++++++++- render-test/manifest_parser.hpp | 3 ++ render-test/render_test.cpp | 8 +++-- render-test/runner.cpp | 2 +- 13 files changed, 96 insertions(+), 59 deletions(-) create mode 100644 render-test/android/app/src/androidTest/java/android/app/NativeActivityTest.java create mode 100644 render-test/android/app/src/androidTest/java/android/app/TestState.java create mode 100644 render-test/android/app/src/main/assets/to_zip.txt delete mode 100755 render-test/android/render_test_setup.sh (limited to 'render-test') diff --git a/render-test/android-manifest.json b/render-test/android-manifest.json index 56223d4753..7aa9eb26bc 100644 --- a/render-test/android-manifest.json +++ b/render-test/android-manifest.json @@ -1,7 +1,8 @@ { "base_test_path":"mapbox-gl-js/test/integration", - "expectation_paths":["render-test/expected/render-tests"], - "ignore_paths":["platform/node/test/ignores.json", "render-test/linux-ignores.json", "render-test/tests/should-fail.json"], + "expectation_paths":[], + "ignore_paths":["ignores/ignores.json", "ignores/linux-ignores.json"], "vendor_path":"vendor", - "asset_path": "mapbox-gl-js/test/integration" + "asset_path": "mapbox-gl-js/test/integration", + "result_path": "/sdcard/" } \ No newline at end of file diff --git a/render-test/android/README.md b/render-test/android/README.md index 270c970fce..4037419012 100644 --- a/render-test/android/README.md +++ b/render-test/android/README.md @@ -1,9 +1,3 @@ # RenderTestRunner -This app is a purely native application, with no Java source code, that can run **mbgl-render-test-runner** on android devices. - - -## Setup the test environment -- Run render_test_setup.sh so that all the necessary test resources are pushed to the device. - -- Switch on storage permission of the app so that it can read/write data on SD card. \ No newline at end of file +This app is a purely native application, with no Java source code, that can run **mbgl-render-test-runner** on android devices. \ No newline at end of file diff --git a/render-test/android/app/build.gradle b/render-test/android/app/build.gradle index 60609e3ba2..682af85dcf 100644 --- a/render-test/android/app/build.gradle +++ b/render-test/android/app/build.gradle @@ -14,6 +14,7 @@ android { targets 'mbgl-render-test-runner' } } + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } externalNativeBuild { cmake { @@ -26,4 +27,7 @@ android { dependencies { implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + androidTestImplementation 'androidx.test.ext:junit:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01' + androidTestImplementation 'androidx.test:rules:1.2.0-beta01' } diff --git a/render-test/android/app/src/androidTest/java/android/app/NativeActivityTest.java b/render-test/android/app/src/androidTest/java/android/app/NativeActivityTest.java new file mode 100644 index 0000000000..3d8c333902 --- /dev/null +++ b/render-test/android/app/src/androidTest/java/android/app/NativeActivityTest.java @@ -0,0 +1,29 @@ +package android.app; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.rule.ActivityTestRule; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import android.util.Log; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class NativeActivityTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(NativeActivity.class, false, false); + + @Test(timeout = 1200000L) + public void runRenderTests() throws Exception { + Log.v("Test", "Start the test"); + mActivityTestRule.launchActivity(null); + while (TestState.running) { + Log.v("Test", "Test is running"); + Thread.sleep(1000L); + } + Log.v("Test", "End the test"); + } +} \ No newline at end of file diff --git a/render-test/android/app/src/androidTest/java/android/app/TestState.java b/render-test/android/app/src/androidTest/java/android/app/TestState.java new file mode 100644 index 0000000000..44a0653fb6 --- /dev/null +++ b/render-test/android/app/src/androidTest/java/android/app/TestState.java @@ -0,0 +1,5 @@ +package android.app; + +public class TestState { + static boolean running = true; +} \ No newline at end of file diff --git a/render-test/android/app/src/main/AndroidManifest.xml b/render-test/android/app/src/main/AndroidManifest.xml index 6c7af7ed8f..8df48ef97f 100644 --- a/render-test/android/app/src/main/AndroidManifest.xml +++ b/render-test/android/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:fullBackupContent="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:hasCode="false"> + android:hasCode="true"> + namespace mbgl { -int runRenderTests(int argc, char* argv[]); +int runRenderTests(int argc, char* argv[], std::function); } // namespace mbgl diff --git a/render-test/manifest_parser.cpp b/render-test/manifest_parser.cpp index 3f1f9f3866..6bba33754a 100644 --- a/render-test/manifest_parser.cpp +++ b/render-test/manifest_parser.cpp @@ -34,9 +34,15 @@ const std::vector>& Manifest::getIgnores() c const std::string& Manifest::getTestRootPath() const { return testRootPath; } +const std::string& Manifest::getAssetPath() const { + return assetPath; +} const std::string& Manifest::getManifestPath() const { return manifestPath; } +const std::string& Manifest::getResultPath() const { + return resultPath; +} void Manifest::doShuffle(uint32_t seed) { std::seed_seq sequence{seed}; @@ -239,7 +245,7 @@ mbgl::filesystem::path getValidPath(const std::string& manifestPath, const std:: result = BasePath / result; } if (mbgl::filesystem::exists(result)) { - return result; + return result.lexically_normal(); } mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provoided inside the manifest file: %s", path.c_str()); return mbgl::filesystem::path{}; @@ -285,6 +291,18 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife return mbgl::nullopt; } } + if (document.HasMember("result_path")) { + const auto& resultPathValue = document["result_path"]; + if (!resultPathValue.IsString()) { + mbgl::Log::Warning( + mbgl::Event::General, "Invalid assetPath is provoided inside the manifest file: %s", filePath.c_str()); + return mbgl::nullopt; + } + manifest.resultPath = (getValidPath(manifest.manifestPath, resultPathValue.GetString()) / "").string(); + if (manifest.resultPath.empty()) { + return mbgl::nullopt; + } + } mbgl::filesystem::path baseTestPath; if (document.HasMember("base_test_path")) { const auto& testPathValue = document["base_test_path"]; @@ -366,6 +384,11 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife if (manifest.manifestPath.back() == '/') { manifest.manifestPath.pop_back(); } + if (manifest.resultPath.empty()) { + manifest.resultPath = manifest.manifestPath; + } else if (manifest.resultPath.back() == '/') { + manifest.resultPath.pop_back(); + } std::vector paths; for (const auto& id : testNames) { diff --git a/render-test/manifest_parser.hpp b/render-test/manifest_parser.hpp index bc5adf1091..c4672fb4c5 100644 --- a/render-test/manifest_parser.hpp +++ b/render-test/manifest_parser.hpp @@ -17,7 +17,9 @@ public: const std::vector>& getIgnores() const; const std::vector& getTestPaths() const; const std::string& getTestRootPath() const; + const std::string& getAssetPath() const; const std::string& getManifestPath() const; + const std::string& getResultPath() const; void doShuffle(uint32_t seed); std::string localizeURL(const std::string& url) const; @@ -43,6 +45,7 @@ private: std::string testRootPath; std::string vendorPath; std::string assetPath; + std::string resultPath; std::vector> ignores; std::vector testPaths; }; diff --git a/render-test/render_test.cpp b/render-test/render_test.cpp index 38d6c15f3f..5753065a7e 100644 --- a/render-test/render_test.cpp +++ b/render-test/render_test.cpp @@ -100,7 +100,7 @@ ArgumentsTuple parseArguments(int argc, char** argv) { } // namespace namespace mbgl { -int runRenderTests(int argc, char** argv) { +int runRenderTests(int argc, char** argv, std::function testStatus) { bool recycleMap; bool shuffle; uint32_t seed; @@ -198,10 +198,12 @@ int runRenderTests(int argc, char** argv) { } metadatas.push_back(std::move(metadata)); + if (testStatus) { + testStatus(); + } } - const auto& testRootPath = manifest.getManifestPath(); const auto resultPath = - testRootPath + "/" + (testNames.empty() ? "render-tests" : testNames.front()) + "_index.html"; + manifest.getResultPath() + "/" + (testNames.empty() ? "render-tests" : testNames.front()) + "_index.html"; std::string resultsHTML = createResultPage(stats, metadatas, shuffle, seed); mbgl::util::write_file(resultPath, resultsHTML); diff --git a/render-test/runner.cpp b/render-test/runner.cpp index 0389b83575..ce76bda157 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -596,7 +596,7 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata, R std::string imagePath = operationArray[2].GetString(); imagePath.erase(std::remove(imagePath.begin(), imagePath.end(), '"'), imagePath.end()); - const mbgl::filesystem::path filePath = mbgl::filesystem::path(manifest.getTestRootPath()) / imagePath; + const mbgl::filesystem::path filePath = (mbgl::filesystem::path(manifest.getAssetPath()) / imagePath); mbgl::optional maybeImage = mbgl::util::readFile(filePath.string()); if (!maybeImage) { -- cgit v1.2.1