Merge changes from topic '7_CLS_topic' into oc-dr1-dev

* changes:
  Offload HAL Service: Device manifest typo
  Offload HAL Service: Unit test framework
  Offload HAL service: Handle callback binder death
  Offload HAL Service: Implement returning values in APIs
This commit is contained in:
TreeHugger Robot
2017-06-22 17:40:01 +00:00
committed by Android (Google) Code Review
23 changed files with 823 additions and 48 deletions

View File

@@ -317,7 +317,7 @@
<instance>default</instance>
</interface>
</hal>
<hal format="hild">
<hal format="hidl">
<name>android.hardware.wifi.offload</name>
<transport>hwbinder</transport>
<version>1.0</version>

View File

@@ -13,16 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
cc_binary {
name: "android.hardware.wifi.offload@1.0-service",
relative_install_path: "hw",
init_rc: ["android.hardware.wifi.offload@1.0-service.rc"],
cc_library_static {
name: "android.hardware.wifi.offload@1.0-lib",
srcs: ["Offload.cpp",
"service.cpp",
"chre_constants.cpp",
"chre_interface.cpp",
"offload_server.cpp",
"chre_interface_factory.cpp",
"offload_status_util.cpp",
],
cflags: ["-Wall", "-Wextra"],
shared_libs: [
@@ -33,7 +31,58 @@ cc_binary {
"libutils",
"android.hardware.wifi.offload@1.0",
],
static_libs: ["chre_client"],
whole_static_libs: [
"chre_client"
]
}
cc_binary {
name: "android.hardware.wifi.offload@1.0-service",
relative_install_path: "hw",
init_rc: ["android.hardware.wifi.offload@1.0-service.rc"],
srcs: ["service.cpp"],
cflags: ["-Wall", "-Wextra"],
shared_libs: [
"libbase",
"libhidlbase",
"libhidltransport",
"liblog",
"libutils",
"android.hardware.wifi.offload@1.0",
],
static_libs: [
"android.hardware.wifi.offload@1.0-lib",
],
vendor: true,
}
cc_test {
name: "wifi-offload-service-unit-tests",
vendor: true,
srcs: [
"test/main.cpp",
"test/mock_chre_interface_callbacks.cpp",
"test/mock_chre_interface_factory.cpp",
"test/mock_chre_interface.cpp",
"test/offload_server_test.cpp",
"test/chre_interface_test.cpp",
],
local_include_dirs: [
"test",
".",
],
shared_libs: [
"libbase",
"libhidlbase",
"libhidltransport",
"libutils",
"liblog",
"android.hardware.wifi.offload@1.0",
],
static_libs: [
"libgmock",
"libgtest",
"android.hardware.wifi.offload@1.0-lib",
],
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 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.
-->
<configuration description="Config for wifi-offload-service-unit-tests">
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" />
<option name="push" value="wifi-offload-service-unit-tests->/data/local/tmp/wifi-offload-service-unit-tests" />
</target_preparer>
<option name="test-suite-tag" value="apct" />
<test class="com.android.tradefed.testtype.GTest" >
<option name="native-test-device-path" value="/data/local/tmp" />
<option name="module-name" value="wifi-offload-service-unit-tests" />
</test>
</configuration>

View File

@@ -3,6 +3,7 @@
#include <android-base/logging.h>
#include "chre_interface_factory.h"
#include "hidl_return_util.h"
namespace android {
namespace hardware {
@@ -11,34 +12,27 @@ namespace offload {
namespace V1_0 {
namespace implementation {
Offload::Offload() : mOffloadServer(new OffloadServer(new ChreInterfaceFactory())) {
using hidl_return_util::validateAndCall;
Offload::Offload()
: mOffloadServer(new OffloadServer(new ChreInterfaceFactory())), cookie_(0),
death_handler_(new HidlDeathHandler<IOffloadCallback>(
std::bind(&Offload::onObjectDeath, this, std::placeholders::_1))) {
LOG(android::base::INFO) << "Wifi Offload HAL impl";
}
// Methods from ::android::hardware::wifi::offload::V1_0::IOffload follow.
Return<void> Offload::configureScans(const ScanParam& param, const ScanFilter& filter) {
if (!mOffloadServer->configureScans(param, filter)) {
LOG(ERROR) << "Failure configuring scans";
}
return Void();
Return<void> Offload::configureScans(const ScanParam &param, const ScanFilter &filter,
configureScans_cb _hidl_cb) {
return validateAndCall(this, &Offload::configureScansInternal, _hidl_cb, param, filter);
}
Return<void> Offload::getScanStats(getScanStats_cb offloadScanStatsCallback) {
ScanStats stats;
bool success;
std::tie(stats, success) = mOffloadServer->getScanStats();
if (!success) {
LOG(ERROR) << "Invalid results reported";
}
offloadScanStatsCallback(stats);
return Void();
Return<void> Offload::getScanStats(getScanStats_cb _hidl_cb) {
return validateAndCall(this, &Offload::getScanStatsInternal, _hidl_cb);
}
Return<void> Offload::subscribeScanResults(uint32_t delayMs) {
if (!mOffloadServer->subscribeScanResults(delayMs)) {
LOG(ERROR) << "Unable to subscribe scans";
}
return Void();
Return<void> Offload::subscribeScanResults(uint32_t delayMs, subscribeScanResults_cb _hidl_cb) {
return validateAndCall(this, &Offload::subscribeScanResultsInternal, _hidl_cb, delayMs);
}
Return<void> Offload::unsubscribeScanResults() {
@@ -51,10 +45,33 @@ Return<void> Offload::unsubscribeScanResults() {
Return<void> Offload::setEventCallback(const sp<IOffloadCallback>& cb) {
if (!mOffloadServer->setEventCallback(cb)) {
LOG(ERROR) << "No callback set";
return Void();
}
cookie_ = reinterpret_cast<uint64_t>(cb.get());
death_handler_->setCallback(cb);
cb->linkToDeath(death_handler_, cookie_);
return Void();
}
OffloadStatus Offload::configureScansInternal(const ScanParam &param, const ScanFilter &filter) {
return mOffloadServer->configureScans(param, filter);
}
std::pair<OffloadStatus, ScanStats> Offload::getScanStatsInternal() {
return mOffloadServer->getScanStats();
}
OffloadStatus Offload::subscribeScanResultsInternal(uint32_t delayMs) {
return mOffloadServer->subscribeScanResults(delayMs);
}
void Offload::onObjectDeath(uint64_t cookie) {
if (cookie == cookie_) {
LOG(DEBUG) << "OffloadCallback death notification received";
mOffloadServer->clearEventCallback();
cookie_ = 0;
}
}
// Methods from ::android::hidl::base::V1_0::IBase follow.
} // namespace implementation

View File

@@ -9,6 +9,38 @@
#include "offload_server.h"
namespace {
// Type of callback invoked by the death handler.
using on_death_cb_function = std::function<void(uint64_t)>;
// Private class used to keep track of death of callbacks
template<typename CallbackType>
class HidlDeathHandler : public android::hardware::hidl_death_recipient {
public:
HidlDeathHandler(const on_death_cb_function &user_cb_function)
: cb_function_(user_cb_function) {
}
~HidlDeathHandler() = default;
// Death notification for callbacks.
void serviceDied(uint64_t cookie,
const android::wp<android::hidl::base::V1_0::IBase> &who) override {
cb_.clear();
cb_function_(cookie);
}
void setCallback(android::wp<CallbackType> cb) {
cb_ = cb;
}
private:
android::wp<CallbackType> cb_;
on_death_cb_function cb_function_;
DISALLOW_COPY_AND_ASSIGN(HidlDeathHandler);
};
} // namespace
namespace android {
namespace hardware {
namespace wifi {
@@ -24,17 +56,23 @@ class Offload : public IOffload {
Offload();
// Methods from ::android::hardware::wifi::offload::V1_0::IOffload follow.
Return<void> configureScans(const ScanParam& param,
const ScanFilter& filter) override;
Return<void> getScanStats(
getScanStats_cb offloadScanStatsCallback) override;
Return<void> subscribeScanResults(uint32_t delayMs) override;
Return<void> configureScans(const ScanParam &param, const ScanFilter &filter,
configureScans_cb _hidl_cb) override;
Return<void> getScanStats(getScanStats_cb _hidl_cb) override;
Return<void> subscribeScanResults(uint32_t delayMs, subscribeScanResults_cb _hidl_cb) override;
Return<void> unsubscribeScanResults() override;
Return<void> setEventCallback(const sp<IOffloadCallback>& cb) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
private:
OffloadStatus configureScansInternal(const ScanParam &param, const ScanFilter &filter);
std::pair<OffloadStatus, ScanStats> getScanStatsInternal();
OffloadStatus subscribeScanResultsInternal(uint32_t delayMs);
void onObjectDeath(uint64_t cookie);
std::unique_ptr<OffloadServer> mOffloadServer;
uint64_t cookie_;
sp<HidlDeathHandler<IOffloadCallback>> death_handler_;
DISALLOW_COPY_AND_ASSIGN(Offload);
};

View File

@@ -121,7 +121,8 @@ void SocketCallbacks::handleUnloadNanoappResponse(const fbs::UnloadNanoappRespon
}
ChreInterface::ChreInterface(ChreInterfaceCallbacks* callback)
: mSocketCallbacks(new SocketCallbacks(this)), mServerCallbacks(callback) {
: mSocketCallbacks(new SocketCallbacks(this)), mServerCallbacks(callback),
mSocketConnected(false) {
if (!mClient.connectInBackground(chre_constants::kSocketName, mSocketCallbacks)) {
LOG(ERROR) << "Offload HAL is not connected to Chre";
}
@@ -132,21 +133,27 @@ ChreInterface::~ChreInterface() {
}
bool ChreInterface::isConnected() {
return mClient.isConnected();
std::lock_guard<std::mutex> lock(mChreInterfaceLock);
return mSocketConnected;
}
void ChreInterface::reportConnectionEvent(ChreInterfaceCallbacks::ConnectionEvent event) {
bool connectionStatus = false;
switch (event) {
case ChreInterfaceCallbacks::ConnectionEvent::CONNECTED:
connectionStatus = true;
break;
case ChreInterfaceCallbacks::ConnectionEvent::DISCONNECTED:
break;
case ChreInterfaceCallbacks::ConnectionEvent::CONNECTION_ABORT:
break;
default:
LOG(WARNING) << "Invalid connection event recieved";
return;
}
{
std::lock_guard<std::mutex> lock(mChreInterfaceLock);
mSocketConnected = connectionStatus;
}
mServerCallbacks->handleConnectionEvents(event);
}

View File

@@ -75,6 +75,8 @@ class ChreInterface {
::android::chre::SocketClient mClient;
sp<SocketCallbacks> mSocketCallbacks;
ChreInterfaceCallbacks* mServerCallbacks;
std::mutex mChreInterfaceLock;
bool mSocketConnected;
};
} // namespace implementation

View File

@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_
#define WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_
#ifndef WIFI_OFFLOAD_CHRE_INTERFACE_FACTORY_H_
#define WIFI_OFFLOAD_CHRE_INTERFACE_FACTORY_H_
#include "chre_interface.h"
#include "chre_interface_callbacks.h"
@@ -40,4 +40,4 @@ class ChreInterfaceFactory {
} // namespace hardware
} // namespace android
#endif // WIFI_OFFLOAD_CHRE_INTERFACE_UTILS_H_
#endif // WIFI_OFFLOAD_CHRE_INTERFACE_FACTORY_H_

View File

@@ -0,0 +1,71 @@
/*
* hidl interface for wpa_supplicant daemon
* Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
* Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
#ifndef HIDL_RETURN_UTIL_H_
#define HIDL_RETURN_UTIL_H_
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
namespace hidl_return_util {
/**
* These utility functions are used to invoke a method on the provided
* HIDL interface object.
* It then invokes the HIDL continuation callback with the status and
* any returned values.
*/
// Use for HIDL methods which return only an instance of OffloadStatus.
template<typename ObjT, typename WorkFuncT, typename... Args>
Return<void> validateAndCall(ObjT* obj, WorkFuncT&& work,
const std::function<void(const OffloadStatus&)>& hidl_cb,
Args&&... args) {
hidl_cb((obj->*work)(std::forward<Args>(args)...));
return Void();
}
// Use for HIDL methods which return instance of OffloadStatus and a single
// return value.
template<typename ObjT, typename WorkFuncT, typename ReturnT, typename... Args>
Return<void> validateAndCall(ObjT* obj, WorkFuncT&& work,
const std::function<void(const OffloadStatus&, ReturnT)>& hidl_cb,
Args&&... args) {
const auto& ret_pair = (obj->*work)(std::forward<Args>(args)...);
const OffloadStatus& status = std::get<0>(ret_pair);
const auto& ret_value = std::get<1>(ret_pair);
hidl_cb(status, ret_value);
return Void();
}
// Use for HIDL methods which return instance of OffloadStatus and 2 return
// values.
template<typename ObjT, typename WorkFuncT, typename ReturnT1, typename ReturnT2, typename... Args>
Return<void>
validateAndCall(ObjT* obj, WorkFuncT&& work,
const std::function<void(const OffloadStatus&, ReturnT1, ReturnT2)>& hidl_cb,
Args&&... args) {
const auto& ret_tuple = (obj->*work)(std::forward<Args>(args)...);
const OffloadStatus& status = std::get<0>(ret_tuple);
const auto& ret_value1 = std::get<1>(ret_tuple);
const auto& ret_value2 = std::get<2>(ret_tuple);
hidl_cb(status, ret_value1, ret_value2);
return Void();
}
} // namespace hidl_return_util
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // HIDL_RETURN_UTIL_H_

View File

@@ -2,7 +2,7 @@
#include <android-base/logging.h>
#include <chrono>
#include "offload_status_util.h"
namespace android {
namespace hardware {
@@ -19,19 +19,20 @@ OffloadServer::OffloadServer(ChreInterfaceFactory* factory)
LOG(VERBOSE) << "Wifi Offload HAL impl";
}
bool OffloadServer::configureScans(const ScanParam& param, const ScanFilter& filter) {
OffloadStatus OffloadServer::configureScans(const ScanParam& param, const ScanFilter& filter) {
LOG(INFO) << "configureScans";
return true;
return createOffloadStatus(OffloadStatusCode::OK);
}
std::pair<ScanStats, bool> OffloadServer::getScanStats() {
std::pair<OffloadStatus, ScanStats> OffloadServer::getScanStats() {
LOG(INFO) << "getScanStats";
return std::make_pair(mScanStats, true);
OffloadStatus status = createOffloadStatus(OffloadStatusCode::OK);
return std::make_pair(status, mScanStats);
}
bool OffloadServer::subscribeScanResults(uint32_t delayMs) {
OffloadStatus OffloadServer::subscribeScanResults(uint32_t delayMs) {
LOG(INFO) << "subscribeScanResults with delay:" << delayMs;
return true;
return createOffloadStatus(OffloadStatusCode::OK);
}
bool OffloadServer::unsubscribeScanResults() {
@@ -51,6 +52,13 @@ bool OffloadServer::setEventCallback(const sp<IOffloadCallback>& cb) {
return result;
}
void OffloadServer::clearEventCallback() {
if (mEventCallback != nullptr) {
mEventCallback.clear();
}
LOG(INFO) << "Event callback cleared";
}
ChreInterfaceCallbacksImpl::ChreInterfaceCallbacksImpl(OffloadServer* server) : mServer(server) {
}

View File

@@ -33,11 +33,12 @@ class OffloadServer {
public:
OffloadServer(ChreInterfaceFactory* factory);
bool configureScans(const ScanParam& param, const ScanFilter& filter);
std::pair<ScanStats, bool> getScanStats();
bool subscribeScanResults(uint32_t delayMs);
OffloadStatus configureScans(const ScanParam& param, const ScanFilter& filter);
std::pair<OffloadStatus, ScanStats> getScanStats();
OffloadStatus subscribeScanResults(uint32_t delayMs);
bool unsubscribeScanResults();
bool setEventCallback(const sp<IOffloadCallback>& cb);
void clearEventCallback();
private:
ScanStats mScanStats;

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 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 "offload_status_util.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
OffloadStatus createOffloadStatus(OffloadStatusCode code, const std::string &description) {
return {code, description};
}
OffloadStatus createOffloadStatus(OffloadStatusCode code) {
return createOffloadStatus(code, "");
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 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 OFFLOAD_STATUS_UTIL_H_
#define OFFLOAD_STATUS_UTIL_H_
#include <android/hardware/wifi/offload/1.0/IOffload.h>
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
OffloadStatus createOffloadStatus(OffloadStatusCode code, const std::string &description);
OffloadStatus createOffloadStatus(OffloadStatusCode code);
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // OFFLOAD_STATUS_UTIL_H_

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2016, 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 <gtest/gtest.h>
#include <android-base/logging.h>
#include "mock_chre_interface_callbacks.h"
#include "chre_interface.h"
namespace {
const size_t kBufSize = 256;
const uint8_t kDefaultValue = 0xaa;
const uint32_t kDefaultMessageType = 0;
} // namespace
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
class ChreInterfaceTest : public ::testing::Test {
protected:
virtual void SetUp() {
chre_interface_.reset(new ChreInterface(chre_interface_callback_.get()));
}
void TearDown() override {
}
std::unique_ptr<testing::NiceMock<MockChreInterfaceCallbacks>> chre_interface_callback_{
new testing::NiceMock<MockChreInterfaceCallbacks>()};
std::unique_ptr<ChreInterface> chre_interface_;
};
TEST_F(ChreInterfaceTest, ChreInterfaceConnectionEventTest) {
EXPECT_CALL(*chre_interface_callback_, handleConnectionEvents(testing::_));
chre_interface_->reportConnectionEvent(ChreInterfaceCallbacks::CONNECTED);
EXPECT_TRUE(chre_interface_->isConnected());
}
TEST_F(ChreInterfaceTest, ChreInterfaceHandleMessageTest) {
EXPECT_CALL(*chre_interface_callback_, handleMessage(testing::_, testing::_));
uint32_t messageType;
std::vector<uint8_t> buffer_recvd;
ON_CALL(*chre_interface_callback_, handleMessage(testing::_, testing::_))
.WillByDefault(
DoAll(testing::SaveArg<0>(&messageType), testing::SaveArg<1>(&buffer_recvd)));
uint8_t buffer_sent[kBufSize];
for (size_t j = 0; j < kBufSize; j++) {
buffer_sent[j] = kDefaultValue;
}
chre_interface_->handleMessage(kDefaultMessageType, (void*)&buffer_sent[0], kBufSize);
EXPECT_EQ(messageType, kDefaultMessageType);
EXPECT_EQ(buffer_recvd.size(), kBufSize);
for (size_t i = 0; i < buffer_recvd.size(); i++) {
EXPECT_EQ(buffer_recvd[i], buffer_sent[i]);
}
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <android-base/logging.h>
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::InitGoogleMock(&argc, argv);
// Force ourselves to always log to stderr
android::base::InitLogging(argv, android::base::StderrLogger);
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2016 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 "mock_chre_interface.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
MockChreInterface::MockChreInterface(ChreInterfaceCallbacks* callback) : ChreInterface(callback) {
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 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 WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_H_
#define WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "chre_interface.h"
#include "chre_interface_callbacks.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
class MockChreInterface : public ChreInterface {
public:
MockChreInterface(ChreInterfaceCallbacks* callback);
~MockChreInterface() = default;
MOCK_METHOD0(isConnected, bool());
MOCK_METHOD2(sendCommandToApp, bool(uint32_t messageType, const std::vector<uint8_t>& message));
MOCK_METHOD1(reportConnectionEvent, void(ChreInterfaceCallbacks::ConnectionEvent event));
MOCK_METHOD0(getHubInfo, bool());
MOCK_METHOD0(getNanoAppList, bool());
MOCK_METHOD3(handleMessage,
void(uint32_t messageType, const void* messageData, size_t messageDataLen));
};
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_H_

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 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 "mock_chre_interface_callbacks.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
MockChreInterfaceCallbacks::MockChreInterfaceCallbacks() {
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2016 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 WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_CALLBACKS_H_
#define WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_CALLBACKS_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "chre_interface_callbacks.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
class MockChreInterfaceCallbacks : public ChreInterfaceCallbacks {
public:
MockChreInterfaceCallbacks();
~MockChreInterfaceCallbacks() override = default;
MOCK_METHOD1(handleConnectionEvents, void(ChreInterfaceCallbacks::ConnectionEvent event));
MOCK_METHOD2(handleMessage, void(uint32_t messageType, const std::vector<uint8_t>& message));
};
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_CALLBACKS_H_

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2016 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 "mock_chre_interface_factory.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
MockChreInterfaceFactory::MockChreInterfaceFactory() {
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2017 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 WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_FACTORY_H_
#define WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_FACTORY_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "chre_interface_callbacks.h"
#include "chre_interface_factory.h"
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
class MockChreInterfaceFactory : public ChreInterfaceFactory {
public:
MockChreInterfaceFactory();
~MockChreInterfaceFactory() override = default;
MOCK_METHOD1(getChreInterface, ChreInterface*(ChreInterfaceCallbacks* handlers));
};
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // WIFI_OFFLOAD_MOCK_CHRE_INTERFACE_FACTORY_H_

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2016, 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 <gtest/gtest.h>
#include <android-base/logging.h>
#include "mock_chre_interface.h"
#include "mock_chre_interface_factory.h"
#include "chre_interface_callbacks.h"
#include "offload_server.h"
namespace {
using android::hardware::wifi::offload::V1_0::implementation::ChreInterfaceCallbacks;
using android::hardware::wifi::offload::V1_0::implementation::MockChreInterface;
using android::hardware::wifi::offload::V1_0::implementation::ChreInterface;
ChreInterface*
CaptureCallback(ChreInterfaceCallbacks* callback,
std::unique_ptr<ChreInterfaceCallbacks>* chre_interface_callback,
std::unique_ptr<testing::NiceMock<MockChreInterface>>* chre_interface) {
chre_interface->reset(new testing::NiceMock<MockChreInterface>(callback));
chre_interface_callback->reset(callback);
return chre_interface->get();
}
} // namespace
namespace android {
namespace hardware {
namespace wifi {
namespace offload {
namespace V1_0 {
namespace implementation {
class OffloadServerTest : public ::testing::Test {
protected:
virtual void SetUp() {
ON_CALL(*chre_interface_factory_, getChreInterface(testing::_))
.WillByDefault(testing::Invoke(std::bind(CaptureCallback, std::placeholders::_1,
&chre_interface_callback_, &chre_interface_)));
}
void TearDown() override {
}
std::unique_ptr<testing::NiceMock<MockChreInterfaceFactory>> chre_interface_factory_{
new testing::NiceMock<MockChreInterfaceFactory>()};
std::unique_ptr<testing::NiceMock<MockChreInterface>> chre_interface_;
std::unique_ptr<ChreInterfaceCallbacks> chre_interface_callback_;
};
TEST_F(OffloadServerTest, createOffloadServerTest) {
EXPECT_CALL(*chre_interface_factory_, getChreInterface(testing::_));
OffloadServer* server = new OffloadServer(chre_interface_factory_.get());
EXPECT_FALSE(chre_interface_callback_.get() == nullptr);
}
} // namespace implementation
} // namespace V1_0
} // namespace offload
} // namespace wifi
} // namespace hardware
} // namespace android

39
wifi_offload/test/runtest.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Copyright (C) 2016 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.
if [ -z $ANDROID_BUILD_TOP ]; then
echo "You need to source and lunch before you can use this script"
exit 1
fi
echo "Running tests"
set -e # fail early
# NOTE We can't actually run these commands, since they rely on functions added by
# build/envsetup.sh to the bash shell environment.
echo "+ mmma -j32 $ANDROID_BUILD_TOP/device/google/wahoo"
make -j32 -C $ANDROID_BUILD_TOP -f build/core/main.mk \
MODULES-IN-device-google-wahoo-wifi_offload
set -x # print commands
adb root
adb wait-for-device
adb remount
adb sync
adb shell /data/nativetest/wifi-offload-service-unit-tests/wifi-offload-service-unit-tests
adb shell /data/nativetest64/wifi-offload-service-unit-tests/wifi-offload-service-unit-tests