Enable equivalence checks of opcode list
authorIustin Pop <iustin@google.com>
Sun, 25 Nov 2012 15:11:26 +0000 (16:11 +0100)
committerIustin Pop <iustin@google.com>
Fri, 30 Nov 2012 13:54:04 +0000 (14:54 +0100)
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
htest/Test/Ganeti/OpCodes.hs

index e61a723..da04968 100755 (executable)
@@ -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__":
index c18cfa8..7c2c2a0 100644 (file)
@@ -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)