blob: 498f80d0a5083627d3e59cd365d5478ae6865322 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005from subprocess import Popen, PIPE
6
7from oeqa.runtime.case import OERuntimeTestCase
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008from oeqa.core.decorator.oetimeout import OETimeout
Andrew Geissler9aee5002022-03-30 16:27:02 +00009from oeqa.core.exception import OEQATimeoutError
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010
11class PingTest(OERuntimeTestCase):
12
13 @OETimeout(30)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014 def test_ping(self):
15 output = ''
16 count = 0
Andrew Geissler9aee5002022-03-30 16:27:02 +000017 try:
18 while count < 5:
19 cmd = 'ping -c 1 %s' % self.target.ip
20 proc = Popen(cmd, shell=True, stdout=PIPE)
21 output += proc.communicate()[0].decode('utf-8')
22 if proc.poll() == 0:
23 count += 1
24 else:
25 count = 0
26 except OEQATimeoutError:
27 self.fail("Ping timeout error for address %s, count %s, output: %s" % (self.target.ip, count, output))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 msg = ('Expected 5 consecutive, got %d.\n'
29 'ping output is:\n%s' % (count,output))
30 self.assertEqual(count, 5, msg = msg)