Show progress on device when Android render test is running (#4119)
This commit is contained in:
@@ -1,11 +1,24 @@
|
||||
#include <mbgl/render_test.hpp>
|
||||
#include "test_runner_common.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::android;
|
||||
|
||||
void updateProgress(JNIEnv* env, struct android_app* app, int completed, int total) {
|
||||
jobject nativeActivity = app->activity->clazz;
|
||||
jclass acl = env->GetObjectClass(nativeActivity);
|
||||
jmethodID updateMethod = env->GetMethodID(acl, "updateProgress", "(II)V");
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(acl);
|
||||
return;
|
||||
}
|
||||
if (updateMethod != nullptr) {
|
||||
env->CallVoidMethod(nativeActivity, updateMethod, completed, total);
|
||||
}
|
||||
env->DeleteLocalRef(acl);
|
||||
}
|
||||
|
||||
void android_main(struct android_app* app) {
|
||||
mbgl::android::theJVM = app->activity->vm;
|
||||
JNIEnv* env = nullptr;
|
||||
@@ -24,7 +37,7 @@ void android_main(struct android_app* app) {
|
||||
unZipFile(env, zipFile, storagePath);
|
||||
|
||||
auto runTestWithManifest =
|
||||
[&storagePath, &app, &outFd, &outEvents, &source](const std::string& manifest) -> bool {
|
||||
[&storagePath, &app, &env, &outFd, &outEvents, &source](const std::string& manifest) -> bool {
|
||||
const std::string configFile = storagePath + manifest;
|
||||
std::vector<std::string> arguments = {"mbgl-render-test-runner", "-p", configFile, "-u", "rebaseline"};
|
||||
std::vector<char*> argv;
|
||||
@@ -33,8 +46,7 @@ void android_main(struct android_app* app) {
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
int finishedTestCount = 0;
|
||||
std::function<void()> testStatus = [&]() {
|
||||
std::function<void(mbgl::TestStatus)> testStatus = [&](mbgl::TestStatus status) {
|
||||
auto result = ALooper_pollOnce(0, &outFd, &outEvents, reinterpret_cast<void**>(&source));
|
||||
if (result == ALOOPER_POLL_ERROR) {
|
||||
throw std::runtime_error("ALooper_pollOnce returned an error");
|
||||
@@ -45,7 +57,9 @@ void android_main(struct android_app* app) {
|
||||
}
|
||||
|
||||
mbgl::Log::Info(mbgl::Event::General,
|
||||
"Current finished tests number is '" + std::to_string(++finishedTestCount) + "'");
|
||||
"Current finished tests number is '" + std::to_string(status.completed) + "/" +
|
||||
std::to_string(status.total) + "'");
|
||||
updateProgress(env, app, static_cast<int>(status.completed), static_cast<int>(status.total));
|
||||
};
|
||||
mbgl::Log::Info(mbgl::Event::General, "Start running RenderTestRunner with manifest: '" + manifest + "'");
|
||||
bool result = mbgl::runRenderTests(argv.size() - 1, argv.data(), testStatus) == 0;
|
||||
|
||||
@@ -12,7 +12,7 @@ int main(int argc, char* argv[]) {
|
||||
#ifdef IS_IOS
|
||||
try {
|
||||
#endif
|
||||
return mbgl::runRenderTests(argc, argv, []() {});
|
||||
return mbgl::runRenderTests(argc, argv, [](mbgl::TestStatus) {});
|
||||
#ifdef IS_IOS
|
||||
} catch (std::exception const& e) {
|
||||
std::cerr << "Caught an exception while running tests\n" << e.what() << '\n';
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.junit.runner.RunWith;
|
||||
public class NativeActivityTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<NativeActivity> mActivityTestRule = new ActivityTestRule<>(NativeActivity.class, false, false);
|
||||
public ActivityTestRule<RenderTestActivity> mActivityTestRule = new ActivityTestRule<>(RenderTestActivity.class, false, false);
|
||||
|
||||
@Test(timeout = 600000L)
|
||||
public void runRenderTests() throws Exception {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
android:debuggable="true"
|
||||
tools:ignore="HardcodedDebugMode">
|
||||
|
||||
<activity android:name="android.app.NativeActivity"
|
||||
<activity android:name="android.app.RenderTestActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package android.app;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class RenderTestActivity extends NativeActivity {
|
||||
|
||||
private TextView progressTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
progressTextView = new TextView(this);
|
||||
progressTextView.setText("Starting tests...");
|
||||
progressTextView.setTextSize(18f);
|
||||
progressTextView.setTextColor(0xFFFFFFFF);
|
||||
progressTextView.setShadowLayer(2f, 1f, 1f, 0xFF000000);
|
||||
progressTextView.setPadding(24, 24, 24, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT
|
||||
);
|
||||
params.gravity = Gravity.TOP | Gravity.START;
|
||||
params.token = getWindow().getDecorView().getWindowToken();
|
||||
|
||||
getWindowManager().addView(progressTextView, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
if (progressTextView != null) {
|
||||
getWindowManager().removeView(progressTextView);
|
||||
}
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from C++ via JNI to update the progress display.
|
||||
*/
|
||||
public void updateProgress(final int completed, final int total) {
|
||||
runOnUiThread(() -> {
|
||||
if (progressTextView != null) {
|
||||
progressTextView.setText(completed + " / " + total + " tests complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
int runRenderTests(int argc, char* argv[], std::function<void()>);
|
||||
struct TestStatus {
|
||||
size_t completed;
|
||||
size_t total;
|
||||
};
|
||||
|
||||
int runRenderTests(int argc, char* argv[], std::function<void(TestStatus)>);
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -18,10 +18,10 @@ bool TestRunner::startTest(const std::string& manifestBasePath) {
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
int finishedTestCount = 0;
|
||||
std::function<void()> testStatus = [&]() {
|
||||
std::function<void(mbgl::TestStatus)> testStatus = [&](mbgl::TestStatus status) {
|
||||
mbgl::Log::Info(mbgl::Event::General,
|
||||
"Current finished tests number is '" + std::to_string(++finishedTestCount) + "' ");
|
||||
"Current finished tests number is '" + std::to_string(status.completed) + "/" +
|
||||
std::to_string(status.total) + "' ");
|
||||
};
|
||||
mbgl::Log::Info(mbgl::Event::General, "Start running RenderTestRunner with manifest: '" + manifest + "' ");
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ void runWithAlternateSources(TestRunner& runner, TestMetadata& metadata, bool& e
|
||||
} // namespace
|
||||
namespace mbgl {
|
||||
|
||||
int runRenderTests(int argc, char** argv, std::function<void()> testStatus) {
|
||||
int runRenderTests(int argc, char** argv, std::function<void(TestStatus)> testStatus) {
|
||||
int returnCode = 0;
|
||||
bool recycleMap;
|
||||
bool shuffle;
|
||||
@@ -226,6 +226,8 @@ int runRenderTests(int argc, char** argv, std::function<void()> testStatus) {
|
||||
metadatas.reserve(testPaths.size());
|
||||
|
||||
TestStatistics stats;
|
||||
const uint32_t totalTests = static_cast<uint32_t>(testPaths.size());
|
||||
uint32_t completedTests = 0;
|
||||
|
||||
for (auto& testPath : testPaths) {
|
||||
TestMetadata metadata = parseTestMetadata(testPath);
|
||||
@@ -324,7 +326,7 @@ int runRenderTests(int argc, char** argv, std::function<void()> testStatus) {
|
||||
|
||||
metadatas.push_back(std::move(metadata));
|
||||
if (testStatus) {
|
||||
testStatus();
|
||||
testStatus({.completed = ++completedTests, .total = totalTests});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user