Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | from subprocess import Popen, PIPE |
| 8 | |
| 9 | from oeqa.runtime.case import OERuntimeTestCase |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | from oeqa.core.decorator.oetimeout import OETimeout |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 11 | from oeqa.core.exception import OEQATimeoutError |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | |
| 13 | class PingTest(OERuntimeTestCase): |
| 14 | |
| 15 | @OETimeout(30) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | def test_ping(self): |
| 17 | output = '' |
| 18 | count = 0 |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 19 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | msg = ('Expected 5 consecutive, got %d.\n' |
| 31 | 'ping output is:\n%s' % (count,output)) |
| 32 | self.assertEqual(count, 5, msg = msg) |