test_wmediumd.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # wmediumd sanity checks
  2. # Copyright (c) 2015, Intel Deutschland GmbH
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import tempfile, os, subprocess, errno
  7. from utils import HwsimSkip
  8. from test_ap_open import _test_ap_open
  9. CFG = """
  10. ifaces :
  11. {
  12. ids = ["%s", "%s" ];
  13. links = (
  14. (0, 1, 30)
  15. );
  16. };
  17. """
  18. def output_wmediumd_log(p, params, data):
  19. log_file = open(os.path.abspath(os.path.join(params['logdir'],
  20. 'wmediumd.log')), 'a')
  21. log_file.write(data)
  22. log_file.close()
  23. def start_wmediumd(fn, params):
  24. try:
  25. p = subprocess.Popen(['wmediumd', '-c', fn],
  26. stdout=subprocess.PIPE,
  27. stderr=subprocess.STDOUT)
  28. except OSError, e:
  29. if e.errno == errno.ENOENT:
  30. raise HwsimSkip('wmediumd not available')
  31. raise
  32. logs = ''
  33. while True:
  34. line = p.stdout.readline()
  35. if not line:
  36. output_wmediumd_log(p, params, logs)
  37. raise Exception('wmediumd was terminated unexpectedly')
  38. if line.find('REGISTER SENT!') > -1:
  39. break
  40. logs += line
  41. return p
  42. def stop_wmediumd(p, params):
  43. p.terminate()
  44. p.wait()
  45. stdoutdata, stderrdata = p.communicate()
  46. output_wmediumd_log(p, params, stdoutdata)
  47. def test_wmediumd_simple(dev, apdev, params):
  48. """test a simple wmediumd configuration"""
  49. fd, fn = tempfile.mkstemp()
  50. try:
  51. f = os.fdopen(fd, 'w')
  52. f.write(CFG % (apdev[0]['bssid'], dev[0].own_addr()))
  53. f.close()
  54. p = start_wmediumd(fn, params)
  55. try:
  56. _test_ap_open(dev, apdev)
  57. finally:
  58. stop_wmediumd(p, params)
  59. # test that releasing hwsim works correctly
  60. _test_ap_open(dev, apdev)
  61. finally:
  62. os.unlink(fn)