From 43a113385e370530eb52cf2e55b3019d8d4f6558 Mon Sep 17 00:00:00 2001 From: Bob Feng Date: Mon, 1 Feb 2021 18:28:58 +0800 Subject: BaseTools: fix the split output files root dir If the output file path is a relative path, the split tool will create the output file under the input file path. But the expected behavior for this case is the output file should be relative to the current directory. This patch will fix this bug. If the output file path is not specified and output prefix is not specified, the output file should be under the input file path Signed-off-by: Bob Feng Cc: Liming Gao Cc: Yuwei Chen Acked-by: Liming Gao Reviewed-by: Yuwei Chen --- BaseTools/Source/Python/tests/Split/test_split.py | 96 ++++++++++++----------- 1 file changed, 50 insertions(+), 46 deletions(-) (limited to 'BaseTools/Source/Python/tests') diff --git a/BaseTools/Source/Python/tests/Split/test_split.py b/BaseTools/Source/Python/tests/Split/test_split.py index 82f71ec..e4866be 100644 --- a/BaseTools/Source/Python/tests/Split/test_split.py +++ b/BaseTools/Source/Python/tests/Split/test_split.py @@ -18,26 +18,27 @@ 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.tmpdir = tempfile.mkdtemp() + self.binary_file = os.path.join(self.tmpdir, "Binary.bin") self.create_inputfile() def tearDown(self): - if os.path.exists(self.WORKSPACE): - shutil.rmtree(self.WORKSPACE) + if os.path.exists(self.tmpdir): + shutil.rmtree(self.tmpdir) 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)] + outputfolder = self.tmpdir 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") + output1 = os.path.join(outputfolder, "Binary.bin1") + output2 = os.path.join(outputfolder, "Binary.bin2") with open(output1, "rb") as f1: size1 = len(f1.read()) with open(output2, "rb") as f2: @@ -53,58 +54,61 @@ class TestSplit(unittest.TestCase): fout.write(st.pack("