2 # This file contain unit test for Test [Binary] section part of InfParser
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
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
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.
14 from __future__
import print_function
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
23 # Test Common binary item
26 #-------------start of common binary item test input--------------------------#
29 # Only has 1 element, binary item Type
31 SectionStringsCommonItem1
= \
36 # Have 2 elements, binary item Type and FileName
38 SectionStringsCommonItem2
= \
44 # Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp
46 SectionStringsCommonItem3
= \
48 GUID | Test/Test.guid | DEBUG
52 # Have 3 elements, Type | FileName | Target
53 # Target with MACRO defined in [Define] section
55 SectionStringsCommonItem4
= \
57 GUID | Test/Test.guid | $(TARGET)
61 # Have 3 elements, Type | FileName | Target
62 # FileName with MACRO defined in [Binary] section
64 SectionStringsCommonItem5
= \
66 DEFINE BINARY_FILE_PATH = Test
67 GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET)
71 # Have 4 elements, Type | FileName | Target | Family
73 SectionStringsCommonItem6
= \
75 GUID | Test/Test.guid | DEBUG | *
79 # Have 4 elements, Type | FileName | Target | Family
81 SectionStringsCommonItem7
= \
83 GUID | Test/Test.guid | DEBUG | MSFT
87 # Have 5 elements, Type | FileName | Target | Family | TagName
89 SectionStringsCommonItem8
= \
91 GUID | Test/Test.guid | DEBUG | MSFT | TEST
95 # Have 6 elements, Type | FileName | Target | Family | TagName | FFE
97 SectionStringsCommonItem9
= \
99 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE
103 # Have 7 elements, Type | FileName | Target | Family | TagName | FFE | Overflow
106 SectionStringsCommonItem10
= \
108 GUID | Test/Test.guid | DEBUG | MSFT | TEST | TRUE | OVERFLOW
111 #-------------end of common binary item test input----------------------------#
115 #-------------start of VER type binary item test input------------------------#
118 # Has 1 element, error format
120 SectionStringsVerItem1
= \
125 # Have 5 elements, error format(Maximum elements amount is 4)
127 SectionStringsVerItem2
= \
129 VER | Test/Test.ver | * | TRUE | OverFlow
133 # Have 2 elements, Type | FileName
135 SectionStringsVerItem3
= \
141 # Have 3 elements, Type | FileName | Target
143 SectionStringsVerItem4
= \
145 VER | Test/Test.ver | DEBUG
149 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
151 SectionStringsVerItem5
= \
153 VER | Test/Test.ver | DEBUG | TRUE
157 # Exist 2 VER items, both opened.
159 SectionStringsVerItem6
= \
161 VER | Test/Test.ver | * | TRUE
162 VER | Test/Test2.ver | * | TRUE
167 # Exist 2 VER items, only 1 opened.
169 SectionStringsVerItem7
= \
171 VER | Test/Test.ver | * | TRUE
172 VER | Test/Test2.ver | * | FALSE
175 #-------------end of VER type binary item test input--------------------------#
178 #-------------start of UI type binary item test input-------------------------#
181 # Test only one UI section can exist
183 SectionStringsUiItem1
= \
185 UI | Test/Test.ui | * | TRUE
186 UI | Test/Test2.ui | * | TRUE
189 SectionStringsUiItem2
= \
191 UI | Test/Test.ui | * | TRUE
192 SEC_UI | Test/Test2.ui | * | TRUE
195 SectionStringsUiItem3
= \
197 UI | Test/Test.ui | * | TRUE
198 UI | Test/Test2.ui | * | FALSE
202 # Has 1 element, error format
204 SectionStringsUiItem4
= \
209 # Have 5 elements, error format(Maximum elements amount is 4)
211 SectionStringsUiItem5
= \
213 UI | Test/Test.ui | * | TRUE | OverFlow
217 # Have 2 elements, Type | FileName
219 SectionStringsUiItem6
= \
225 # Have 3 elements, Type | FileName | Target
227 SectionStringsUiItem7
= \
229 UI | Test/Test.ui | DEBUG
233 # Have 4 elements, Type | FileName | Target | FeatureFlagExp
235 SectionStringsUiItem8
= \
237 UI | Test/Test.ui | DEBUG | TRUE
239 #---------------end of UI type binary item test input-------------------------#
242 gFileName
= "BinarySectionTest.inf"
245 # Construct SectionString for call section parser usage.
247 def StringToSectionString(String
):
248 Lines
= String
.split('\n')
252 if Line
.strip() == '':
254 SectionString
.append((Line
, LineNo
, ''))
259 def PrepareTest(String
):
260 SectionString
= StringToSectionString(String
)
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:
268 # Create a temp file for test.
270 FileName
= os
.path
.normpath(os
.path
.realpath(ValueList
[1].strip()))
272 TempFile
= open (FileName
, "w")
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()
282 ItemList
.append((ValueList
, InfLineCommentObject
, CurrentLine
))
286 if __name__
== '__main__':
289 InfBinariesInstance
= InfBinariesObject()
290 ArchList
= ['COMMON']
291 Global
.gINF_MODULE_DIR
= os
.getcwd()
299 SectionStringsUiItem1
,
300 SectionStringsUiItem2
,
301 SectionStringsUiItem3
,
302 SectionStringsUiItem4
,
303 SectionStringsUiItem5
,
304 SectionStringsUiItem6
,
305 SectionStringsUiItem7
,
306 SectionStringsUiItem8
309 for Item
in UiStringList
:
310 Ui
= PrepareTest(Item
)
311 if Item
== SectionStringsUiItem4
or Item
== SectionStringsUiItem5
:
313 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
314 except Logger
.FatalError
:
318 InfBinariesInstance
.SetBinary(Ui
= Ui
, ArchList
= ArchList
)
320 AllPassedFlag
= False
326 SectionStringsVerItem1
,
327 SectionStringsVerItem2
,
328 SectionStringsVerItem3
,
329 SectionStringsVerItem4
,
330 SectionStringsVerItem5
,
331 SectionStringsVerItem6
,
332 SectionStringsVerItem7
334 for Item
in VerStringList
:
335 Ver
= PrepareTest(Item
)
336 if Item
== SectionStringsVerItem1
or \
337 Item
== SectionStringsVerItem2
:
340 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
346 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
348 AllPassedFlag
= False
351 # For All Common Test
354 SectionStringsCommonItem1
,
355 SectionStringsCommonItem2
,
356 SectionStringsCommonItem3
,
357 SectionStringsCommonItem4
,
358 SectionStringsCommonItem5
,
359 SectionStringsCommonItem6
,
360 SectionStringsCommonItem7
,
361 SectionStringsCommonItem8
,
362 SectionStringsCommonItem9
,
363 SectionStringsCommonItem10
366 for Item
in CommonStringList
:
367 CommonBin
= PrepareTest(Item
)
368 if Item
== SectionStringsCommonItem10
or \
369 Item
== SectionStringsCommonItem1
:
372 InfBinariesInstance
.SetBinary(CommonBinary
= CommonBin
, ArchList
= ArchList
)
378 InfBinariesInstance
.SetBinary(Ver
= Ver
, ArchList
= ArchList
)
380 print("Test Failed!")
381 AllPassedFlag
= False
384 print('All tests passed...')
386 print('Some unit test failed!')