2013-03-02 11:22:28 +01:00
|
|
|
# hwsim testing utilities
|
2014-03-15 09:42:46 +01:00
|
|
|
# Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
|
2013-03-02 11:22:28 +01:00
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
2013-05-11 10:34:49 +02:00
|
|
|
import os
|
2013-03-02 11:22:28 +01:00
|
|
|
import subprocess
|
2014-03-15 09:42:46 +01:00
|
|
|
import time
|
2013-03-02 11:22:28 +01:00
|
|
|
import logging
|
2013-10-31 11:46:42 +01:00
|
|
|
logger = logging.getLogger()
|
2013-03-02 11:22:28 +01:00
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
def test_connectivity_run(ifname1, ifname2, dscp=None, tos=None, max_tries=1):
|
2013-05-11 10:34:49 +02:00
|
|
|
if os.path.isfile("../../mac80211_hwsim/tools/hwsim_test"):
|
|
|
|
hwsim_test = "../../mac80211_hwsim/tools/hwsim_test"
|
|
|
|
else:
|
|
|
|
hwsim_test = "hwsim_test"
|
2013-03-02 11:22:28 +01:00
|
|
|
cmd = ["sudo",
|
2013-05-11 10:34:49 +02:00
|
|
|
hwsim_test,
|
2013-03-02 11:22:28 +01:00
|
|
|
ifname1,
|
|
|
|
ifname2]
|
2013-12-24 19:21:58 +01:00
|
|
|
if dscp:
|
|
|
|
cmd.append('-D')
|
|
|
|
cmd.append(str(dscp))
|
|
|
|
elif tos:
|
|
|
|
cmd.append('-t')
|
|
|
|
cmd.append(str(tos))
|
2014-03-15 09:42:46 +01:00
|
|
|
success = False
|
|
|
|
for i in range(0, max_tries):
|
|
|
|
try:
|
|
|
|
s = subprocess.check_output(cmd)
|
|
|
|
logger.debug(s)
|
|
|
|
success = True
|
|
|
|
break
|
|
|
|
except subprocess.CalledProcessError, e:
|
|
|
|
logger.info("hwsim failed: " + str(e.returncode))
|
|
|
|
logger.info(e.output)
|
|
|
|
if i + 1 < max_tries:
|
|
|
|
time.sleep(1)
|
|
|
|
if not success:
|
|
|
|
raise Exception("hwsim_test failed")
|
2013-03-02 11:22:28 +01:00
|
|
|
|
2014-10-19 16:54:49 +02:00
|
|
|
def test_connectivity(dev1, dev2, dscp=None, tos=None, max_tries=1):
|
|
|
|
test_connectivity_run(dev1.ifname, dev2.ifname, dscp=dscp, tos=tos,
|
|
|
|
max_tries=max_tries)
|
|
|
|
|
|
|
|
def test_connectivity_iface(dev1, ifname, dscp=None, tos=None, max_tries=1):
|
|
|
|
test_connectivity_run(dev1.ifname, ifname, dscp=dscp, tos=tos,
|
|
|
|
max_tries=max_tries)
|
|
|
|
|
2013-12-24 19:21:58 +01:00
|
|
|
def test_connectivity_p2p(dev1, dev2, dscp=None, tos=None):
|
2013-03-09 16:34:08 +01:00
|
|
|
ifname1 = dev1.group_ifname if dev1.group_ifname else dev1.ifname
|
|
|
|
ifname2 = dev2.group_ifname if dev2.group_ifname else dev2.ifname
|
2014-10-19 16:54:49 +02:00
|
|
|
test_connectivity_run(ifname1, ifname2, dscp, tos)
|
2013-03-27 12:57:48 +01:00
|
|
|
|
2013-12-24 19:21:58 +01:00
|
|
|
def test_connectivity_p2p_sta(dev1, dev2, dscp=None, tos=None):
|
2013-09-01 10:56:55 +02:00
|
|
|
ifname1 = dev1.group_ifname if dev1.group_ifname else dev1.ifname
|
|
|
|
ifname2 = dev2.ifname
|
2014-10-19 16:54:49 +02:00
|
|
|
test_connectivity_run(ifname1, ifname2, dscp, tos)
|
2013-09-01 10:56:55 +02:00
|
|
|
|
2013-12-24 19:21:58 +01:00
|
|
|
def test_connectivity_sta(dev1, dev2, dscp=None, tos=None):
|
2013-03-27 12:57:48 +01:00
|
|
|
ifname1 = dev1.ifname
|
|
|
|
ifname2 = dev2.ifname
|
2014-10-19 16:54:49 +02:00
|
|
|
test_connectivity_run(ifname1, ifname2, dscp, tos)
|