ping.py 737 B

1234567891011121314151617181920212223242526
  1. #
  2. # SPDX-License-Identifier: MIT
  3. #
  4. from subprocess import Popen, PIPE
  5. from oeqa.runtime.case import OERuntimeTestCase
  6. from oeqa.core.decorator.oetimeout import OETimeout
  7. class PingTest(OERuntimeTestCase):
  8. @OETimeout(30)
  9. def test_ping(self):
  10. output = ''
  11. count = 0
  12. while count < 5:
  13. cmd = 'ping -c 1 %s' % self.target.ip
  14. proc = Popen(cmd, shell=True, stdout=PIPE)
  15. output += proc.communicate()[0].decode('utf-8')
  16. if proc.poll() == 0:
  17. count += 1
  18. else:
  19. count = 0
  20. msg = ('Expected 5 consecutive, got %d.\n'
  21. 'ping output is:\n%s' % (count,output))
  22. self.assertEqual(count, 5, msg = msg)