aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-12-01 16:27:18 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-12-03 01:42:29 +0100
commit01491b14fd20917990d401ac21df2d861bb307d7 (patch)
treef18a87e2366a6173e64bb429c133cd2024e4afd4
parentecbc4b48f9e94f2cffbf36b9d3b73a46c1d45422 (diff)
downloadhardware_replicant_libsamsung-ipc-01491b14fd20917990d401ac21df2d861bb307d7.tar.gz
hardware_replicant_libsamsung-ipc-01491b14fd20917990d401ac21df2d861bb307d7.tar.bz2
hardware_replicant_libsamsung-ipc-01491b14fd20917990d401ac21df2d861bb307d7.zip
tools: nv_data-md5: Add tests
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tools/Makefile.am5
-rwxr-xr-xtools/nv_data-md5.py70
2 files changed, 73 insertions, 2 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 38580eb..4d5fa8b 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -13,9 +13,10 @@ bin_PROGRAMS = \
# TODO: Find a way to make test more modular and represent each run of the
# nv_data-imei in TEST while having it implemented in a single python file
-TESTS = nv_data-imei.py
-TEST_EXTENSIONS = .py
PY_LOG_COMPILER = $(PYTHON)
+TEST_EXTENSIONS = .py
+TESTS = nv_data-imei.py \
+ nv_data-md5.py
ipc_modem_SOURCES = ipc-modem.c
ipc_modem_LDADD = $(top_builddir)/samsung-ipc/libsamsung-ipc.la
diff --git a/tools/nv_data-md5.py b/tools/nv_data-md5.py
new file mode 100755
index 0000000..2897f18
--- /dev/null
+++ b/tools/nv_data-md5.py
@@ -0,0 +1,70 @@
+#!/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 NvDataMD5(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])
+
+ self.nv_data_md5 = sh.Command(srcdir + os.sep + "nv_data-md5")
+ def test_help(self):
+ try:
+ self.nv_data_md5()
+ except sh.ErrorReturnCode_1:
+ pass
+ else:
+ raise Exception()
+
+ def test_commands(self):
+ expected_md5 = "5293814414abb3831e3fc1a1b35e69bc"
+ NV_DATA_SIZE = 0x200000
+ nv_data_bin = get_output(sh.mktemp())
+
+ # Create nv_data.bin
+ sh.ddrescue("/dev/zero", nv_data_bin, "-s", str(NV_DATA_SIZE))
+
+ output = get_output(self.nv_data_md5(nv_data_bin))
+
+ print(output)
+
+ if output != expected_md5:
+ raise Exception()
+
+def main():
+ nv_data_md5 = NvDataMD5()
+ nv_data_md5.test_help()
+ nv_data_md5.test_commands()
+
+if __name__ == '__main__':
+ rc = main()
+ sys.exit(rc)