diff --git a/edk2toollib/uefi/edk2/parsers/base_parser.py b/edk2toollib/uefi/edk2/parsers/base_parser.py index 168b0f38a..771c8f379 100644 --- a/edk2toollib/uefi/edk2/parsers/base_parser.py +++ b/edk2toollib/uefi/edk2/parsers/base_parser.py @@ -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}") diff --git a/tests.unit/parsers/test_base_parser.py b/tests.unit/parsers/test_base_parser.py index 10a7be42e..771d37222 100644 --- a/tests.unit/parsers/test_base_parser.py +++ b/tests.unit/parsers/test_base_parser.py @@ -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("") diff --git a/tests.unit/parsers/test_dsc_parser.py b/tests.unit/parsers/test_dsc_parser.py index d8a5916a5..7c3490871 100644 --- a/tests.unit/parsers/test_dsc_parser.py +++ b/tests.unit/parsers/test_dsc_parser.py @@ -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)