utils.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Testing utilities
  2. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. def get_ifnames():
  7. ifnames = []
  8. with open("/proc/net/dev", "r") as f:
  9. lines = f.readlines()
  10. for l in lines:
  11. val = l.split(':', 1)
  12. if len(val) == 2:
  13. ifnames.append(val[0].strip(' '))
  14. return ifnames
  15. class HwsimSkip(Exception):
  16. def __init__(self, reason):
  17. self.reason = reason
  18. def __str__(self):
  19. return self.reason
  20. class alloc_fail(object):
  21. def __init__(self, dev, count, funcs):
  22. self._dev = dev
  23. self._count = count
  24. self._funcs = funcs
  25. def __enter__(self):
  26. cmd = "TEST_ALLOC_FAIL %d:%s" % (self._count, self._funcs)
  27. if "OK" not in self._dev.request(cmd):
  28. raise HwsimSkip("TEST_ALLOC_FAIL not supported")
  29. def __exit__(self, type, value, traceback):
  30. if type is None:
  31. if self._dev.request("GET_ALLOC_FAIL") != "0:%s" % self._funcs:
  32. raise Exception("Allocation failure did not trigger")