2 # This file contain unit test for Test [Binary] section part of InfParser
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
8 from __future__
import print_function
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
17 # Test Common binary item
20 #-------------start of common binary item test input--------------------------#
23 # Only has 1 element, binary item Type
25 SectionStringsCommonItem1
= \
30 # Have 2 elements, binary item Type and FileName
32 SectionStringsCommonItem2
= \
38 # Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp
40 SectionStringsCommonItem3
= \
42 GUID | Test/Test.guid | DEBUG
46 # Have 3 elements, Type | FileName | Target
47 # Target with MACRO defined in [Define] section
49 SectionStringsCommonItem4
= \
51 GUID | Test/Test.guid | $(TARGET)
55 # Have 3 elements, Type | FileName | Target
56 # FileName with MACRO defined in [Binary] section
58 SectionStringsCommonItem5
= \
60 DEFINE BINARY_FILE_PATH = Test
61 GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET)
65 # Have 4 elements, Type | FileName | Target | Family
67 SectionStringsCommonItem6
= \
69 GUID | Test/Test.guid | DEBUG | *
73 # Have 4 elements, Type | FileName | Target | Family
75 SectionStringsCommonItem7
= \
77 GUID | Test/Test.guid | DEBUG | MSFT
81 # Have 5 elements, Type | FileName | Target | Family | TagName
83 SectionStringsCommonItem8
= \
85 GUID | Test/Test.guid | DEBUG | MSFT | TEST
89 # Have 6 elements, Type | FileName | Target | Family | TagName | FFE
91 SectionStringsCommonItem9
= \
93 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE
97 # Have 7 elements, Type | FileName | Target | Family | TagName | FFE | Overflow
100 SectionStringsCommonItem10
= \
102 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE | OVERFLOW
105 #-------------end of common binary item test input----------------------------#
109 #-------------start of VER type binary item test input------------------------#
112 # Has 1 element, error format
114 SectionStringsVerItem1
= \
119 # Have 5 elements, error format(Maximum elements amount is 4)
121 SectionStringsVerItem2
= \
123 VER | Test/Test.ver | * | TRUE | OverFlow
127 # Have 2 elements, Type | FileName
129 SectionStringsVerItem3
= \
135 # Have 3 elements, Type | FileName | Target
137 SectionStringsVerItem4
= \
139 VER | Test/Test.ver | DEBUG
143 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
145 SectionStringsVerItem5
= \
147 VER | Test/Test.ver | DEBUG | TRUE
151 # Exist 2 VER items, both opened.
153 SectionStringsVerItem6
= \
155 VER | Test/Test.ver | * | TRUE
156 VER | Test/Test2.ver | * | TRUE
161 # Exist 2 VER items, only 1 opened.
163 SectionStringsVerItem7
= \
165 VER | Test/Test.ver | * | TRUE
166 VER | Test/Test2.ver | * | FALSE
169 #-------------end of VER type binary item test input--------------------------#
172 #-------------start of UI type binary item test input-------------------------#
175 # Test only one UI section can exist
177 SectionStringsUiItem1
= \
179 UI | Test/Test.ui | * | TRUE
180 UI | Test/Test2.ui | * | TRUE
183 SectionStringsUiItem2
= \
185 UI | Test/Test.ui | * | TRUE
186 SEC_UI | Test/Test2.ui | * | TRUE
189 SectionStringsUiItem3
= \
191 UI | Test/Test.ui | * | TRUE
192 UI | Test/Test2.ui | * | FALSE
196 # Has 1 element, error format
198 SectionStringsUiItem4
= \
203 # Have 5 elements, error format(Maximum elements amount is 4)
205 SectionStringsUiItem5
= \
207 UI | Test/Test.ui | * | TRUE | OverFlow
211 # Have 2 elements, Type | FileName
213 SectionStringsUiItem6
= \
219 # Have 3 elements, Type | FileName | Target
221 SectionStringsUiItem7
= \
223 UI | Test/Test.ui | DEBUG
227 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
229 SectionStringsUiItem8
= \
231 UI | Test/Test.ui | DEBUG | TRUE
233 #---------------end of UI type binary item test input-------------------------#
236 gFileName
= "BinarySectionTest.inf"
239 # Construct SectionString for call section parser usage.
241 def StringToSectionString(String
):
242 Lines
= String
.split('\n')
246 if Line
.strip() == '':
248 SectionString
.append((Line
, LineNo
, ''))
253 def PrepareTest(String
):
254 SectionString
= StringToSectionString(String
)
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:
262 # Create a temp file for test.
264 FileName
= os
.path
.normpath(os
.path
.realpath(ValueList
[1].strip()))
266 TempFile
= open (FileName
, "w")
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()
276 ItemList
.append((ValueList
, InfLineCommentObject
, CurrentLine
))
280 if __name__
== '__main__':
283 InfBinariesInstance
= InfBinariesObject()
284 ArchList
= ['COMMON']
285 Global
.gINF_MODULE_DIR
= os
.getcwd()
293 SectionStringsUiItem1
,
294 SectionStringsUiItem2
,
295 SectionStringsUiItem3
,
296 SectionStringsUiItem4
,
297 SectionStringsUiItem5
,
298 SectionStringsUiItem6
,
299 SectionStringsUiItem7
,
300 SectionStringsUiItem8
303 for Item
in UiStringList
:
304 Ui
= PrepareTest(Item
)
305 if Item
== SectionStringsUiItem4
or Item
== SectionStringsUiItem5
:
307 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
308 except Logger
.FatalError
:
312 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
314 AllPassedFlag
= False
320 SectionStringsVerItem1
,
321 SectionStringsVerItem2
,
322 SectionStringsVerItem3
,
323 SectionStringsVerItem4
,
324 SectionStringsVerItem5
,
325 SectionStringsVerItem6
,
326 SectionStringsVerItem7
328 for Item
in VerStringList
:
329 Ver
= PrepareTest(Item
)
330 if Item
== SectionStringsVerItem1
or \
331 Item
== SectionStringsVerItem2
:
334 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
340 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
342 AllPassedFlag
= False
345 # For All Common Test
348 SectionStringsCommonItem1
,
349 SectionStringsCommonItem2
,
350 SectionStringsCommonItem3
,
351 SectionStringsCommonItem4
,
352 SectionStringsCommonItem5
,
353 SectionStringsCommonItem6
,
354 SectionStringsCommonItem7
,
355 SectionStringsCommonItem8
,
356 SectionStringsCommonItem9
,
357 SectionStringsCommonItem10
360 for Item
in CommonStringList
:
361 CommonBin
= PrepareTest(Item
)
362 if Item
== SectionStringsCommonItem10
or \
363 Item
== SectionStringsCommonItem1
:
366 InfBinariesInstance
.SetBinary(CommonBinary
= CommonBin
, ArchList
= ArchList
)
372 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
374 print("Test Failed!")
375 AllPassedFlag
= False
378 print('All tests passed...')
380 print('Some unit test failed!')