From 9b7736655d57dab23eec8da1847acc28eeb43f7d Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 25 Nov 2012 16:11:26 +0100 Subject: [PATCH] Enable equivalence checks of opcode list This patch enhances the opcode list checks - instead of spawning a Python interpreter to display the opcode list, we export it statically in Constants.hs via a slight convert-constants change. Furthermore, since we now have opcode parity, we enable full opcode list checks. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Helga Velroyen <helgav@google.com> --- autotools/convert-constants | 12 ++++++++++++ htest/Test/Ganeti/OpCodes.hs | 14 +++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/autotools/convert-constants b/autotools/convert-constants index e61a72336..da04968d0 100755 --- a/autotools/convert-constants +++ b/autotools/convert-constants @@ -30,6 +30,7 @@ from ganeti import compat from ganeti import constants from ganeti import errors from ganeti import luxi +from ganeti import opcodes from ganeti import qlang @@ -296,12 +297,23 @@ def Convert(module, prefix): return "\n".join(lines) +def ConvertMisc(): + """Convert some extra computed-values to Haskell. + + """ + lines = [""] + lines.extend(ConvertVariable("opcodes", "OP_IDS", + opcodes.OP_MAPPING.keys(), {})) + return "\n".join(lines) + + def main(): print Convert(constants, "") print Convert(luxi, "luxi") print Convert(qlang, "qlang") print Convert(_autoconf, "autoconf") print Convert(errors, "errors") + print ConvertMisc() if __name__ == "__main__": diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs index c18cfa82e..7c2c2a025 100644 --- a/htest/Test/Ganeti/OpCodes.hs +++ b/htest/Test/Ganeti/OpCodes.hs @@ -410,16 +410,12 @@ prop_serialization = testSerialisation -- | Check that Python and Haskell defined the same opcode list. case_AllDefined :: HUnit.Assertion case_AllDefined = do - py_stdout <- runPython "from ganeti import opcodes\n\ - \print '\\n'.join(opcodes.OP_MAPPING.keys())" "" >>= - checkPythonResult - let py_ops = sort $ lines py_stdout - hs_ops = OpCodes.allOpIDs - -- extra_py = py_ops \\ hs_ops + let py_ops = sort C.opcodesOpIds + hs_ops = sort OpCodes.allOpIDs + extra_py = py_ops \\ hs_ops extra_hs = hs_ops \\ py_ops - -- FIXME: uncomment when we have parity - -- HUnit.assertBool ("OpCodes missing from Haskell code:\n" ++ - -- unlines extra_py) (null extra_py) + HUnit.assertBool ("Missing OpCodes from the Haskell code:\n" ++ + unlines extra_py) (null extra_py) HUnit.assertBool ("Extra OpCodes in the Haskell code code:\n" ++ unlines extra_hs) (null extra_hs) -- GitLab