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