1#
2# SPDX-License-Identifier: MIT
3#
4
5from subprocess import Popen, PIPE
6import time
7
8from oeqa.runtime.case import OERuntimeTestCase
9from oeqa.core.decorator.depends import OETestDepends
10from oeqa.core.decorator.oetimeout import OETimeout
11from oeqa.core.decorator.data import skipIfQemu
12
13class BootTest(OERuntimeTestCase):
14
15    @OETimeout(120)
16    @skipIfQemu()
17    @OETestDepends(['ssh.SSHTest.test_ssh'])
18    def test_reboot(self):
19        output = ''
20        count = 0
21        (status, output) = self.target.run('reboot -h')
22        while count < 5:
23            time.sleep(5)
24            cmd = 'ping -c 1 %s' % self.target.ip
25            proc = Popen(cmd, shell=True, stdout=PIPE)
26            output += proc.communicate()[0].decode('utf-8')
27            if proc.poll() == 0:
28                count += 1
29            else:
30                count = 0
31        msg = ('Expected 5 consecutive, got %d.\n'
32               'ping output is:\n%s' % (count,output))
33        self.assertEqual(count, 5, msg = msg)
34