tests: Allow hwsim_test and wlantest_cli to be used from PATH

This makes it easier to support some test environments where the
repository is shared between hosts.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-05-11 11:34:49 +03:00
parent 4ee18c9207
commit 280cd8a9a2
2 changed files with 24 additions and 13 deletions

View File

@ -6,13 +6,18 @@
# This software may be distributed under the terms of the BSD license. # This software may be distributed under the terms of the BSD license.
# See README for more details. # See README for more details.
import os
import subprocess import subprocess
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def test_connectivity(ifname1, ifname2): def test_connectivity(ifname1, ifname2):
if os.path.isfile("../../mac80211_hwsim/tools/hwsim_test"):
hwsim_test = "../../mac80211_hwsim/tools/hwsim_test"
else:
hwsim_test = "hwsim_test"
cmd = ["sudo", cmd = ["sudo",
"../../mac80211_hwsim/tools/hwsim_test", hwsim_test,
ifname1, ifname1,
ifname2] ifname2]
try: try:

View File

@ -13,52 +13,58 @@ import logging
import wpaspy import wpaspy
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
wlantest_cli = '../../wlantest/wlantest_cli'
class Wlantest: class Wlantest:
def __init__(self):
if os.path.isfile('../../wlantest/wlantest_cli'):
self.wlantest_cli = '../../wlantest/wlantest_cli'
else:
self.wlantest_cli = 'wlantest_cli'
def flush(self): def flush(self):
res = subprocess.check_output([wlantest_cli, "flush"]) res = subprocess.check_output([self.wlantest_cli, "flush"])
if "FAIL" in res: if "FAIL" in res:
raise Exception("wlantest_cli flush failed") raise Exception("wlantest_cli flush failed")
def add_passphrase(self, passphrase): def add_passphrase(self, passphrase):
res = subprocess.check_output([wlantest_cli, "add_passphrase", res = subprocess.check_output([self.wlantest_cli, "add_passphrase",
passphrase]) passphrase])
if "FAIL" in res: if "FAIL" in res:
raise Exception("wlantest_cli add_passphrase failed") raise Exception("wlantest_cli add_passphrase failed")
def add_wepkey(self, key): def add_wepkey(self, key):
res = subprocess.check_output([wlantest_cli, "add_wepkey", key]) res = subprocess.check_output([self.wlantest_cli, "add_wepkey", key])
if "FAIL" in res: if "FAIL" in res:
raise Exception("wlantest_cli add_key failed") raise Exception("wlantest_cli add_key failed")
def info_bss(self, field, bssid): def info_bss(self, field, bssid):
res = subprocess.check_output([wlantest_cli, "info_bss", field, bssid]) res = subprocess.check_output([self.wlantest_cli, "info_bss",
field, bssid])
if "FAIL" in res: if "FAIL" in res:
raise Exception("Could not get BSS info from wlantest for " + bssid) raise Exception("Could not get BSS info from wlantest for " + bssid)
return res return res
def info_sta(self, field, bssid, addr): def info_sta(self, field, bssid, addr):
res = subprocess.check_output([wlantest_cli, "info_sta", field, bssid, res = subprocess.check_output([self.wlantest_cli, "info_sta",
addr]) field, bssid, addr])
if "FAIL" in res: if "FAIL" in res:
raise Exception("Could not get STA info from wlantest for " + addr) raise Exception("Could not get STA info from wlantest for " + addr)
return res return res
def get_sta_counter(self, field, bssid, addr): def get_sta_counter(self, field, bssid, addr):
res = subprocess.check_output([wlantest_cli, "get_sta_counter", field, res = subprocess.check_output([self.wlantest_cli, "get_sta_counter",
bssid, addr]); field, bssid, addr]);
if "FAIL" in res: if "FAIL" in res:
raise Exception("wlantest_cli command failed") raise Exception("wlantest_cli command failed")
return int(res) return int(res)
def tdls_clear(self, bssid, addr1, addr2): def tdls_clear(self, bssid, addr1, addr2):
subprocess.call([wlantest_cli, "clear_tdls_counters", bssid, addr1, subprocess.call([self.wlantest_cli, "clear_tdls_counters", bssid, addr1,
addr2]); addr2]);
def get_tdls_counter(self, field, bssid, addr1, addr2): def get_tdls_counter(self, field, bssid, addr1, addr2):
res = subprocess.check_output([wlantest_cli, "get_tdls_counter", field, res = subprocess.check_output([self.wlantest_cli, "get_tdls_counter",
bssid, addr1, addr2]); field, bssid, addr1, addr2]);
if "FAIL" in res: if "FAIL" in res:
raise Exception("wlantest_cli command failed") raise Exception("wlantest_cli command failed")
return int(res) return int(res)