From 0d48dc81d08c2f6947537490c258c84d72cd3621 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Thu, 7 Mar 2019 13:04:33 -0800 Subject: [PATCH 1/2] health: skip VTS on healthd if vendor HAL is present. If vendor HAL is present, healthd is not used by the framework. VTS should skip testing it when this is the case. Provide a --force option to the test if one wants to test healthd. Fixes: 118852225 Test: on walleye, test healthd with and without --force. Change-Id: I85f792f25406b1c02887a0ac273730e719003e2f Merged-In: I85f792f25406b1c02887a0ac273730e719003e2f (cherry picked from commit e6807ddec17da45161b5f20396776a0ba38b3680) --- health/2.0/vts/functional/Android.bp | 1 + .../vts/functional/VtsHalHealthV2_0TargetTest.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/health/2.0/vts/functional/Android.bp b/health/2.0/vts/functional/Android.bp index 4ad01b98db..c4f2dc9e3a 100644 --- a/health/2.0/vts/functional/Android.bp +++ b/health/2.0/vts/functional/Android.bp @@ -19,6 +19,7 @@ cc_test { defaults: ["VtsHalTargetTestDefaults"], srcs: ["VtsHalHealthV2_0TargetTest.cpp"], static_libs: [ + "libgflags", "android.hardware.health@1.0", "android.hardware.health@2.0", ], diff --git a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp index c5431e45c2..55b48b86ff 100644 --- a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp +++ b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using ::testing::AssertionFailure; using ::testing::AssertionResult; @@ -29,6 +30,8 @@ using ::testing::AssertionSuccess; using ::testing::VtsHalHidlTargetTestBase; using ::testing::VtsHalHidlTargetTestEnvBase; +DEFINE_bool(force, false, "Force test healthd even when the default instance is present."); + namespace android { namespace hardware { namespace health { @@ -57,6 +60,14 @@ class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: virtual void SetUp() override { std::string serviceName = HealthHidlEnvironment::Instance()->getServiceName(); + + if (serviceName == "backup" && !FLAGS_force && + ::testing::VtsHalHidlTargetTestBase::getService() != nullptr) { + LOG(INFO) << "Skipping tests on healthd because the default instance is present. " + << "Use --force if you really want to test healthd."; + GTEST_SKIP(); + } + LOG(INFO) << "get service with name:" << serviceName; ASSERT_FALSE(serviceName.empty()); mHealth = ::testing::VtsHalHidlTargetTestBase::getService(serviceName); @@ -269,6 +280,7 @@ int main(int argc, char** argv) { ::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); HealthHidlEnvironment::Instance()->init(&argc, argv); + gflags::ParseCommandLineFlags(&argc, &argv, true /* remove flags */); int status = RUN_ALL_TESTS(); LOG(INFO) << "Test result = " << status; return status; From 68c09adf4c387650dadf3419334dc8db9da008ce Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 8 Mar 2019 11:37:33 -0800 Subject: [PATCH 2/2] health vts: implement GTEST_SKIP if not defined. gtest in Android P tree does not have GTEST_SKIP. Implement a naive version of it. Bug: 118852225 Test: manually undefine GTEST_SKIP, test with and without --force Change-Id: I8df1154d8a94a67ae28e8024de6022fcfe76384d Merged-In: I8df1154d8a94a67ae28e8024de6022fcfe76384d (cherry picked from commit 03b2a3477b9c39403a8cc641e0d7ef2d092eff66) --- .../functional/VtsHalHealthV2_0TargetTest.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp index 55b48b86ff..7bb47fdd1f 100644 --- a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp +++ b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp @@ -17,6 +17,8 @@ #define LOG_TAG "health_hidl_hal_test" #include +#include +#include #include #include @@ -32,6 +34,39 @@ using ::testing::VtsHalHidlTargetTestEnvBase; DEFINE_bool(force, false, "Force test healthd even when the default instance is present."); +// If GTEST_SKIP is not implemented, use our own skipping mechanism +#ifndef GTEST_SKIP +static std::mutex gSkippedTestsMutex; +static std::set gSkippedTests; +static std::string GetCurrentTestName() { + const auto& info = ::testing::UnitTest::GetInstance()->current_test_info(); +#ifdef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + std::string test_suite = info->test_suite_name(); +#else + std::string test_suite = info->test_case_name(); +#endif + return test_suite + "." + info->name(); +} + +#define GTEST_SKIP() \ + do { \ + std::unique_lock lock(gSkippedTestsMutex); \ + gSkippedTests.insert(GetCurrentTestName()); \ + return; \ + } while (0) + +#define SKIP_IF_SKIPPED() \ + do { \ + std::unique_lock lock(gSkippedTestsMutex); \ + if (gSkippedTests.find(GetCurrentTestName()) != gSkippedTests.end()) { \ + std::cerr << "[ SKIPPED ] " << GetCurrentTestName() << std::endl; \ + return; \ + } \ + } while (0) +#else +#define SKIP_IF_SKIPPED() +#endif + namespace android { namespace hardware { namespace health { @@ -122,6 +157,7 @@ AssertionResult isAllOk(const Return& r) { * unregisterCallback, and update. */ TEST_F(HealthHidlTest, Callbacks) { + SKIP_IF_SKIPPED(); using namespace std::chrono_literals; sp firstCallback = new Callback(); sp secondCallback = new Callback(); @@ -158,6 +194,7 @@ TEST_F(HealthHidlTest, Callbacks) { } TEST_F(HealthHidlTest, UnregisterNonExistentCallback) { + SKIP_IF_SKIPPED(); sp callback = new Callback(); auto ret = mHealth->unregisterCallback(callback); ASSERT_OK(ret); @@ -239,6 +276,7 @@ bool verifyHealthInfo(const HealthInfo& health_info) { * interface IHealth. */ TEST_F(HealthHidlTest, Properties) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getChargeCounter([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value > 0); }));