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