Convert audio hal test to use VtsHalHidlTargetTestEnvBase

Bug: 64203181
Test: make vts
      vts-tradefed run vts -m VtsHalAudioV2_0Target

Change-Id: I1f85216c992eabf70f7e907b5d2afc4fb59cbb4a
This commit is contained in:
Zhuoyao Zhang 2018-01-23 18:16:27 -08:00
parent 744e71e3e8
commit f62c91f057
2 changed files with 13 additions and 5 deletions

View file

@ -20,6 +20,7 @@
#include <functional>
#include <list>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <gtest/gtest.h>
namespace android {
@ -33,13 +34,13 @@ namespace utility {
* Avoid destroying static objects after main return.
* Post main return destruction leads to incorrect gtest timing measurements as
* well as harder debuging if anything goes wrong during destruction. */
class Environment : public ::testing::Environment {
class Environment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
using TearDownFunc = std::function<void()>;
void registerTearDown(TearDownFunc&& tearDown) { tearDowns.push_back(std::move(tearDown)); }
private:
void TearDown() override {
void HidlTearDown() override {
// Call the tear downs in reverse order of insertion
for (auto& tearDown : tearDowns) {
tearDown();

View file

@ -88,8 +88,13 @@ using ::android::hardware::audio::common::V2_0::ThreadInfo;
using namespace ::android::hardware::audio::common::test::utility;
class AudioHidlTestEnvironment : public ::Environment {
public:
virtual void registerTestServices() override { registerTestService<IDevicesFactory>(); }
};
// Instance to register global tearDown
static Environment* environment;
static AudioHidlTestEnvironment* environment;
class HidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
@ -109,7 +114,8 @@ class AudioHidlTest : public HidlTest {
if (devicesFactory == nullptr) {
environment->registerTearDown([] { devicesFactory.clear(); });
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>();
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(
environment->getServiceName<IDevicesFactory>("default"));
}
ASSERT_TRUE(devicesFactory != nullptr);
}
@ -1265,9 +1271,10 @@ TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) {
//////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv) {
environment = new Environment;
environment = new AudioHidlTestEnvironment;
::testing::AddGlobalTestEnvironment(environment);
::testing::InitGoogleTest(&argc, argv);
environment->init(&argc, argv);
int status = RUN_ALL_TESTS();
return status;
}