Pass 2 more variables to lit tests.
[oota-llvm.git] / utils / lit / lit / Test.py
index 7f5d4117bab8aef2e7490c94bb6e87c8b9cece7c..38bb41b0252d59a3769a3be2097cbae659f6d109 100644 (file)
@@ -1,5 +1,6 @@
 import os
 from xml.sax.saxutils import escape
+from json import JSONEncoder
 
 # Test result codes.
 
@@ -73,6 +74,42 @@ class RealMetricValue(MetricValue):
     def todata(self):
         return self.value
 
+class JSONMetricValue(MetricValue):
+    """
+        JSONMetricValue is used for types that are representable in the output
+        but that are otherwise uninterpreted.
+    """
+    def __init__(self, value):
+        # Ensure the value is a serializable by trying to encode it.
+        # WARNING: The value may change before it is encoded again, and may
+        #          not be encodable after the change.
+        try:
+            e = JSONEncoder()
+            e.encode(value)
+        except TypeError:
+            raise
+        self.value = value
+
+    def format(self):
+        e = JSONEncoder(indent=2, sort_keys=True)
+        return e.encode(self.value)
+
+    def todata(self):
+        return self.value
+
+def toMetricValue(value):
+    if isinstance(value, MetricValue):
+        return value
+    elif isinstance(value, int) or isinstance(value, long):
+        return IntMetricValue(value)
+    elif isinstance(value, float):
+        return RealMetricValue(value)
+    else:
+        # Try to create a JSONMetricValue and let the constructor throw
+        # if value is not a valid type.
+        return JSONMetricValue(value)
+
+
 # Test results.
 
 class Result(object):
@@ -206,7 +243,7 @@ class Test:
         if safe_test_path:
             class_name = safe_name + "." + "/".join(safe_test_path) 
         else:
-            class_name = safe_name
+            class_name = safe_name + "." + safe_name
 
         xml = "<testcase classname='" + class_name + "' name='" + \
             test_name + "'"