aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ipc-modem.py
blob: b1d28b473c95e37f1fb155ac81ffc531c2d507eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
#
#  This file is part of libsamsung-ipc.
#
#  Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
#  libsamsung-ipc is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  libsamsung-ipc is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.

import os
import re
import sys
import sh

def usage(progname):
    print("{} [test]".format(progname))
    sys.exit(1)

def get_output(data):
    return str(data).replace(os.linesep, "")

class IpcModem(object):
    def __init__(self):
        srcdir = os.environ.get('srcdir', None)
        # Enable also to test without automake
        if not srcdir:
            srcdir = os.path.dirname(sys.argv[0])

        ipc_modem = sh.Command(srcdir + os.sep + "ipc-modem")
        self.ipc_modem = ipc_modem.bake('--dry-run')

    def test_help(self):
        try:
            self.ipc_modem()
        except sh.ErrorReturnCode_1:
            pass
        else:
            raise Exception()

    def test_boot(self, timeout=2):
        self.ipc_modem("boot",  _timeout=timeout)

    def test_power_on(self, timeout=2):
        self.ipc_modem("power-on",  _timeout=timeout)

    def test_power_off(self, timeout=2):
        self.ipc_modem("power-off", _timeout=timeout)

    def test_start(self, timeout=3):
        try:
            self.ipc_modem("start",  _timeout=timeout)
        except sh.TimeoutException:
            pass
        else:
            raise Exception()

    def test_commands(self):
        self.test_boot()
        self.test_power_on()
        self.test_power_off()
        self.test_start()

def main():
    ipc_modem = IpcModem()
    ipc_modem.test_help()
    ipc_modem.test_commands()

if __name__ == '__main__':
    rc = main()
    sys.exit(rc)