From 51f16ec76d00dd121e4b8f0611acebc02a27a4a9 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 4 Jun 2018 11:40:20 -0700 Subject: tests: Skip ScreenRecoveryUITest on gr_init failure. It addresses the ScreenRecoveryUITest failures on gce targets which don't have any graphics backend. Probing for all backend devices in tests could work, but would duplicate codes. This CL relies on the result of gr_init(). As a side effect, it may give false negatives if gr_init() is supposed to work but silently broken. But such issues are beyond ScreenRecoveryUITest's concern, which should be captured by the tests for minui or graphics backends instead. Fixes: 79616356 Test: Run recovery_unit_test on marlin. Test: Run recovery_unit_test on gce. Change-Id: I121aacc61c8a614447509506057ecfd8d86163e4 --- tests/unit/screen_ui_test.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/unit/screen_ui_test.cpp b/tests/unit/screen_ui_test.cpp index a3dd2add9..2f4b7b09b 100644 --- a/tests/unit/screen_ui_test.cpp +++ b/tests/unit/screen_ui_test.cpp @@ -30,6 +30,7 @@ #include "common/test_constants.h" #include "device.h" +#include "minui/minui.h" #include "otautil/paths.h" #include "private/resources.h" #include "screen_ui.h" @@ -274,18 +275,34 @@ class ScreenRecoveryUITest : public ::testing::Test { const std::string kTestRtlLocaleWithSuffix = "ar-EG"; void SetUp() override { - ui_ = std::make_unique(); + has_graphics_ = gr_init() == 0; + gr_exit(); + + if (has_graphics_) { + ui_ = std::make_unique(); + } testdata_dir_ = from_testdata_base(""); Paths::Get().set_resource_dir(testdata_dir_); res_set_resource_dir(testdata_dir_); } + bool has_graphics_; std::unique_ptr ui_; std::string testdata_dir_; }; +#define RETURN_IF_NO_GRAPHICS \ + do { \ + if (!has_graphics_) { \ + GTEST_LOG_(INFO) << "Test skipped due to no available graphics device"; \ + return; \ + } \ + } while (false) + TEST_F(ScreenRecoveryUITest, Init) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ASSERT_EQ(kTestLocale, ui_->GetLocale()); ASSERT_FALSE(ui_->GetRtlLocale()); @@ -299,6 +316,8 @@ TEST_F(ScreenRecoveryUITest, dtor_NotCallingInit) { } TEST_F(ScreenRecoveryUITest, ShowText) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ASSERT_FALSE(ui_->IsTextVisible()); ui_->ShowText(true); @@ -311,16 +330,22 @@ TEST_F(ScreenRecoveryUITest, ShowText) { } TEST_F(ScreenRecoveryUITest, RtlLocale) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestRtlLocale)); ASSERT_TRUE(ui_->GetRtlLocale()); } TEST_F(ScreenRecoveryUITest, RtlLocaleWithSuffix) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestRtlLocaleWithSuffix)); ASSERT_TRUE(ui_->GetRtlLocale()); } TEST_F(ScreenRecoveryUITest, ShowMenu) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ui_->SetKeyBuffer({ KeyCode::UP, @@ -347,6 +372,8 @@ TEST_F(ScreenRecoveryUITest, ShowMenu) { } TEST_F(ScreenRecoveryUITest, ShowMenu_NotMenuOnly) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ui_->SetKeyBuffer({ KeyCode::MAGIC, @@ -358,6 +385,8 @@ TEST_F(ScreenRecoveryUITest, ShowMenu_NotMenuOnly) { } TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ui_->SetKeyBuffer({ KeyCode::TIMEOUT, @@ -366,6 +395,8 @@ TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut) { } TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut_TextWasEverVisible) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); ui_->ShowText(true); ui_->ShowText(false); @@ -382,6 +413,8 @@ TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut_TextWasEverVisible) { } TEST_F(ScreenRecoveryUITest, LoadAnimation) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); // Make a few copies of loop00000.png from testdata. std::string image_data; @@ -410,6 +443,8 @@ TEST_F(ScreenRecoveryUITest, LoadAnimation) { } TEST_F(ScreenRecoveryUITest, LoadAnimation_MissingAnimation) { + RETURN_IF_NO_GRAPHICS; + ASSERT_TRUE(ui_->Init(kTestLocale)); TemporaryDir resource_dir; Paths::Get().set_resource_dir(resource_dir.path); @@ -417,3 +452,5 @@ TEST_F(ScreenRecoveryUITest, LoadAnimation_MissingAnimation) { ::testing::FLAGS_gtest_death_test_style = "threadsafe"; ASSERT_EXIT(ui_->RunLoadAnimation(), ::testing::KilledBySignal(SIGABRT), ""); } + +#undef RETURN_IF_NO_GRAPHICS -- cgit v1.2.3