1# Copyright (c) 2013 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
7from autotest_lib.client.bin import test
8from autotest_lib.client.bin import utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.common_lib.cros.network import interface
11
12
13class network_WlanDriver(test.test):
14    """
15    Ensure wireless devices have the expected associated kernel driver.
16    """
17    version = 1
18    DEVICES = [ 'wlan0', 'mlan0' ]
19    EXPECTED_DRIVER = {
20            'Atheros AR9280': {
21                    '3.4': 'wireless/ath/ath9k/ath9k.ko',
22                    '3.8': 'wireless-3.4/ath/ath9k/ath9k.ko'
23            },
24            'Atheros AR9382': {
25                    '3.4': 'wireless/ath/ath9k/ath9k.ko',
26                    '3.8': 'wireless-3.4/ath/ath9k/ath9k.ko'
27            },
28            'Intel 7260': {
29                    '3.8': 'wireless/iwl7000/iwlwifi/iwlwifi.ko',
30                    '3.10': 'wireless-3.8/iwl7000/iwlwifi/iwlwifi.ko',
31                    '3.14': 'wireless-3.8/iwl7000/iwlwifi/iwlwifi.ko',
32                    '4.4': 'wireless/iwl7000/iwlwifi/iwlwifi.ko'
33            },
34            'Intel 7265': {
35                    '3.8': 'wireless/iwl7000/iwlwifi/iwlwifi.ko',
36                    '3.10': 'wireless-3.8/iwl7000/iwlwifi/iwlwifi.ko',
37                    '3.14': 'wireless-3.8/iwl7000/iwlwifi/iwlwifi.ko',
38                    '3.18': 'wireless/iwl7000/iwlwifi/iwlwifi.ko'
39            },
40            'Atheros AR9462': {
41                    '3.4': 'wireless/ath/ath9k_btcoex/ath9k_btcoex.ko',
42                    '3.8': 'wireless-3.4/ath/ath9k_btcoex/ath9k_btcoex.ko'
43            },
44            'Qualcomm Atheros QCA6174': {
45                    '3.18': 'wireless/ar10k/ath/ath10k/ath10k_core.ko',
46                    '3.18': 'wireless/ar10k/ath/ath10k/ath10k_pci.ko'
47            },
48            'Qualcomm Atheros NFA344A/QCA6174': {
49                    '3.18': 'wireless/ar10k/ath/ath10k/ath10k_core.ko',
50                    '3.18': 'wireless/ar10k/ath/ath10k/ath10k_pci.ko'
51            },
52            'Marvell 88W8797 SDIO': {
53                    '3.4': 'wireless/mwifiex/mwifiex_sdio.ko',
54                    '3.8': 'wireless-3.4/mwifiex/mwifiex_sdio.ko'
55            },
56            'Marvell 88W8887 SDIO': {
57                     '3.14': 'wireless-3.8/mwifiex/mwifiex_sdio.ko'
58            },
59            'Marvell 88W8897 PCIE': {
60                     '3.8': 'wireless/mwifiex/mwifiex_pcie.ko',
61                     '3.10': 'wireless-3.8/mwifiex/mwifiex_pcie.ko'
62            },
63            'Marvell 88W8897 SDIO': {
64                     '3.8': 'wireless/mwifiex/mwifiex_sdio.ko',
65                     '3.10': 'wireless-3.8/mwifiex/mwifiex_sdio.ko',
66                     '3.14': 'wireless-3.8/mwifiex/mwifiex_sdio.ko',
67                     '3.18': 'wireless/mwifiex/mwifiex_sdio.ko'
68            },
69            'Broadcom BCM4354 SDIO': {
70                     '3.8': 'wireless/brcm80211/brcmfmac/brcmfmac.ko',
71                     '3.14': 'wireless-3.8/brcm80211/brcmfmac/brcmfmac.ko'
72            },
73            'Broadcom BCM4356 PCIE': {
74                     '3.10': 'wireless-3.8/brcm80211/brcmfmac/brcmfmac.ko'
75            },
76            'Marvell 88W8997 PCIE': {
77                     '4.4': 'wireless/marvell/mwifiex/mwifiex_pcie.ko',
78            },
79    }
80
81
82    def run_once(self):
83        """Test main loop"""
84        # full_revision looks like "3.4.0".
85        full_revision = utils.system_output('uname -r')
86        # base_revision looks like "3.4".
87        base_revision = '.'.join(full_revision.split('.')[:2])
88        logging.info('Kernel base is %s', base_revision)
89
90        found_devices = 0
91        for device in self.DEVICES:
92            net_if = interface.Interface(device)
93            device_description = net_if.device_description
94
95            if not device_description:
96                continue
97
98            device_name, module_path = device_description
99            logging.info('Device name %s, module path %s',
100                         device_name, module_path)
101            if not device_name in self.EXPECTED_DRIVER:
102                raise error.TestFail('Unexpected device name %s' %
103                                     device_name)
104
105            if not base_revision in self.EXPECTED_DRIVER[device_name]:
106                raise error.TestNAError('Unexpected base kernel revision %s '
107                                        'with device name %s' %
108                                        (base_revision, device_name))
109
110            expected_driver = self.EXPECTED_DRIVER[device_name][base_revision]
111            if module_path != expected_driver:
112                raise error.TestFail('Unexpected driver for %s/%s; '
113                                     'got %s but expected %s' %
114                                     (base_revision, device_name,
115                                      module_path, expected_driver))
116            found_devices += 1
117        if not found_devices:
118            raise error.TestNAError('Found no recognized wireless devices?')
119