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