tests: Use logcat for output on Android
Use the following to see output when using the APK:
adb logcat | grep VulkanLayerValidationTests
Printfs still won't show up, but this should give a
better idea of how things are running on production
devices, including when a test hangs or crashes.
diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp
index 7ebe6af..c2b5a9a 100644
--- a/tests/layer_validation_tests.cpp
+++ b/tests/layer_validation_tests.cpp
@@ -23072,6 +23072,7 @@
#endif
#if defined(ANDROID) && defined(VALIDATION_APK)
+const char *appTag = "VulkanLayerValidationTests";
static bool initialized = false;
static bool active = false;
@@ -23115,6 +23116,66 @@
return args;
}
+void addFullTestCommentIfPresent(const ::testing::TestInfo& test_info, std::string& error_message) {
+ const char* const type_param = test_info.type_param();
+ const char* const value_param = test_info.value_param();
+
+ if (type_param != NULL || value_param != NULL) {
+ error_message.append(", where ");
+ if (type_param != NULL) {
+ error_message.append("TypeParam = ").append(type_param);
+ if (value_param != NULL)
+ error_message.append(" and ");
+ }
+ if (value_param != NULL) {
+ error_message.append("GetParam() = ").append(value_param);
+ }
+ }
+}
+
+// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
+class LogcatPrinter : public ::testing::EmptyTestEventListener {
+ // Called before a test starts.
+ virtual void OnTestStart(const ::testing::TestInfo& test_info) {
+ __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
+ }
+
+ // Called after a failed assertion or a SUCCEED() invocation.
+ virtual void OnTestPartResult(const ::testing::TestPartResult& result) {
+
+ // If the test part succeeded, we don't need to do anything.
+ if (result.type() == ::testing::TestPartResult::kSuccess)
+ return;
+
+ __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s",
+ result.failed() ? "*** Failure" : "Success",
+ result.file_name(),
+ result.line_number(),
+ result.summary());
+ }
+
+ // Called after a test ends.
+ virtual void OnTestEnd(const ::testing::TestInfo& info) {
+ std::string result;
+ if (info.result()->Passed()) {
+ result.append("[ OK ]");
+ } else {
+ result.append("[ FAILED ]");
+ }
+ result.append(info.test_case_name()).append(".").append(info.name());
+ if (info.result()->Failed())
+ addFullTestCommentIfPresent(info, result);
+
+ if (::testing::GTEST_FLAG(print_time)) {
+ std::ostringstream os;
+ os << info.result()->elapsed_time();
+ result.append(" (").append(os.str()).append(" ms)");
+ }
+
+ __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
+ };
+};
+
static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
static void processCommand(struct android_app *app, int32_t cmd) {
@@ -23139,7 +23200,6 @@
void android_main(struct android_app *app) {
app_dummy();
- const char *appTag = "VulkanLayerValidationTests";
int vulkanSupport = InitVulkan();
if (vulkanSupport == 0) {
@@ -23187,6 +23247,10 @@
freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
::testing::InitGoogleTest(&argc, argv);
+
+ ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
+ listeners.Append(new LogcatPrinter);
+
VkTestFramework::InitArgs(&argc, argv);
::testing::AddGlobalTestEnvironment(new TestEnvironment);