Adding testing of cpu variants.
authorTim 'mithro' Ansell <me@mith.ro>
Fri, 26 Apr 2019 22:13:28 +0000 (17:13 -0500)
committerTim 'mithro' Ansell <me@mith.ro>
Fri, 26 Apr 2019 23:57:49 +0000 (18:57 -0500)
litex/soc/integration/soc_core.py
test/test_targets.py

index c5fe7ad2fe12f46979e6be04e9f7dff82ab5f066..a36b68a2908b7375208f6eb3779302f4fe4e23a0 100644 (file)
@@ -54,7 +54,7 @@ Invalid extension in cpu_variant value: {}
 
 Possible Values:
 """.format(variant)
-        for e in CPU_VARIANTS_EXTENSIONS.items():
+        for e in CPU_VARIANTS_EXTENSIONS:
             msg += " - {}\n".format(e)
         ValueError.__init__(self, msg)
 
@@ -217,8 +217,8 @@ class SoCCore(Module):
 
         # Check for valid CPU extensions.
         for ext in sorted(cpu_variant_ext):
-            if cpu_variant_ext not in CPU_VARIANTS_EXTENSIONS:
-                raise InvalidCPUExtension(cpu_variant)
+            if ext not in CPU_VARIANTS_EXTENSIONS:
+                raise InvalidCPUExtensionError(cpu_variant)
             self.cpu_variant += "+"+ext
 
         if integrated_rom_size:
index 1b0151377467214f98f2d634da6354ebfd4f6e63..eadbd8e6d13a2b3cef091cf0c692cf0617b7d0ca 100644 (file)
@@ -1,3 +1,4 @@
+import subprocess
 import unittest
 import os
 
@@ -6,6 +7,9 @@ from migen import *
 from litex.soc.integration.builder import *
 
 
+RUNNING_ON_TRAVIS = (os.getenv('TRAVIS', 'false').lower() == 'true')
+
+
 def build_test(socs):
     errors = 0
     for soc in socs:
@@ -98,8 +102,54 @@ class TestTargets(unittest.TestCase):
         platforms += ["avalanche"]                                 # PolarFire
 
         for p in platforms:
-            os.system("litex/boards/targets/simple.py litex.boards.platforms." + p +
-                " --cpu-type=vexriscv " +
-                " --no-compile-software " +
-                " --no-compile-gateware " +
-                " --uart-stub=True")
+            with self.subTest(platform=p):
+                cmd = """\
+litex/boards/targets/simple.py litex.boards.platforms.{p} \
+    --cpu-type=vexriscv     \
+    --no-compile-software   \
+    --no-compile-gateware   \
+    --uart-stub=True        \
+""".format(p=p)
+                subprocess.check_call(cmd, shell=True)
+
+    def run_variants(self, cpu, variants):
+        for v in variants:
+            with self.subTest(cpu=cpu, variant=v):
+                self.run_variant(cpu, v)
+
+    def run_variant(self, cpu, variant):
+        cmd = """\
+litex/boards/targets/simple.py litex.boards.platforms.arty \
+    --cpu-type={c}          \
+    --cpu-variant={v}       \
+    --no-compile-software   \
+    --no-compile-gateware   \
+    --uart-stub=True        \
+""".format(c=cpu, v=variant)
+        subprocess.check_output(cmd, shell=True)
+
+    # Build some variants for the arty platform to make sure they work.
+    def test_variants_riscv(self):
+        cpu_variants = {
+            'picorv32': ('standard', 'minimal'),
+            'vexriscv': ('standard', 'minimal', 'lite', 'lite+debug', 'full+debug'),
+            'minerva': ('standard',),
+        }
+        for cpu, variants in cpu_variants.items():
+            self.run_variants(cpu, variants)
+
+    def test_bad_variants(self):
+        with self.assertRaises(subprocess.CalledProcessError):
+            self.run_variant('vexriscv', 'bad')
+
+    def test_bad_variant_extension(self):
+        with self.assertRaises(subprocess.CalledProcessError):
+            self.run_variant('vexriscv', 'standard+bad')
+
+    @unittest.skipIf(RUNNING_ON_TRAVIS, "No lm32 toolchain on Travis-CI")
+    def test_variants_lm32(self):
+        self.run_variants('lm32', ('standard', 'minimal', 'lite'))
+
+    @unittest.skipIf(RUNNING_ON_TRAVIS, "No or1k toolchain on Travis-CI")
+    def test_variants_or1k(self):
+        self.run_variants('or1k', ('standard', 'linux'))