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