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