From: "Bob Feng" <bob.c.feng@intel.com>
To: devel@edk2.groups.io
Cc: Liming Gao <gaoliming@byosoft.com.cn>, Yuwei Chen <yuwei.chen@intel.com>
Subject: [Patch 2/2] BaseTools: Add unittest for Split tool
Date: Wed, 13 Jan 2021 17:56:09 +0800 [thread overview]
Message-ID: <20210113095609.1398-3-bob.c.feng@intel.com> (raw)
In-Reply-To: <20210113095609.1398-1-bob.c.feng@intel.com>
This patch is to add the unit test for Split python tool
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
---
BaseTools/Source/Python/tests/test_split.py | 101 ++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 BaseTools/Source/Python/tests/test_split.py
diff --git a/BaseTools/Source/Python/tests/test_split.py b/BaseTools/Source/Python/tests/test_split.py
new file mode 100644
index 000000000000..0d44946d7010
--- /dev/null
+++ b/BaseTools/Source/Python/tests/test_split.py
@@ -0,0 +1,101 @@
+import unittest
+import tempfile
+import os
+import shutil
+import Split.Split as sp
+import struct as st
+
+
+class TestSplit(unittest.TestCase):
+ def setUp(self):
+ self.WORKSPACE = tempfile.mkdtemp()
+ self.binary_file = os.path.join(self.WORKSPACE, "Binary.bin")
+ self.create_inputfile()
+
+ def tearDown(self):
+ if os.path.exists(self.WORKSPACE):
+ shutil.rmtree(self.WORKSPACE)
+
+ def test_splitFile_position(self):
+ position = [-1, 0, 256, 512, 700, 1024, 2048]
+ result = [(0, 1024), (0, 1024), (256, 768),
+ (512, 512), (700, 324), (1024, 0), (1024, 0)]
+ for index, po in enumerate(position):
+ try:
+ sp.splitFile(self.binary_file, po)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+
+ output1 = os.path.join(self.WORKSPACE, "Binary.bin1")
+ output2 = os.path.join(self.WORKSPACE, "Binary.bin2")
+ with open(output1, "rb") as f1:
+ size1 = len(f1.read())
+ with open(output2, "rb") as f2:
+ size2 = len(f2.read())
+
+ ex_result = result[index]
+ self.assertEqual(size1, ex_result[0])
+ self.assertEqual(size2, ex_result[1])
+
+ def create_inputfile(self):
+ with open(self.binary_file, "wb") as fout:
+ for i in range(512):
+ fout.write(st.pack("<H", i))
+
+ def test_splitFile_outputfile(self):
+ output = [None, "Binary.bin", "Binary1.bin", r"output/Binary1.bin",
+ os.path.join(self.WORKSPACE, r"output/Binary1.bin")]
+ for o in output:
+ try:
+ sp.splitFile(self.binary_file, 123, outputfile1=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin1")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(o))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o)))
+ self.create_inputfile()
+
+ try:
+ sp.splitFile(self.binary_file, 123, outputfile2=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin2")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(o))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o)))
+ self.create_inputfile()
+
+ def test_splitFile_outputfolder(self):
+ outputfolder = [None, "output", r"output1/output2",
+ os.path.join(self.WORKSPACE, "output")]
+ for o in outputfolder:
+ try:
+ sp.splitFile(self.binary_file, 123, outputdir=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin1")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(
+ os.path.join(o, "Binary.bin1")))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o, "Binary.bin1")))
+
+
+if __name__ == '__main__':
+ unittest.main()
--
2.29.1.windows.1
next prev parent reply other threads:[~2021-01-13 9:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 9:56 [Patch 0/2] Convert Split tool to python Bob Feng
2021-01-13 9:56 ` [Patch 1/2] BaseTools: " Bob Feng
2021-01-13 9:56 ` Bob Feng [this message]
2021-01-14 0:53 ` 回复: [edk2-devel] [Patch 0/2] " gaoliming
2021-01-14 2:46 ` [edk2-devel] " Bob Feng
2021-01-15 1:12 ` 回复: " gaoliming
2021-01-15 1:49 ` Bob Feng
2021-01-18 23:56 ` Bob Feng
2021-01-19 1:10 ` 回复: " gaoliming
2021-01-19 1:28 ` Bob Feng
[not found] ` <165B7DE8D411B030.2239@groups.io>
2021-01-19 13:58 ` Bob Feng
[not found] ` <165BA6D400EB9835.28472@groups.io>
2021-01-21 8:15 ` Bob Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210113095609.1398-3-bob.c.feng@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox