Files
hardware_interfaces/tetheroffload/control/1.0/vts/functional/OffloadControlTestBase.cpp
junyulai 6f2cd06e03 Refactor 1.0 TetheroffloadControl VTS
This is a pure no-op refactoring that split the implementation
into several files. So the follow-up tests might be able to
re-use them to prevent from code duplication.

Test: atest VtsHalTetheroffloadControlV1_0TargetTest

Bug: 149467454
Bug: 170699770
Bug: 170179169
Change-Id: Icda34e3eb4d4ccb9f4564e23a61bd71323ca9bb3
2020-11-12 11:22:13 +08:00

95 lines
3.6 KiB
C++

/*
* Copyright (C) 2020 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.
*/
#include <OffloadControlTestBase.h>
void OffloadControlTestBase::TearDown() {
// For good measure, the teardown should try stopOffload() once more, since
// different HAL call test cycles might enter this function. Also the
// return code cannot be actually expected for all cases, hence ignore it.
stopOffload(ExpectBoolean::Ignored);
}
// The IOffloadConfig HAL is tested more thoroughly elsewhere. Here the class
// just setup everything correctly and verify basic readiness.
void OffloadControlTestBase::setupConfigHal() {
config = IOffloadConfig::getService(std::get<0>(GetParam()));
ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
unique_fd fd1(conntrackSocket(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY));
if (fd1.get() < 0) {
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
FAIL();
}
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
nativeHandle1->data[0] = fd1.release();
hidl_handle h1;
h1.setTo(nativeHandle1, true);
unique_fd fd2(conntrackSocket(NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY));
if (fd2.get() < 0) {
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
FAIL();
}
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
nativeHandle2->data[0] = fd2.release();
hidl_handle h2;
h2.setTo(nativeHandle2, true);
const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
ASSERT_TRUE(ret.isOk());
}
void OffloadControlTestBase::prepareControlHal() {
control = createControl(std::get<1>(GetParam()));
ASSERT_NE(nullptr, control.get()) << "Could not get HIDL instance";
control_cb = new TetheringOffloadCallback();
ASSERT_NE(nullptr, control_cb.get()) << "Could not get get offload callback";
}
void OffloadControlTestBase::initOffload(const bool expected_result) {
auto init_cb = [&](bool success, std::string errMsg) {
std::string msg = StringPrintf("Unexpectedly %s to init offload: %s",
success ? "succeeded" : "failed", errMsg.c_str());
ASSERT_EQ(expected_result, success) << msg;
};
const Return<void> ret = control->initOffload(control_cb, init_cb);
ASSERT_TRUE(ret.isOk());
}
void OffloadControlTestBase::setupControlHal() {
prepareControlHal();
initOffload(true);
}
void OffloadControlTestBase::stopOffload(const ExpectBoolean value) {
auto cb = [&](bool success, const hidl_string& errMsg) {
switch (value) {
case ExpectBoolean::False:
ASSERT_EQ(false, success) << "Unexpectedly able to stop offload: " << errMsg;
break;
case ExpectBoolean::True:
ASSERT_EQ(true, success) << "Unexpectedly failed to stop offload: " << errMsg;
break;
case ExpectBoolean::Ignored:
break;
}
};
const Return<void> ret = control->stopOffload(cb);
ASSERT_TRUE(ret.isOk());
}