Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Javagedes committed Sep 29, 2023
1 parent 4951233 commit ceceefa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 5 additions & 0 deletions edk2toollib/uefi/edk2/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ def ComputeResult(self, value, cond, value2):
return (ivalue != ivalue2) and (value != value2)

# check to make sure we only have digits from here on out
if value.upper() in ["TRUE", "FALSE"] or value2.upper() in ["TRUE", "FALSE"]:
self.Logger.error(f"Invalid comparison: {value} {cond} {value2}")
self.Logger.debug(f"Invalid comparison: {value} {cond} {value2}")
raise ValueError("Invalid comparison")

if not isinstance(ivalue, int) and not str.isdigit(value):
self.Logger.error(f"{self.__class__}: Unknown value: {value} {ivalue.__class__}")
self.Logger.debug(f"{self.__class__}: Conditional: {value} {cond}{value2}")
Expand Down
7 changes: 7 additions & 0 deletions tests.unit/parsers/test_base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ def test_process_conditional_hex_number(self):
self.assertTrue(parser.ProcessConditional("!IF 0x20 == 32"))
self.assertTrue(parser.InActiveCode())
self.assertTrue(parser.ProcessConditional("!endif"))
# check that hex comparisons work
self.assertTrue(parser.ProcessConditional("!IF 0x20 > 0x20"))
self.assertFalse(parser.InActiveCode())
self.assertTrue(parser.ProcessConditional("!endif"))
self.assertTrue(parser.ProcessConditional("!IF 0x20 >= 0x20"))
self.assertTrue(parser.InActiveCode())
self.assertTrue(parser.ProcessConditional("!endif"))

def test_process_conditional_greater_than(self):
parser = BaseParser("")
Expand Down
25 changes: 0 additions & 25 deletions tests.unit/parsers/test_dsc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,3 @@ def test_dsc_include_relative_path(self):
self.assertEqual(parser.LocalVars["INCLUDED"], "TRUE") # make sure we got the defines
finally:
os.chdir(cwd)

def test_handle_integer_comparisons(self):
DSC_FILE = '''
[Defines]
DEFINE SERIAL_REGISTER_BASE = 0xFEDC9000
[PcdsFixedAtBuild]
!if $(SERIAL_REGISTER_BASE) == 0x3F8 OR $(SERIAL_REGISTER_BASE) == 0x3E8
gEfiModulePkgTokenSpaceGuid.MyValue|0x04
# UART0 is COM2/4 IRQ3
!elseif $(SERIAL_REGISTER_BASE) == 0x2F8 OR $(SERIAL_REGISTER_BASE) == 0x2E8
gEfiModulePkgTokenSpaceGuid.MyValue|0x03
!endif
!if $(SERIAL_REGISTER_BASE) >= 0x10000
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride|4
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|48000000
!else
'''
import pathlib
workspace = tempfile.mkdtemp()
dsc = pathlib.Path(workspace) / "dsc.dsc"
dsc.write_text(DSC_FILE)
parser = DscParser()
parser.SetEdk2Path(Edk2Path(workspace, []))
parser.ParseFile(dsc)

0 comments on commit ceceefa

Please sign in to comment.