ping.py 701 B

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