blob: f72460e7f3f8a45bb46e855bfef926e6bd314c5e [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
Patrick Williams8e7b46e2023-05-01 14:19:06 -05008from time import sleep
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009
10from oeqa.runtime.case import OERuntimeTestCase
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011from oeqa.core.decorator.oetimeout import OETimeout
Andrew Geissler9aee5002022-03-30 16:27:02 +000012from oeqa.core.exception import OEQATimeoutError
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013
14class PingTest(OERuntimeTestCase):
15
16 @OETimeout(30)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017 def test_ping(self):
18 output = ''
19 count = 0
Patrick Williams8e7b46e2023-05-01 14:19:06 -050020 self.assertNotEqual(len(self.target.ip), 0, msg="No target IP address set")
Andrew Geissler9aee5002022-03-30 16:27:02 +000021 try:
22 while count < 5:
23 cmd = 'ping -c 1 %s' % self.target.ip
24 proc = Popen(cmd, shell=True, stdout=PIPE)
25 output += proc.communicate()[0].decode('utf-8')
26 if proc.poll() == 0:
27 count += 1
28 else:
29 count = 0
Patrick Williams8e7b46e2023-05-01 14:19:06 -050030 sleep(1)
Andrew Geissler9aee5002022-03-30 16:27:02 +000031 except OEQATimeoutError:
32 self.fail("Ping timeout error for address %s, count %s, output: %s" % (self.target.ip, count, output))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 msg = ('Expected 5 consecutive, got %d.\n'
34 'ping output is:\n%s' % (count,output))
35 self.assertEqual(count, 5, msg = msg)