From 7ee1273120791fd6f4ad690c0913223bd3c980a9 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Tue, 31 Aug 2021 23:11:27 +0200 Subject: tools: ipc-modem: Add tests While the tests don't talk to a real modem, they are still useful to detect regressions with the use of threads. Signed-off-by: Denis 'GNUtoo' Carikli --- .gitignore | 2 ++ tools/Makefile.am | 5 ++-- tools/ipc-modem.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100755 tools/ipc-modem.py diff --git a/.gitignore b/.gitignore index d901273..5ff2f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ /samsung-ipc/tests/libsamsung-ipc-test.trs /samsung-ipc/tests/test-suite.log /test-driver +/tools/ipc-modem.log +/tools/ipc-modem.trs /tools/nv_data-imei.log /tools/nv_data-imei.trs /tools/nv_data-md5.log diff --git a/tools/Makefile.am b/tools/Makefile.am index 4d5fa8b..41e5441 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -15,12 +15,13 @@ bin_PROGRAMS = \ # nv_data-imei in TEST while having it implemented in a single python file PY_LOG_COMPILER = $(PYTHON) TEST_EXTENSIONS = .py -TESTS = nv_data-imei.py \ +TESTS = ipc-modem.py \ + nv_data-imei.py \ nv_data-md5.py ipc_modem_SOURCES = ipc-modem.c ipc_modem_LDADD = $(top_builddir)/samsung-ipc/libsamsung-ipc.la -ipc_modem_LDFLAGS = +ipc_modem_LDFLAGS = -lpthread ipc_test_SOURCES = ipc-test.c ipc_test_LDADD = $(top_builddir)/samsung-ipc/libsamsung-ipc.la diff --git a/tools/ipc-modem.py b/tools/ipc-modem.py new file mode 100755 index 0000000..b1d28b4 --- /dev/null +++ b/tools/ipc-modem.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# +# This file is part of libsamsung-ipc. +# +# Copyright (C) 2020 Denis 'GNUtoo' Carikli +# +# 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 . + +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) -- cgit v1.2.3