[Replicant] [libsamsung-ipc] [PATCH 1/2] tools: nv_data-md5: Add tests

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Tue Dec 1 15:40:26 UTC 2020


Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 tools/Makefile.am    |  5 ++--
 tools/nv_data-md5.py | 70 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100755 tools/nv_data-md5.py

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 at 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)
-- 
2.29.2



More information about the Replicant mailing list