Merge "Convert broadcastradio hal test to use VtsHalHidlTargetTestEnvBase"

This commit is contained in:
Zhuoyao Zhang 2018-02-14 17:25:33 +00:00 committed by Android (Google) Code Review
commit b46346f9bd
6 changed files with 88 additions and 15 deletions

View file

@ -18,5 +18,8 @@ cc_test {
name: "VtsHalBroadcastradioV1_0TargetTest",
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalBroadcastradioV1_0TargetTest.cpp"],
static_libs: ["android.hardware.broadcastradio@1.0"],
static_libs: [
"android.hardware.broadcastradio@1.0",
"android.hardware.broadcastradio@vts-utils-lib",
],
}

View file

@ -22,12 +22,12 @@
#include <hidl/HidlTransportSupport.h>
#include <utils/threads.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h>
#include <android/hardware/broadcastradio/1.0/ITuner.h>
#include <android/hardware/broadcastradio/1.0/ITunerCallback.h>
#include <android/hardware/broadcastradio/1.0/types.h>
#include <broadcastradio-vts-utils/environment-utils.h>
using ::android::sp;
using ::android::Mutex;
@ -48,6 +48,7 @@ using ::android::hardware::broadcastradio::V1_0::ProgramInfo;
using ::android::hardware::broadcastradio::V1_0::MetaData;
using ::android::hardware::broadcastradio::V1_0::MetadataKey;
using ::android::hardware::broadcastradio::V1_0::MetadataType;
using ::android::hardware::broadcastradio::vts::BroadcastRadioHidlEnvironment;
#define RETURN_IF_SKIPPED \
if (skipped) { \
@ -55,8 +56,8 @@ using ::android::hardware::broadcastradio::V1_0::MetadataType;
return; \
}
static BroadcastRadioHidlEnvironment<IBroadcastRadioFactory>* gEnv = nullptr;
// The main test class for Broadcast Radio HIDL HAL.
class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase,
public ::testing::WithParamInterface<Class> {
protected:
@ -67,7 +68,7 @@ class BroadcastRadioHidlTest : public ::testing::VtsHalHidlTargetTestBase,
skipped = false;
sp<IBroadcastRadioFactory> factory =
::testing::VtsHalHidlTargetTestBase::getService<IBroadcastRadioFactory>();
getService<IBroadcastRadioFactory>(gEnv->getServiceName<IBroadcastRadioFactory>());
ASSERT_NE(nullptr, factory.get());
Result connectResult;
@ -731,8 +732,11 @@ INSTANTIATE_TEST_CASE_P(
::testing::Values(Class::AM_FM, Class::SAT, Class::DT));
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
gEnv = new BroadcastRadioHidlEnvironment<IBroadcastRadioFactory>;
::testing::AddGlobalTestEnvironment(gEnv);
::testing::InitGoogleTest(&argc, argv);
gEnv->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}

View file

