From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web11.5943.1610531774284313300 for ; Wed, 13 Jan 2021 01:56:19 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: bob.c.feng@intel.com) IronPort-SDR: GRZoE3rHgSh5SJ0ESPDV79CpYdHUBZiX25xf7dqRhX4PxXMl0Htk5Ab5WorUBbtv9ZUIZSeiig n16iuF0s548g== X-IronPort-AV: E=McAfee;i="6000,8403,9862"; a="177403477" X-IronPort-AV: E=Sophos;i="5.79,344,1602572400"; d="scan'208";a="177403477" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2021 01:56:19 -0800 IronPort-SDR: z4HVuZMgOgYzkBRdS2Lx5ZdAERqBl2xbMhfDmq8IsAtKyYWDYTTbEcP6lPH9pp5eiePmzqu78g iyunibXG91FA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,344,1602572400"; d="scan'208";a="464845019" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.32]) by fmsmga001.fm.intel.com with ESMTP; 13 Jan 2021 01:56:18 -0800 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Yuwei Chen Subject: [Patch 2/2] BaseTools: Add unittest for Split tool Date: Wed, 13 Jan 2021 17:56:09 +0800 Message-Id: <20210113095609.1398-3-bob.c.feng@intel.com> X-Mailer: git-send-email 2.29.1.windows.1 In-Reply-To: <20210113095609.1398-1-bob.c.feng@intel.com> References: <20210113095609.1398-1-bob.c.feng@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable This patch is to add the unit test for Split python tool=0D Signed-off-by: Bob Feng =0D Cc: Liming Gao =0D Cc: Yuwei Chen =0D --- 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=0D +import tempfile=0D +import os=0D +import shutil=0D +import Split.Split as sp=0D +import struct as st=0D +=0D +=0D +class TestSplit(unittest.TestCase):=0D + def setUp(self):=0D + self.WORKSPACE =3D tempfile.mkdtemp()=0D + self.binary_file =3D os.path.join(self.WORKSPACE, "Binary.bin")=0D + self.create_inputfile()=0D +=0D + def tearDown(self):=0D + if os.path.exists(self.WORKSPACE):=0D + shutil.rmtree(self.WORKSPACE)=0D +=0D + def test_splitFile_position(self):=0D + position =3D [-1, 0, 256, 512, 700, 1024, 2048]=0D + result =3D [(0, 1024), (0, 1024), (256, 768),=0D + (512, 512), (700, 324), (1024, 0), (1024, 0)]=0D + for index, po in enumerate(position):=0D + try:=0D + sp.splitFile(self.binary_file, po)=0D + except Exception as e:=0D + self.assertTrue(False, msg=3D"splitFile function error")=0D +=0D + output1 =3D os.path.join(self.WORKSPACE, "Binary.bin1")=0D + output2 =3D os.path.join(self.WORKSPACE, "Binary.bin2")=0D + with open(output1, "rb") as f1:=0D + size1 =3D len(f1.read())=0D + with open(output2, "rb") as f2:=0D + size2 =3D len(f2.read())=0D +=0D + ex_result =3D result[index]=0D + self.assertEqual(size1, ex_result[0])=0D + self.assertEqual(size2, ex_result[1])=0D +=0D + def create_inputfile(self):=0D + with open(self.binary_file, "wb") as fout:=0D + for i in range(512):=0D + fout.write(st.pack("