PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/edk2/BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py

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