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