xref: /aosp_15_r20/kernel/tests/net/test/netlink_test.py (revision 2f2c4c7ab4226c71756b9c31670392fdd6887c4f)
1*2f2c4c7aSAndroid Build Coastguard Worker#!/usr/bin/python3
2*2f2c4c7aSAndroid Build Coastguard Worker#
3*2f2c4c7aSAndroid Build Coastguard Worker# Copyright 2022 The Android Open Source Project
4*2f2c4c7aSAndroid Build Coastguard Worker#
5*2f2c4c7aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*2f2c4c7aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*2f2c4c7aSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*2f2c4c7aSAndroid Build Coastguard Worker#
9*2f2c4c7aSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0
10*2f2c4c7aSAndroid Build Coastguard Worker#
11*2f2c4c7aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*2f2c4c7aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*2f2c4c7aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*2f2c4c7aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*2f2c4c7aSAndroid Build Coastguard Worker# limitations under the License.
16*2f2c4c7aSAndroid Build Coastguard Worker
17*2f2c4c7aSAndroid Build Coastguard Workerimport unittest
18*2f2c4c7aSAndroid Build Coastguard Worker
19*2f2c4c7aSAndroid Build Coastguard Workerimport iproute
20*2f2c4c7aSAndroid Build Coastguard Workerimport netlink
21*2f2c4c7aSAndroid Build Coastguard Workerimport sock_diag
22*2f2c4c7aSAndroid Build Coastguard Workerimport tcp_metrics
23*2f2c4c7aSAndroid Build Coastguard Worker
24*2f2c4c7aSAndroid Build Coastguard Worker
25*2f2c4c7aSAndroid Build Coastguard Workerclass NetlinkTest(unittest.TestCase):
26*2f2c4c7aSAndroid Build Coastguard Worker
27*2f2c4c7aSAndroid Build Coastguard Worker  def _CheckConstant(self, expected, module, value, prefix):
28*2f2c4c7aSAndroid Build Coastguard Worker    self.assertEqual(
29*2f2c4c7aSAndroid Build Coastguard Worker        expected,
30*2f2c4c7aSAndroid Build Coastguard Worker        netlink.NetlinkSocket._GetConstantName(module.__name__, value, prefix))
31*2f2c4c7aSAndroid Build Coastguard Worker
32*2f2c4c7aSAndroid Build Coastguard Worker  def testGetConstantName(self):
33*2f2c4c7aSAndroid Build Coastguard Worker    self._CheckConstant("INET_DIAG_INFO", sock_diag, 2, "INET_DIAG_")
34*2f2c4c7aSAndroid Build Coastguard Worker    self._CheckConstant("INET_DIAG_BC_S_GE", sock_diag, 2, "INET_DIAG_BC_")
35*2f2c4c7aSAndroid Build Coastguard Worker    self._CheckConstant("IFA_ADDRESS", iproute, 1, "IFA_")
36*2f2c4c7aSAndroid Build Coastguard Worker    self._CheckConstant("IFA_F_SECONDARY", iproute, 1, "IFA_F_")
37*2f2c4c7aSAndroid Build Coastguard Worker    self._CheckConstant("TCP_METRICS_ATTR_AGE", tcp_metrics, 3,
38*2f2c4c7aSAndroid Build Coastguard Worker                        "TCP_METRICS_ATTR_")
39*2f2c4c7aSAndroid Build Coastguard Worker
40*2f2c4c7aSAndroid Build Coastguard Worker
41*2f2c4c7aSAndroid Build Coastguard Workerif __name__ == "__main__":
42*2f2c4c7aSAndroid Build Coastguard Worker  unittest.main()
43