@ -25,6 +25,7 @@
#include <android/hardware/broadcastradio/1.1/types.h>
#include <broadcastradio-utils-1x/Utils.h>
#include <broadcastradio-vts-utils/call-barrier.h>
#include <broadcastradio-vts-utils/environment-utils.h>
#include <broadcastradio-vts-utils/mock-timeout.h>
#include <broadcastradio-vts-utils/pointer-utils.h>
#include <cutils/native_handle.h>
@ -58,6 +59,7 @@ using V1_0::MetadataKey;
using V1_0::MetadataType;
using broadcastradio::vts::clearAndWait;
using broadcastradio::vts::BroadcastRadioHidlEnvironment;
static constexpr auto kConfigTimeout = 10s;
static constexpr auto kConnectModuleTimeout = 1s;
@ -91,6 +93,8 @@ struct TunerCallbackMock : public ITunerCallback {
MOCK_TIMEOUT_METHOD1(currentProgramInfoChanged, Return<void>(const ProgramInfo&));
};
static BroadcastRadioHidlEnvironment<IBroadcastRadioFactory>* gEnv = nullptr;
class BroadcastRadioHalTest : public ::testing::VtsHalHidlTargetTestBase,
public ::testing::WithParamInterface<Class> {
protected:
@ -119,7 +123,8 @@ void BroadcastRadioHalTest::SetUp() {
radioClass = GetParam();
// lookup HIDL service
auto factory = getService<IBroadcastRadioFactory>();
auto factory =
getService<IBroadcastRadioFactory>(gEnv->getServiceName<IBroadcastRadioFactory>());
ASSERT_NE(nullptr, factory.get());
// connect radio module
@ -606,8 +611,14 @@ INSTANTIATE_TEST_CASE_P(BroadcastRadioHalTestCases, BroadcastRadioHalTest,
} // namespace android
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
using android::hardware::broadcastradio::V1_1::vts::gEnv;
using android::hardware::broadcastradio::V1_1::IBroadcastRadioFactory;
using android::hardware::broadcastradio::vts::BroadcastRadioHidlEnvironment;
gEnv = new BroadcastRadioHidlEnvironment<IBroadcastRadioFactory>;
::testing::AddGlobalTestEnvironment(gEnv);
::testing::InitGoogleTest(&argc, argv);
gEnv->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}

View file

@ -26,6 +26,7 @@
#include <android/hardware/broadcastradio/2.0/types.h>
#include <broadcastradio-utils-2x/Utils.h>
#include <broadcastradio-vts-utils/call-barrier.h>
#include <broadcastradio-vts-utils/environment-utils.h>
#include <broadcastradio-vts-utils/mock-timeout.h>
#include <broadcastradio-vts-utils/pointer-utils.h>
#include <cutils/bitops.h>
@ -52,6 +53,7 @@ using testing::DoAll;
using testing::Invoke;
using testing::SaveArg;
using broadcastradio::vts::BroadcastRadioHidlEnvironment;
using broadcastradio::vts::CallBarrier;
using broadcastradio::vts::clearAndWait;
using utils::make_identifier;
@ -97,6 +99,8 @@ struct AnnouncementListenerMock : public IAnnouncementListener {
MOCK_METHOD1(onListUpdated, Return<void>(const hidl_vec<Announcement>&));
};
static BroadcastRadioHidlEnvironment<IBroadcastRadio>* gEnv = nullptr;
class BroadcastRadioHalTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
virtual void SetUp() override;
@ -171,7 +175,7 @@ void BroadcastRadioHalTest::SetUp() {
EXPECT_EQ(nullptr, mModule.get()) << "Module is already open";
// lookup HIDL service (radio module)
mModule = getService<IBroadcastRadio>();
mModule = getService<IBroadcastRadio>(gEnv->getServiceName<IBroadcastRadio>());
ASSERT_NE(nullptr, mModule.get()) << "Couldn't find broadcast radio HAL implementation";
// get module properties
@ -804,7 +808,13 @@ TEST_F(BroadcastRadioHalTest, AnnouncementListenerRegistration) {
} // namespace android
int main(int argc, char** argv) {
using android::hardware::broadcastradio::V2_0::vts::gEnv;
using android::hardware::broadcastradio::V2_0::IBroadcastRadio;
using android::hardware::broadcastradio::vts::BroadcastRadioHidlEnvironment;
gEnv = new BroadcastRadioHidlEnvironment<IBroadcastRadio>;
::testing::AddGlobalTestEnvironment(gEnv);
::testing::InitGoogleTest(&argc, argv);
gEnv->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;

View file

@ -25,4 +25,8 @@ cc_library_static {
"-Wextra",
"-Werror",
],
static_libs: [
"VtsHalHidlTargetTestBase",
],
group_static_libs: true,
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_BROADCASTRADIO_VTS_ENVIRONMENT_UTILS
#define ANDROID_HARDWARE_BROADCASTRADIO_VTS_ENVIRONMENT_UTILS
#include <VtsHalHidlTargetTestEnvBase.h>
namespace android {
namespace hardware {
namespace broadcastradio {
namespace vts {
// Test environment for BroadcastRadio HIDL HAL.
template <typename... T>
class BroadcastRadioHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
virtual void registerTestServices() override {
using expander = int[];
(void)expander{0, (registerTestService<T>(), 0)...};
}
};
} // namespace vts
} // namespace broadcastradio
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_BROADCASTRADIO_VTS_ENVIRONMENT_UTILS