blob: 79d3440f8c23d2b96e6295d06d3e01f8bf03e85c [file] [log] [blame]
Maciej Żenczykowskib70da762019-01-28 15:20:48 -08001/*
2 * Copyright 2019 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 * ClatUtilsTest.cpp - unit tests for ClatUtils.cpp
17 */
18
19#include <gtest/gtest.h>
20
21#include "ClatUtils.h"
22
Maciej Żenczykowski0a7dce82019-01-28 15:31:55 -080023#include <linux/if_arp.h>
24
Maciej Żenczykowskib70da762019-01-28 15:20:48 -080025namespace android {
26namespace net {
27
28class ClatUtilsTest : public ::testing::Test {
29 public:
30 void SetUp() {}
31};
32
Maciej Żenczykowski0a7dce82019-01-28 15:31:55 -080033TEST_F(ClatUtilsTest, HardwareAddressTypeOfNonExistingIf) {
34 EXPECT_EQ(-ENODEV, hardwareAddressType("not_existing_if"));
35}
36
37TEST_F(ClatUtilsTest, HardwareAddressTypeOfLoopback) {
38 EXPECT_EQ(ARPHRD_LOOPBACK, hardwareAddressType("lo"));
39}
40
41// If wireless 'wlan0' interface exists it should be Ethernet.
42TEST_F(ClatUtilsTest, HardwareAddressTypeOfWireless) {
43 int type = hardwareAddressType("wlan0");
44 if (type == -ENODEV) return;
45
46 EXPECT_EQ(ARPHRD_ETHER, type);
47}
48
49// If cellular 'rmnet_data0' interface exists it should
50// *probably* not be Ethernet and instead be RawIp.
51TEST_F(ClatUtilsTest, HardwareAddressTypeOfCellular) {
52 int type = hardwareAddressType("rmnet_data0");
53 if (type == -ENODEV) return;
54
55 EXPECT_NE(ARPHRD_ETHER, type);
56
57 // ARPHRD_RAWIP is 530 on some pre-4.14 Qualcomm devices.
58 if (type == 530) return;
59
60 EXPECT_EQ(ARPHRD_RAWIP, type);
61}
62
Maciej Żenczykowskib70da762019-01-28 15:20:48 -080063} // namespace net
64} // namespace android