blob: 967b44175f071dd39259b2216c8accb00ab59a8e [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007from subprocess import Popen, PIPE
8
9from oeqa.runtime.case import OERuntimeTestCase
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010from oeqa.core.decorator.oetimeout import OETimeout
Andrew Geissler9aee5002022-03-30 16:27:02 +000011from oeqa.core.exception import OEQATimeoutError
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012
13class PingTest(OERuntimeTestCase):
14
15 @OETimeout(30)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 def test_ping(self):
17 output = ''
18 count = 0
Andrew Geissler9aee5002022-03-30 16:27:02 +000019 try:
20 while count < 5:
21 cmd = 'ping -c 1 %s' % self.target.ip
22 proc = Popen(cmd, shell=True, stdout=PIPE)
23 output += proc.communicate()[0].decode('utf-8')
24 if proc.poll() == 0:
25 count += 1
26 else:
27 count = 0
28 except OEQATimeoutError:
29 self.fail("Ping timeout error for address %s, count %s, output: %s" % (self.target.ip, count, output))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 msg = ('Expected 5 consecutive, got %d.\n'
31 'ping output is:\n%s' % (count,output))
32 self.assertEqual(count, 5, msg = msg)