]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / UPT / UnitTest / InfBinarySectionTest.py
CommitLineData
4234283c 1## @file\r
f7496d71 2# This file contain unit test for Test [Binary] section part of InfParser\r
4234283c 3#\r
f7496d71 4# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c 5#\r
f7496d71
LG
6# This program and the accompanying materials are licensed and made available\r
7# under the terms and conditions of the BSD License which accompanies this\r
8# distribution. The full text of the license may be found at\r
4234283c
LG
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
72443dd2 14from __future__ import print_function\r
4234283c
LG
15import os\r
16#import Object.Parser.InfObject as InfObject\r
17from Object.Parser.InfCommonObject import CurrentLine\r
18from Object.Parser.InfCommonObject import InfLineCommentObject\r
19from Object.Parser.InfBinaryObject import InfBinariesObject\r
20import Logger.Log as Logger\r
21import Library.GlobalData as Global\r
22##\r
23# Test Common binary item\r
24#\r
25\r
26#-------------start of common binary item test input--------------------------#\r
27\r
28#\r
29# Only has 1 element, binary item Type\r
30#\r
31SectionStringsCommonItem1 = \\r
32"""\r
33GUID\r
34"""\r
35#\r
36# Have 2 elements, binary item Type and FileName\r
37#\r
38SectionStringsCommonItem2 = \\r
39"""\r
40GUID | Test/Test.guid\r
41"""\r
42\r
43#\r
44# Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp\r
45#\r
46SectionStringsCommonItem3 = \\r
47"""\r
48GUID | Test/Test.guid | DEBUG\r
49"""\r
50\r
51#\r
f7496d71 52# Have 3 elements, Type | FileName | Target\r
4234283c
LG
53# Target with MACRO defined in [Define] section\r
54#\r
55SectionStringsCommonItem4 = \\r
56"""\r
57GUID | Test/Test.guid | $(TARGET)\r
58"""\r
59\r
60#\r
f7496d71 61# Have 3 elements, Type | FileName | Target\r
4234283c
LG
62# FileName with MACRO defined in [Binary] section\r
63#\r
64SectionStringsCommonItem5 = \\r
65"""\r
66DEFINE BINARY_FILE_PATH = Test\r
67GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET)\r
68"""\r
69\r
70#\r
71# Have 4 elements, Type | FileName | Target | Family\r
72#\r
73SectionStringsCommonItem6 = \\r
74"""\r
75GUID | Test/Test.guid | DEBUG | *\r
76"""\r
77\r
78#\r
79# Have 4 elements, Type | FileName | Target | Family\r
80#\r
81SectionStringsCommonItem7 = \\r
82"""\r
83GUID | Test/Test.guid | DEBUG | MSFT\r
84"""\r
85\r
86#\r
87# Have 5 elements, Type | FileName | Target | Family | TagName\r
88#\r
89SectionStringsCommonItem8 = \\r
90"""\r
91GUID | Test/Test.guid | DEBUG | MSFT | TEST\r
92"""\r
93\r
94#\r
95# Have 6 elements, Type | FileName | Target | Family | TagName | FFE\r
96#\r
97SectionStringsCommonItem9 = \\r
98"""\r
99GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE\r
100"""\r
101\r
102#\r
103# Have 7 elements, Type | FileName | Target | Family | TagName | FFE | Overflow\r
104# Test wrong format\r
105#\r
106SectionStringsCommonItem10 = \\r
107"""\r
108GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE | OVERFLOW\r
109"""\r
110\r
111#-------------end of common binary item test input----------------------------#\r
112\r
113\r
114\r
115#-------------start of VER type binary item test input------------------------#\r
116\r
117#\r
f7496d71 118# Has 1 element, error format\r
4234283c
LG
119#\r
120SectionStringsVerItem1 = \\r
121"""\r
122VER\r
123"""\r
124#\r
125# Have 5 elements, error format(Maximum elements amount is 4)\r
126#\r
127SectionStringsVerItem2 = \\r
128"""\r
129VER | Test/Test.ver | * | TRUE | OverFlow\r
130"""\r
131\r
132#\r
133# Have 2 elements, Type | FileName\r
134#\r
135SectionStringsVerItem3 = \\r
136"""\r
137VER | Test/Test.ver\r
138"""\r
139\r
140#\r
141# Have 3 elements, Type | FileName | Target\r
142#\r
143SectionStringsVerItem4 = \\r
144"""\r
145VER | Test/Test.ver | DEBUG\r
146"""\r
147\r
148#\r
149# Have 4 elements, Type | FileName | Target | FeatureFlagExp\r
150#\r
151SectionStringsVerItem5 = \\r
152"""\r
153VER | Test/Test.ver | DEBUG | TRUE\r
154"""\r
155\r
156#\r
157# Exist 2 VER items, both opened.\r
158#\r
159SectionStringsVerItem6 = \\r
160"""\r
161VER | Test/Test.ver | * | TRUE\r
162VER | Test/Test2.ver | * | TRUE\r
163"""\r
164\r
165\r
166#\r
167# Exist 2 VER items, only 1 opened.\r
168#\r
169SectionStringsVerItem7 = \\r
170"""\r
171VER | Test/Test.ver | * | TRUE\r
172VER | Test/Test2.ver | * | FALSE\r
173"""\r
174\r
175#-------------end of VER type binary item test input--------------------------#\r
176\r
177\r
178#-------------start of UI type binary item test input-------------------------#\r
179\r
180#\r
181# Test only one UI section can exist\r
182#\r
183SectionStringsUiItem1 = \\r
184"""\r
185UI | Test/Test.ui | * | TRUE\r
186UI | Test/Test2.ui | * | TRUE\r
187"""\r
188\r
189SectionStringsUiItem2 = \\r
190"""\r
191UI | Test/Test.ui | * | TRUE\r
192SEC_UI | Test/Test2.ui | * | TRUE\r
193"""\r
194\r
195SectionStringsUiItem3 = \\r
196"""\r
197UI | Test/Test.ui | * | TRUE\r
198UI | Test/Test2.ui | * | FALSE\r
199"""\r
200\r
201#\r
f7496d71 202# Has 1 element, error format\r
4234283c
LG
203#\r
204SectionStringsUiItem4 = \\r
205"""\r
206UI\r
207"""\r
208#\r
209# Have 5 elements, error format(Maximum elements amount is 4)\r
210#\r
211SectionStringsUiItem5 = \\r
212"""\r
213UI | Test/Test.ui | * | TRUE | OverFlow\r
214"""\r
215\r
216#\r
217# Have 2 elements, Type | FileName\r
218#\r
219SectionStringsUiItem6 = \\r
220"""\r
221UI | Test/Test.ui\r
222"""\r
223\r
224#\r
225# Have 3 elements, Type | FileName | Target\r
226#\r
227SectionStringsUiItem7 = \\r
228"""\r
229UI | Test/Test.ui | DEBUG\r
230"""\r
231\r
232#\r
233# Have 4 elements, Type | FileName | Target | FeatureFlagExp\r
234#\r
235SectionStringsUiItem8 = \\r
236"""\r
237UI | Test/Test.ui | DEBUG | TRUE\r
238"""\r
239#---------------end of UI type binary item test input-------------------------#\r
240\r
241\r
242gFileName = "BinarySectionTest.inf"\r
243\r
244##\r
245# Construct SectionString for call section parser usage.\r
246#\r
247def StringToSectionString(String):\r
248 Lines = String.split('\n')\r
249 LineNo = 0\r
250 SectionString = []\r
251 for Line in Lines:\r
252 if Line.strip() == '':\r
253 continue\r
254 SectionString.append((Line, LineNo, ''))\r
255 LineNo = LineNo + 1\r
f7496d71 256\r
4234283c
LG
257 return SectionString\r
258\r
259def PrepareTest(String):\r
260 SectionString = StringToSectionString(String)\r
261 ItemList = []\r
262 for Item in SectionString:\r
263 ValueList = Item[0].split('|')\r
264 for count in range(len(ValueList)):\r
265 ValueList[count] = ValueList[count].strip()\r
266 if len(ValueList) >= 2:\r
267 #\r
268 # Create a temp file for test.\r
269 #\r
270 FileName = os.path.normpath(os.path.realpath(ValueList[1].strip()))\r
271 try:\r
f7496d71 272 TempFile = open (FileName, "w")\r
4234283c
LG
273 TempFile.close()\r
274 except:\r
72443dd2 275 print("File Create Error")\r
4234283c
LG
276 CurrentLine = CurrentLine()\r
277 CurrentLine.SetFileName("Test")\r
278 CurrentLine.SetLineString(Item[0])\r
279 CurrentLine.SetLineNo(Item[1])\r
280 InfLineCommentObject = InfLineCommentObject()\r
f7496d71 281\r
4234283c 282 ItemList.append((ValueList, InfLineCommentObject, CurrentLine))\r
f7496d71 283\r
4234283c
LG
284 return ItemList\r
285\r
286if __name__ == '__main__':\r
287 Logger.Initialize()\r
f7496d71 288\r
4234283c
LG
289 InfBinariesInstance = InfBinariesObject()\r
290 ArchList = ['COMMON']\r
291 Global.gINF_MODULE_DIR = os.getcwd()\r
f7496d71 292\r
4234283c 293 AllPassedFlag = True\r
f7496d71 294\r
4234283c
LG
295 #\r
296 # For All Ui test\r
297 #\r
f7496d71 298 UiStringList = [\r
4234283c
LG
299 SectionStringsUiItem1,\r
300 SectionStringsUiItem2,\r
301 SectionStringsUiItem3,\r
302 SectionStringsUiItem4,\r
303 SectionStringsUiItem5,\r
304 SectionStringsUiItem6,\r
305 SectionStringsUiItem7,\r
f7496d71 306 SectionStringsUiItem8\r
4234283c 307 ]\r
f7496d71
LG
308\r
309 for Item in UiStringList:\r
4234283c
LG
310 Ui = PrepareTest(Item)\r
311 if Item == SectionStringsUiItem4 or Item == SectionStringsUiItem5:\r
312 try:\r
313 InfBinariesInstance.SetBinary(Ui = Ui, ArchList = ArchList)\r
314 except Logger.FatalError:\r
315 pass\r
316 else:\r
f7496d71 317 try:\r
4234283c
LG
318 InfBinariesInstance.SetBinary(Ui = Ui, ArchList = ArchList)\r
319 except:\r
f7496d71
LG
320 AllPassedFlag = False\r
321\r
4234283c
LG
322 #\r
323 # For All Ver Test\r
324 #\r
325 VerStringList = [\r
326 SectionStringsVerItem1,\r
327 SectionStringsVerItem2,\r
328 SectionStringsVerItem3,\r
329 SectionStringsVerItem4,\r
330 SectionStringsVerItem5,\r
331 SectionStringsVerItem6,\r
332 SectionStringsVerItem7\r
333 ]\r
f7496d71 334 for Item in VerStringList:\r
4234283c
LG
335 Ver = PrepareTest(Item)\r
336 if Item == SectionStringsVerItem1 or \\r
337 Item == SectionStringsVerItem2:\r
f7496d71 338\r
4234283c
LG
339 try:\r
340 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList)\r
341 except:\r
342 pass\r
f7496d71 343\r
4234283c
LG
344 else:\r
345 try:\r
346 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList)\r
347 except:\r
f7496d71
LG
348 AllPassedFlag = False\r
349\r
4234283c
LG
350 #\r
351 # For All Common Test\r
f7496d71 352 #\r
4234283c
LG
353 CommonStringList = [\r
354 SectionStringsCommonItem1,\r
355 SectionStringsCommonItem2,\r
356 SectionStringsCommonItem3,\r
357 SectionStringsCommonItem4,\r
358 SectionStringsCommonItem5,\r
359 SectionStringsCommonItem6,\r
360 SectionStringsCommonItem7,\r
361 SectionStringsCommonItem8,\r
362 SectionStringsCommonItem9,\r
363 SectionStringsCommonItem10\r
364 ]\r
365\r
f7496d71 366 for Item in CommonStringList:\r
4234283c
LG
367 CommonBin = PrepareTest(Item)\r
368 if Item == SectionStringsCommonItem10 or \\r
369 Item == SectionStringsCommonItem1:\r
f7496d71 370\r
4234283c
LG
371 try:\r
372 InfBinariesInstance.SetBinary(CommonBinary = CommonBin, ArchList = ArchList)\r
373 except:\r
374 pass\r
f7496d71 375\r
4234283c
LG
376 else:\r
377 try:\r
378 InfBinariesInstance.SetBinary(Ver = Ver, ArchList = ArchList)\r
379 except:\r
72443dd2 380 print("Test Failed!")\r
4234283c 381 AllPassedFlag = False\r
f7496d71 382\r
4234283c 383 if AllPassedFlag :\r
72443dd2 384 print('All tests passed...')\r
4234283c 385 else:\r
72443dd2 386 print('Some unit test failed!')\r
4234283c 387\r