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