]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2Pkg/Tools/Tests/test_yaml.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / IntelFsp2Pkg / Tools / Tests / test_yaml.py
1 # @file
2 # Split a file into two pieces at the request offset.
3 #
4 # Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8 ##
9
10 # Import Modules
11 import unittest
12 import tempfile
13 import os
14 import shutil
15 import struct as st
16 import filecmp
17
18 import os, sys
19 currentdir = os.path.dirname(os.path.realpath(__file__))
20 parentdir = os.path.dirname(currentdir)
21 sys.path.append(parentdir)
22 import FspDscBsf2Yaml
23
24 YamlHeaderLineLength = 10
25 HdrFileHeaderLineLength = 32
26 BsfFileHeaderLineLength = 19
27
28 def GenFileWithoutHdr(inputfile, numLineToStrip):
29 yaml_file = open(inputfile, "r")
30 lines = yaml_file.readlines()
31 yaml_file.close()
32 del lines[:numLineToStrip]
33
34 noHdrOutputFileName = "no-header-" + inputfile
35 stripped_file = open(noHdrOutputFileName, "w")
36 for line in lines:
37 stripped_file.write(line)
38 stripped_file.close()
39 return noHdrOutputFileName
40
41 class TestFspScripts(unittest.TestCase):
42 def test_generateFspHeader_fromDsc(self):
43 # Generate HEADER
44 cmd = '{} {} HEADER {} {} {}'.format(
45 'python',
46 '..\GenCfgOpt.py',
47 'QemuFspPkg.dsc',
48 '.',
49 "")
50 os.system(cmd)
51 noHdrOutputFileName = GenFileWithoutHdr("FspUpd.h", HdrFileHeaderLineLength)
52 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
53 'ExpectedFspUpd.h'))
54
55 def test_generateFspsHeader_fromDsc(self):
56 noHdrOutputFileName = GenFileWithoutHdr("FspsUpd.h", HdrFileHeaderLineLength)
57 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
58 'ExpectedFspsUpd.h'))
59
60 def test_generateFsptHeader_fromDsc(self):
61 noHdrOutputFileName = GenFileWithoutHdr("FsptUpd.h", HdrFileHeaderLineLength)
62 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
63 'ExpectedFsptUpd.h'))
64
65 def test_generateFspmHeader_fromDsc(self):
66 noHdrOutputFileName = GenFileWithoutHdr("FspmUpd.h", HdrFileHeaderLineLength)
67 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
68 'ExpectedFspmUpd.h'))
69
70 def test_generateBsf_fromDsc(self):
71 # Generate BSF
72 cmd = '{} {} GENBSF {} {} {}'.format(
73 'python',
74 '..\GenCfgOpt.py',
75 'QemuFspPkg.dsc',
76 '.',
77 "Output.bsf")
78 os.system(cmd)
79 noHdrOutputFileName = GenFileWithoutHdr("Output.bsf", BsfFileHeaderLineLength)
80 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
81 'ExpectedOutput.bsf'))
82
83 def test_generateYaml_fromDsc(self):
84 # Generate YAML
85 cmd = '{} {} {} {}'.format(
86 'python',
87 '..\FspDscBsf2Yaml.py',
88 'QemuFspPkg.dsc',
89 "Output.yaml")
90 os.system(cmd)
91 noHdrOutputFileName = GenFileWithoutHdr("Output.yaml", YamlHeaderLineLength)
92 self.assertTrue(filecmp.cmp(noHdrOutputFileName,
93 'ExpectedOutput.yaml'))
94
95 if __name__ == '__main__':
96 unittest.main()