]>
Commit | Line | Data |
---|---|---|
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 | |
14 | import os\r | |
15 | #import Object.Parser.InfObject as InfObject\r | |
16 | from Object.Parser.InfCommonObject import CurrentLine\r | |
17 | from Object.Parser.InfCommonObject import InfLineCommentObject\r | |
18 | from Object.Parser.InfBinaryObject import InfBinariesObject\r | |
19 | import Logger.Log as Logger\r | |
20 | import 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 | |
30 | SectionStringsCommonItem1 = \\r | |
31 | """\r | |
32 | GUID\r | |
33 | """\r | |
34 | #\r | |
35 | # Have 2 elements, binary item Type and FileName\r | |
36 | #\r | |
37 | SectionStringsCommonItem2 = \\r | |
38 | """\r | |
39 | GUID | Test/Test.guid\r | |
40 | """\r | |
41 | \r | |
42 | #\r | |
43 | # Have 3 elements, Type | FileName | Target | Family | TagName | FeatureFlagExp\r | |
44 | #\r | |
45 | SectionStringsCommonItem3 = \\r | |
46 | """\r | |
47 | GUID | 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 | |
54 | SectionStringsCommonItem4 = \\r | |
55 | """\r | |
56 | GUID | 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 | |
63 | SectionStringsCommonItem5 = \\r | |
64 | """\r | |
65 | DEFINE BINARY_FILE_PATH = Test\r | |
66 | GUID | $(BINARY_FILE_PATH)/Test.guid | $(TARGET)\r | |
67 | """\r | |
68 | \r | |
69 | #\r | |
70 | # Have 4 elements, Type | FileName | Target | Family\r | |
71 | #\r | |
72 | SectionStringsCommonItem6 = \\r | |
73 | """\r | |
74 | GUID | Test/Test.guid | DEBUG | *\r | |
75 | """\r | |
76 | \r | |
77 | #\r | |
78 | # Have 4 elements, Type | FileName | Target | Family\r | |
79 | #\r | |
80 | SectionStringsCommonItem7 = \\r | |
81 | """\r | |
82 | GUID | Test/Test.guid | DEBUG | MSFT\r | |
83 | """\r | |
84 | \r | |
85 | #\r | |
86 | # Have 5 elements, Type | FileName | Target | Family | TagName\r | |
87 | #\r | |
88 | SectionStringsCommonItem8 = \\r | |
89 | """\r | |
90 | GUID | 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 | |
96 | SectionStringsCommonItem9 = \\r | |
97 | """\r | |
98 | GUID | 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 | |
105 | SectionStringsCommonItem10 = \\r | |
106 | """\r | |
107 | GUID | 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 | |
119 | SectionStringsVerItem1 = \\r | |
120 | """\r | |
121 | VER\r | |
122 | """\r | |
123 | #\r | |
124 | # Have 5 elements, error format(Maximum elements amount is 4)\r | |
125 | #\r | |
126 | SectionStringsVerItem2 = \\r | |
127 | """\r | |
128 | VER | Test/Test.ver | * | TRUE | OverFlow\r | |
129 | """\r | |
130 | \r | |
131 | #\r | |
132 | # Have 2 elements, Type | FileName\r | |
133 | #\r | |
134 | SectionStringsVerItem3 = \\r | |
135 | """\r | |
136 | VER | Test/Test.ver\r | |
137 | """\r | |
138 | \r | |
139 | #\r | |
140 | # Have 3 elements, Type | FileName | Target\r | |
141 | #\r | |
142 | SectionStringsVerItem4 = \\r | |
143 | """\r | |
144 | VER | Test/Test.ver | DEBUG\r | |
145 | """\r | |
146 | \r | |
147 | #\r | |
148 | # Have 4 elements, Type | FileName | Target | FeatureFlagExp\r | |
149 | #\r | |
150 | SectionStringsVerItem5 = \\r | |
151 | """\r | |
152 | VER | Test/Test.ver | DEBUG | TRUE\r | |
153 | """\r | |
154 | \r | |
155 | #\r | |
156 | # Exist 2 VER items, both opened.\r | |
157 | #\r | |
158 | SectionStringsVerItem6 = \\r | |
159 | """\r | |
160 | VER | Test/Test.ver | * | TRUE\r | |
161 | VER | Test/Test2.ver | * | TRUE\r | |
162 | """\r | |
163 | \r | |
164 | \r | |
165 | #\r | |
166 | # Exist 2 VER items, only 1 opened.\r | |
167 | #\r | |
168 | SectionStringsVerItem7 = \\r | |
169 | """\r | |
170 | VER | Test/Test.ver | * | TRUE\r | |
171 | VER | 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 | |
182 | SectionStringsUiItem1 = \\r | |
183 | """\r | |
184 | UI | Test/Test.ui | * | TRUE\r | |
185 | UI | Test/Test2.ui | * | TRUE\r | |
186 | """\r | |
187 | \r | |
188 | SectionStringsUiItem2 = \\r | |
189 | """\r | |
190 | UI | Test/Test.ui | * | TRUE\r | |
191 | SEC_UI | Test/Test2.ui | * | TRUE\r | |
192 | """\r | |
193 | \r | |
194 | SectionStringsUiItem3 = \\r | |
195 | """\r | |
196 | UI | Test/Test.ui | * | TRUE\r | |
197 | UI | Test/Test2.ui | * | FALSE\r | |
198 | """\r | |
199 | \r | |
200 | #\r | |
201 | # Has 1 element, error format \r | |
202 | #\r | |
203 | SectionStringsUiItem4 = \\r | |
204 | """\r | |
205 | UI\r | |
206 | """\r | |
207 | #\r | |
208 | # Have 5 elements, error format(Maximum elements amount is 4)\r | |
209 | #\r | |
210 | SectionStringsUiItem5 = \\r | |
211 | """\r | |
212 | UI | Test/Test.ui | * | TRUE | OverFlow\r | |
213 | """\r | |
214 | \r | |
215 | #\r | |
216 | # Have 2 elements, Type | FileName\r | |
217 | #\r | |
218 | SectionStringsUiItem6 = \\r | |
219 | """\r | |
220 | UI | Test/Test.ui\r | |
221 | """\r | |
222 | \r | |
223 | #\r | |
224 | # Have 3 elements, Type | FileName | Target\r | |
225 | #\r | |
226 | SectionStringsUiItem7 = \\r | |
227 | """\r | |
228 | UI | Test/Test.ui | DEBUG\r | |
229 | """\r | |
230 | \r | |
231 | #\r | |
232 | # Have 4 elements, Type | FileName | Target | FeatureFlagExp\r | |
233 | #\r | |
234 | SectionStringsUiItem8 = \\r | |
235 | """\r | |
236 | UI | Test/Test.ui | DEBUG | TRUE\r | |
237 | """\r | |
238 | #---------------end of UI type binary item test input-------------------------#\r | |
239 | \r | |
240 | \r | |
241 | gFileName = "BinarySectionTest.inf"\r | |
242 | \r | |
243 | ##\r | |
244 | # Construct SectionString for call section parser usage.\r | |
245 | #\r | |
246 | def 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 | |
258 | def 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 | |
285 | if __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 |