Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55adb1b6 authored by Sohani Rao's avatar Sohani Rao
Browse files

VTS for Wifi Offload HAL

Basic VTS test suite for Wifi Offload HAL
Cherry pick from 00dd5147c4f9a4cdff941b2eed12e1d5844bef86
Bug: 32842314
Bug: 36865676
Change-Id: I702b9d90164f21104a915003b9496fbf4dd969c0
Test: adb shell /data/VtsHalWifiOffloadV1_0TargetTest
parent b3c3f8c1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,5 +3,6 @@ subdirs = [
    "1.0",
    "1.0/vts/functional",
    "offload/1.0",
    "offload/1.0/vts/functional",
    "supplicant/1.0",
]
+36 −0
Original line number Diff line number Diff line
//
// 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.
//

cc_test {
    name: "VtsHalWifiOffloadV1_0TargetTest",
    defaults: ["hidl_defaults"],
    srcs: ["VtsHalWifiOffloadV1_0TargetTest.cpp"],
    shared_libs: [
        "libbase",
        "liblog",
        "libcutils",
        "libhidlbase",
        "libhidltransport",
        "libnativehelper",
        "libutils",
        "android.hardware.wifi.offload@1.0",
    ],
    static_libs: ["VtsHalHidlTargetTestBase"],
    cflags: [
        "-O0",
        "-g",
    ],
}
+151 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

#define LOG_TAG "wifi_offload_hidl_hal_test"

#include <android-base/logging.h>
#include <android/hardware/wifi/offload/1.0/IOffload.h>
#include <android/hardware/wifi/offload/1.0/IOffloadCallback.h>
#include <android/hardware/wifi/offload/1.0/types.h>

#include <VtsHalHidlTargetTestBase.h>

#include <vector>

using ::android::hardware::wifi::offload::V1_0::IOffload;
using ::android::hardware::wifi::offload::V1_0::IOffloadCallback;
using ::android::hardware::wifi::offload::V1_0::ScanResult;
using ::android::hardware::wifi::offload::V1_0::ScanParam;
using ::android::hardware::wifi::offload::V1_0::ScanFilter;
using ::android::hardware::wifi::offload::V1_0::ScanStats;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::sp;

typedef std::function<void(const std::vector<ScanResult>& scanResult)>
    OnOffloadScanResultsReadyHandler;

// The main test class for WifiOffload HIDL HAL.
class WifiOffloadHidlTest : public ::testing::VtsHalHidlTargetTestBase {
   public:
    virtual void SetUp() override {
        wifi_offload_ =
            ::testing::VtsHalHidlTargetTestBase::getService<IOffload>();
        ASSERT_NE(wifi_offload_, nullptr);

        wifi_offload_cb_ = new OffloadCallback(
            [this](std::vector<ScanResult> scanResult) -> void {
                this->reportScanResults(scanResult);
            });
        ASSERT_NE(wifi_offload_cb_, nullptr);

        defaultSize = 0;
    }

    virtual void TearDown() override {}

    void reportScanResults(std::vector<ScanResult> scanResult) {
        defaultSize = scanResult.size();
    }

    /* Callback class for scanResult. */
    class OffloadCallback : public IOffloadCallback {
       public:
        OffloadCallback(OnOffloadScanResultsReadyHandler handler)
            : handler_(handler){};

        virtual ~OffloadCallback() = default;

        Return<void> onScanResult(
            const hidl_vec<ScanResult>& scanResult) override {
            const std::vector<ScanResult> scanResult_(scanResult);
            handler_(scanResult_);
            return Void();
        };

       private:
        OnOffloadScanResultsReadyHandler handler_;
    };

    sp<IOffload> wifi_offload_;
    sp<IOffloadCallback> wifi_offload_cb_;
    int defaultSize = 0;
};

/*
 * Verify that setEventCallback method returns without errors
 */
TEST_F(WifiOffloadHidlTest, setEventCallback) {
    auto returnObject = wifi_offload_->setEventCallback(wifi_offload_cb_);
    ASSERT_EQ(returnObject.isOk(), true);
}

/*
 * Verify that subscribeScanResults method returns without errors
 */
TEST_F(WifiOffloadHidlTest, subscribeScanResults) {
    auto returnObject = wifi_offload_->subscribeScanResults(0);
    ASSERT_EQ(returnObject.isOk(), true);
}

/*
 * Verify that unsubscribeScanResults method returns without errors
 */
TEST_F(WifiOffloadHidlTest, unsubscribeScanResults) {
    auto returnObject = wifi_offload_->unsubscribeScanResults();
    ASSERT_EQ(returnObject.isOk(), true);
}

/*
 * Verify that configureScans method returns without errors
 */
TEST_F(WifiOffloadHidlTest, configureScans) {
    ScanParam* pScanParam = new ScanParam();
    ScanFilter* pScanFilter = new ScanFilter();
    auto returnObject =
        wifi_offload_->configureScans(*pScanParam, *pScanFilter);
    ASSERT_EQ(returnObject.isOk(), true);
}

/*
 * Verify that getScanStats returns without any errors
 */
TEST_F(WifiOffloadHidlTest, getScanStats) {
    ScanStats* pScanStats = new ScanStats();
    const auto& returnObject =
        wifi_offload_->getScanStats([pScanStats](ScanStats scanStats) -> void {
            *pScanStats = std::move(scanStats);
        });
    ASSERT_EQ(returnObject.isOk(), true);
}

// A class for test environment setup
class WifiOffloadHalHidlEnvironment : public ::testing::Environment {
   public:
    virtual void SetUp() {}
    virtual void TearDown() {}
};

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(new WifiOffloadHalHidlEnvironment);
    ::testing::InitGoogleTest(&argc, argv);

    int status = RUN_ALL_TESTS();
    LOG(INFO) << "Test result = " << status;

    return status;
}