From a772e8bcd170a432fd130a93cfacd5b9736b4df4 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 4 Jan 2019 17:25:04 +0800 Subject: [PATCH] p2p: add vts for addGroup_1_2 Bug: 64695709 Test: build - make vts Test: atest VtsHalWifiSupplicantP2pV1_2TargetTest Test: vts-tradefed run commandAndExit vts-hal --skip-all-system-status-check \ --primary-abi-only --skip-preconditions --module \ VtsHalWifiSupplicantP2pV1_2Target -l INFO Change-Id: I679fbc7e55aea4a5b6baf3f4bf6f2b04fe7b7f7f --- wifi/supplicant/1.2/vts/OWNERS | 2 + wifi/supplicant/1.2/vts/functional/Android.bp | 60 ++++++++ .../VtsHalWifiSupplicantV1_2TargetTest.cpp | 60 ++++++++ .../supplicant_hidl_test_utils_1_2.cpp | 28 ++++ .../supplicant_hidl_test_utils_1_2.h | 25 ++++ .../supplicant_p2p_iface_hidl_test.cpp | 128 ++++++++++++++++++ 6 files changed, 303 insertions(+) create mode 100644 wifi/supplicant/1.2/vts/OWNERS create mode 100644 wifi/supplicant/1.2/vts/functional/Android.bp create mode 100644 wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp create mode 100644 wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp create mode 100644 wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h create mode 100644 wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp diff --git a/wifi/supplicant/1.2/vts/OWNERS b/wifi/supplicant/1.2/vts/OWNERS new file mode 100644 index 0000000000..8bfb14882c --- /dev/null +++ b/wifi/supplicant/1.2/vts/OWNERS @@ -0,0 +1,2 @@ +rpius@google.com +etancohen@google.com diff --git a/wifi/supplicant/1.2/vts/functional/Android.bp b/wifi/supplicant/1.2/vts/functional/Android.bp new file mode 100644 index 0000000000..9bd998c4de --- /dev/null +++ b/wifi/supplicant/1.2/vts/functional/Android.bp @@ -0,0 +1,60 @@ +// +// Copyright (C) 2019 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_library_static { + name: "VtsHalWifiSupplicantV1_2TargetTestUtil", + defaults: ["VtsHalTargetTestDefaults"], + srcs: ["supplicant_hidl_test_utils_1_2.cpp"], + export_include_dirs: [ + "." + ], + static_libs: [ + "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiSupplicantV1_0TargetTestUtil", + "VtsHalWifiSupplicantV1_1TargetTestUtil", + "android.hardware.wifi.supplicant@1.0", + "android.hardware.wifi.supplicant@1.1", + "android.hardware.wifi.supplicant@1.2", + "android.hardware.wifi@1.0", + "libcrypto", + "libgmock", + "libwifi-system", + "libwifi-system-iface", + ], +} + +cc_test { + name: "VtsHalWifiSupplicantP2pV1_2TargetTest", + defaults: ["VtsHalTargetTestDefaults"], + srcs: [ + "VtsHalWifiSupplicantV1_2TargetTest.cpp", + "supplicant_p2p_iface_hidl_test.cpp", + ], + static_libs: [ + "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiSupplicantV1_0TargetTestUtil", + "VtsHalWifiSupplicantV1_1TargetTestUtil", + "VtsHalWifiSupplicantV1_2TargetTestUtil", + "android.hardware.wifi.supplicant@1.0", + "android.hardware.wifi.supplicant@1.1", + "android.hardware.wifi.supplicant@1.2", + "android.hardware.wifi@1.0", + "libcrypto", + "libgmock", + "libwifi-system", + "libwifi-system-iface", + ], +} diff --git a/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp b/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp new file mode 100644 index 0000000000..9d0e960435 --- /dev/null +++ b/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2019 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 + +#include +#include + +#include "supplicant_hidl_test_utils.h" +#include "wifi_hidl_test_utils.h" + +class WifiSupplicantHidlEnvironment_1_2 : public WifiSupplicantHidlEnvironment { + public: + // get the test environment singleton + static WifiSupplicantHidlEnvironment_1_2* Instance() { + static WifiSupplicantHidlEnvironment_1_2* instance = + new WifiSupplicantHidlEnvironment_1_2; + return instance; + } + virtual void registerTestServices() override { + registerTestService<::android::hardware::wifi::V1_0::IWifi>(); + registerTestService< + ::android::hardware::wifi::supplicant::V1_0::ISupplicant>(); + registerTestService< + ::android::hardware::wifi::supplicant::V1_1::ISupplicant>(); + registerTestService< + ::android::hardware::wifi::supplicant::V1_2::ISupplicant>(); + } + + private: + WifiSupplicantHidlEnvironment_1_2() {} +}; + +WifiSupplicantHidlEnvironment* gEnv = + WifiSupplicantHidlEnvironment_1_2::Instance(); + +int main(int argc, char** argv) { + ::testing::AddGlobalTestEnvironment(gEnv); + ::testing::InitGoogleTest(&argc, argv); + gEnv->init(&argc, argv); + int status = gEnv->initFromOptions(argc, argv); + if (status == 0) { + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + } + return status; +} diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp new file mode 100644 index 0000000000..5b5d4e9234 --- /dev/null +++ b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 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 +#include + +#include "supplicant_hidl_test_utils.h" +#include "supplicant_hidl_test_utils_1_2.h" + +using ::android::sp; +using ::android::hardware::wifi::supplicant::V1_2::ISupplicantP2pIface; + +sp getSupplicantP2pIface_1_2() { + return ISupplicantP2pIface::castFrom(getSupplicantP2pIface()); +} diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h new file mode 100644 index 0000000000..48be08d7ed --- /dev/null +++ b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2019 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 SUPPLICANT_HIDL_TEST_UTILS_1_2_H +#define SUPPLICANT_HIDL_TEST_UTILS_1_2_H + +#include + +android::sp +getSupplicantP2pIface_1_2(); + +#endif /* SUPPLICANT_HIDL_TEST_UTILS_1_2_H */ diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp new file mode 100644 index 0000000000..46b4087017 --- /dev/null +++ b/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2019 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 + +#include + +#include + +#include "supplicant_hidl_test_utils.h" +#include "supplicant_hidl_test_utils_1_2.h" + +using ::android::sp; +using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; +using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::supplicant::V1_2::ISupplicantP2pIface; + +namespace { +constexpr uint8_t kTestSsid[] = {'D', 'I', 'R', 'E', 'C', 'T', '-', 'x', + 'y', '-', 'H', 'E', 'L', 'L', 'O'}; +constexpr char kTestPassphrase[] = "P2pWorld1234"; +constexpr uint8_t kTestZeroMacAddr[] = {[0 ... 5] = 0x0}; +} // namespace + +class SupplicantP2pIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + startSupplicantAndWaitForHidlService(); + EXPECT_TRUE(turnOnExcessiveLogging()); + p2p_iface_ = getSupplicantP2pIface_1_2(); + ASSERT_NE(p2p_iface_.get(), nullptr); + } + + virtual void TearDown() override { stopSupplicant(); } + + protected: + // ISupplicantP2pIface object used for all tests in this fixture. + sp p2p_iface_; +}; + +/* + * Verify that AddGroup_1_2 could create a group successfully. + */ +TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_Success) { + std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); + std::string passphrase = kTestPassphrase; + int freq = 5; + std::array zero_mac_addr; + memcpy(zero_mac_addr.data(), kTestZeroMacAddr, zero_mac_addr.size()); + bool persistent = false; + int is_join = false; + + p2p_iface_->addGroup_1_2(ssid, passphrase, persistent, freq, zero_mac_addr, + is_join, [](const SupplicantStatus& status) { + EXPECT_EQ(SupplicantStatusCode::SUCCESS, + status.code); + }); +} + +/* + * Verify that AddGroup_1_2 fails due to invalid SSID. + */ +TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidSsid) { + std::vector ssid; + std::string passphrase = kTestPassphrase; + int freq = 5; + std::array zero_mac_addr; + memcpy(zero_mac_addr.data(), kTestZeroMacAddr, zero_mac_addr.size()); + bool persistent = false; + int is_join = false; + + p2p_iface_->addGroup_1_2( + ssid, passphrase, persistent, freq, zero_mac_addr, is_join, + [](const SupplicantStatus& status) { + EXPECT_EQ(SupplicantStatusCode::FAILURE_ARGS_INVALID, status.code); + }); +} + +/* + * Verify that AddGroup_1_2 fails due to invalid passphrase. + */ +TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidPassphrase) { + std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); + std::string passphrase = "1234"; + int freq = 5; + std::array zero_mac_addr; + memcpy(zero_mac_addr.data(), kTestZeroMacAddr, zero_mac_addr.size()); + bool persistent = false; + int is_join = false; + + p2p_iface_->addGroup_1_2( + ssid, passphrase, persistent, freq, zero_mac_addr, is_join, + [](const SupplicantStatus& status) { + EXPECT_EQ(SupplicantStatusCode::FAILURE_ARGS_INVALID, status.code); + }); +} + +/* + * Verify that AddGroup_1_2 fails due to invalid frequency. + */ +TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidFrequency) { + std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); + std::string passphrase = kTestPassphrase; + int freq = 9999; + std::array zero_mac_addr; + memcpy(zero_mac_addr.data(), kTestZeroMacAddr, zero_mac_addr.size()); + bool persistent = false; + int is_join = false; + + p2p_iface_->addGroup_1_2( + ssid, passphrase, persistent, freq, zero_mac_addr, is_join, + [](const SupplicantStatus& status) { + EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code); + }); +}