From b0f47458fd3897b45390b3a652dc57dd9bb7248a Mon Sep 17 00:00:00 2001 From: hneemann Date: Tue, 21 May 2019 08:26:27 +0200 Subject: [PATCH] Added a config regression test --- .../digital/toolchain/ConfigurationTest.java | 2 +- .../digital/toolchain/RegressionTest.java | 54 ++++++++++++++ src/test/resources/toolchain/ff.dig | 71 +++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/test/java/de/neemann/digital/toolchain/RegressionTest.java create mode 100644 src/test/resources/toolchain/ff.dig diff --git a/src/test/java/de/neemann/digital/toolchain/ConfigurationTest.java b/src/test/java/de/neemann/digital/toolchain/ConfigurationTest.java index a3ff07647..8fbdad29e 100644 --- a/src/test/java/de/neemann/digital/toolchain/ConfigurationTest.java +++ b/src/test/java/de/neemann/digital/toolchain/ConfigurationTest.java @@ -126,7 +126,7 @@ public class ConfigurationTest extends TestCase { throw new RuntimeException(command.getName(), e); } - private void clear() { + void clear() { files.clear(); commands.clear(); } diff --git a/src/test/java/de/neemann/digital/toolchain/RegressionTest.java b/src/test/java/de/neemann/digital/toolchain/RegressionTest.java new file mode 100644 index 000000000..58ad6dca1 --- /dev/null +++ b/src/test/java/de/neemann/digital/toolchain/RegressionTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.toolchain; + +import de.neemann.digital.core.element.Keys; +import de.neemann.digital.core.wiring.Clock; +import de.neemann.digital.draw.elements.VisualElement; +import de.neemann.digital.integration.FileScanner; +import de.neemann.digital.integration.Resources; +import de.neemann.digital.integration.ToBreakRunner; +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; + +/** + * Runs all the commands in all configs in the hdl folder. + * Tests only the file creation and ensures the templates are ok. + * Does not ensure the generated files are correct! + */ +public class RegressionTest extends TestCase { + private ToBreakRunner br; + private int[] frequencies = new int[]{20, 10000000}; + private VisualElement clock; + private ConfigurationTest.TestIOInterface ioInterface; + + public void testSimple() throws Exception { + ioInterface = new ConfigurationTest.TestIOInterface(); + br = new ToBreakRunner(new File(Resources.getRoot(), "toolchain/ff.dig")); + clock = br.getCircuit().findElements(v -> v.equalsDescription(Clock.DESCRIPTION)).get(0); + File root = new File(Resources.getRoot(), "../../main/dig/hdl"); + int fc = new FileScanner(this::doCheck).setSuffix(".config").scan(root); + + assertEquals(3, fc); + } + + private void doCheck(File f) throws IOException, InterruptedException { + Configuration configuration = Configuration.load(f) + .setFilenameProvider(() -> new File("z/test.dig")) + .setLibraryProvider(br::getLibrary) + .setCircuitProvider(br::getCircuit) + .setIoInterface(ioInterface); + + for (int freq : frequencies) { + ioInterface.clear(); + clock.setAttribute(Keys.FREQUENCY, freq); + for (Command command : configuration.getCommands()) + configuration.executeCommand(command, null).join(); + } + } +} diff --git a/src/test/resources/toolchain/ff.dig b/src/test/resources/toolchain/ff.dig new file mode 100644 index 000000000..d118692d8 --- /dev/null +++ b/src/test/resources/toolchain/ff.dig @@ -0,0 +1,71 @@ + + + 1 + + + + D_FF + + + + + Clock + + + Label + CLK + + + Frequency + 200 + + + runRealTime + true + + + + + + Out + + + Label + Q + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file