From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web09.27953.1610937227513799514 for ; Sun, 17 Jan 2021 18:33:47 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: bob.c.feng@intel.com) IronPort-SDR: 6GpsGt5UXseNaMXvDEBkOQ34l0/thx+ARnZT0YNNA630bOrvf2/y6O2ilgygLKa1DloRqyH09j iv8QZfFmWeIw== X-IronPort-AV: E=McAfee;i="6000,8403,9867"; a="175245039" X-IronPort-AV: E=Sophos;i="5.79,355,1602572400"; d="scan'208";a="175245039" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2021 18:33:46 -0800 IronPort-SDR: 4BH4sV2F4WJcf9ggxxYPgDOJQrqAyoCyzqvbWFYYpNXzQ/5VfA5ZZz3OVeEn6HhkjmkM4T4r0j CNTKFWUBFEWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,355,1602572400"; d="scan'208";a="466214509" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.32]) by fmsmga001.fm.intel.com with ESMTP; 17 Jan 2021 18:33:45 -0800 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Yuwei Chen Subject: [Patch 2/2 V3] BaseTools: Add unittest for Split tool Date: Mon, 18 Jan 2021 10:33:37 +0800 Message-Id: <20210118023337.1498-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 .../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("