diff options
author | Yifan Hong <elsk@google.com> | 2019-03-08 11:37:33 -0800 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2019-03-08 15:00:48 -0800 |
commit | 03b2a3477b9c39403a8cc641e0d7ef2d092eff66 (patch) | |
tree | 1928ba120ffba49729c0ae95990fd3aa4b50d55b /health | |
parent | 1d2cd434761c5fd4875502aff00b9d979b5f8048 (diff) | |
download | android_hardware_interfaces-03b2a3477b9c39403a8cc641e0d7ef2d092eff66.tar.gz android_hardware_interfaces-03b2a3477b9c39403a8cc641e0d7ef2d092eff66.tar.bz2 android_hardware_interfaces-03b2a3477b9c39403a8cc641e0d7ef2d092eff66.zip |
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
Diffstat (limited to 'health')
-rw-r--r-- | health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp index 4af8a5df3..74fe4fbd8 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 <mutex> +#include <set> +#include <string> #include <VtsHalHidlTargetTestBase.h> #include <android-base/logging.h> @@ -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<std::string> 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<std::mutex> lock(gSkippedTestsMutex); \ + gSkippedTests.insert(GetCurrentTestName()); \ + return; \ + } while (0) + +#define SKIP_IF_SKIPPED() \ + do { \ + std::unique_lock<std::mutex> 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<Result>& r) { * unregisterCallback, and update. */ TEST_F(HealthHidlTest, Callbacks) { + SKIP_IF_SKIPPED(); using namespace std::chrono_literals; sp<Callback> firstCallback = new Callback(); sp<Callback> secondCallback = new Callback(); @@ -158,6 +194,7 @@ TEST_F(HealthHidlTest, Callbacks) { } TEST_F(HealthHidlTest, UnregisterNonExistentCallback) { + SKIP_IF_SKIPPED(); sp<Callback> callback = new Callback(); auto ret = mHealth->unregisterCallback(callback); ASSERT_OK(ret); @@ -236,6 +273,7 @@ bool verifyHealthInfo(const HealthInfo& health_info) { * Tests the values returned by getChargeCounter() from interface IHealth. */ TEST_F(HealthHidlTest, getChargeCounter) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getChargeCounter([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value > 0); })); @@ -245,6 +283,7 @@ TEST_F(HealthHidlTest, getChargeCounter) { * Tests the values returned by getCurrentNow() from interface IHealth. */ TEST_F(HealthHidlTest, getCurrentNow) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getCurrentNow([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT32_MIN); })); @@ -254,6 +293,7 @@ TEST_F(HealthHidlTest, getCurrentNow) { * Tests the values returned by getCurrentAverage() from interface IHealth. */ TEST_F(HealthHidlTest, getCurrentAverage) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getCurrentAverage([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT32_MIN); })); @@ -263,6 +303,7 @@ TEST_F(HealthHidlTest, getCurrentAverage) { * Tests the values returned by getCapacity() from interface IHealth. */ TEST_F(HealthHidlTest, getCapacity) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getCapacity([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), 0 <= value && value <= 100); })); @@ -272,6 +313,7 @@ TEST_F(HealthHidlTest, getCapacity) { * Tests the values returned by getEnergyCounter() from interface IHealth. */ TEST_F(HealthHidlTest, getEnergyCounter) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getEnergyCounter([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, std::to_string(value), value != INT64_MIN); })); @@ -281,6 +323,7 @@ TEST_F(HealthHidlTest, getEnergyCounter) { * Tests the values returned by getChargeStatus() from interface IHealth. */ TEST_F(HealthHidlTest, getChargeStatus) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getChargeStatus([](auto result, auto value) { EXPECT_VALID_OR_UNSUPPORTED_PROP( result, toString(value), @@ -292,6 +335,7 @@ TEST_F(HealthHidlTest, getChargeStatus) { * Tests the values returned by getStorageInfo() from interface IHealth. */ TEST_F(HealthHidlTest, getStorageInfo) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getStorageInfo([](auto result, auto& value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), verifyStorageInfo(value)); })); @@ -301,6 +345,7 @@ TEST_F(HealthHidlTest, getStorageInfo) { * Tests the values returned by getDiskStats() from interface IHealth. */ TEST_F(HealthHidlTest, getDiskStats) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getDiskStats([](auto result, auto& value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), true); })); @@ -310,6 +355,7 @@ TEST_F(HealthHidlTest, getDiskStats) { * Tests the values returned by getHealthInfo() from interface IHealth. */ TEST_F(HealthHidlTest, getHealthInfo) { + SKIP_IF_SKIPPED(); EXPECT_OK(mHealth->getHealthInfo([](auto result, auto& value) { EXPECT_VALID_OR_UNSUPPORTED_PROP(result, toString(value), verifyHealthInfo(value)); })); |