1/* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "netd_hidl_test" 18 19#include <VtsHalHidlTargetTestBase.h> 20#include <android/system/net/netd/1.0/INetd.h> 21#include <log/log.h> 22 23using ::android::system::net::netd::V1_0::INetd; 24using ::android::hardware::Return; 25using ::android::sp; 26 27class NetdHidlTest : public ::testing::VtsHalHidlTargetTestBase { 28 public: 29 virtual void SetUp() override { 30 netd = ::testing::VtsHalHidlTargetTestBase::getService<INetd>(); 31 ASSERT_NE(nullptr, netd.get()) << "Could not get HIDL instance"; 32 } 33 34 sp<INetd> netd; 35}; 36 37// positive test. Ensure netd creates an oem network and returns valid netHandle, and destroys it. 38TEST_F(NetdHidlTest, TestCreateAndDestroyOemNetworkOk) { 39 auto cb = [this](uint64_t netHandle, uint32_t packetMark, INetd::StatusCode status) { 40 ASSERT_EQ(INetd::StatusCode::OK, status); 41 ASSERT_NE((uint64_t)0, netHandle); 42 ASSERT_NE((uint32_t)0, packetMark); 43 44 Return<INetd::StatusCode> retStatus = netd->destroyOemNetwork(netHandle); 45 ASSERT_EQ(INetd::StatusCode::OK, retStatus); 46 }; 47 48 Return<void> ret = netd->createOemNetwork(cb); 49 ASSERT_TRUE(ret.isOk()); 50} 51 52// negative test. Ensure destroy for invalid OEM network fails appropriately 53TEST_F(NetdHidlTest, TestDestroyOemNetworkInvalid) { 54 const uint64_t nh = 0x6600FACADE; 55 56 Return<INetd::StatusCode> retStatus = netd->destroyOemNetwork(nh); 57 ASSERT_EQ(INetd::StatusCode::INVALID_ARGUMENTS, retStatus); 58} 59 60int main(int argc, char** argv) { 61 ::testing::InitGoogleTest(&argc, argv); 62 int status = RUN_ALL_TESTS(); 63 ALOGE("Test result with status=%d", status); 64 return status; 65} 66