Show progress on device when Android render test is running (#4119)
This commit is contained in:
@@ -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