From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.5545.1611019709104617981 for ; Mon, 18 Jan 2021 17:28:29 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: bob.c.feng@intel.com) IronPort-SDR: UtGuere1x5SUgYUYlVRtrf/BXRdwr1BbziuU1/b/95qe/GZa0Pg+8kPUI1/ARrFev88s1Sd/6H gj4IyFijGSqw== X-IronPort-AV: E=McAfee;i="6000,8403,9868"; a="166531524" X-IronPort-AV: E=Sophos;i="5.79,357,1602572400"; d="scan'208";a="166531524" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2021 17:28:27 -0800 IronPort-SDR: 36uMR6+tNl5wIjl9n95abT5kGB2WupyVVlfXSuszjLjh5cWhGCmBwprYO98JBraIr9mjalGrI9 kTaOqQqyk03A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,357,1602572400"; d="scan'208";a="383739193" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.32]) by orsmga008.jf.intel.com with ESMTP; 18 Jan 2021 17:28:26 -0800 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Yuwei Chen Subject: [Patch 2/2 V4] BaseTools: Add unittest for Split tool Date: Tue, 19 Jan 2021 09:28:24 +0800 Message-Id: <20210119012824.197-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.29.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3165 This patch is to add the unit test for Split python tool Signed-off-by: Bob Feng Cc: Liming Gao Cc: Yuwei Chen --- V3: Move test_split.py to tests/Sprit folder V4: No change on V4 .../Source/Python/tests/Split/test_split.py | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 BaseTools/Source/Python/tests/Split/test_split.py diff --git a/BaseTools/Source/Python/tests/Split/test_split.py b/BaseTools/Source/Python/tests/Split/test_split.py new file mode 100644 index 000000000000..82f71ecf5372 --- /dev/null +++ b/BaseTools/Source/Python/tests/Split/test_split.py @@ -0,0 +1,111 @@ +# @file +# Split a file into two pieces at the request offset. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +# Import Modules +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("