Added a config regression test

This commit is contained in:
hneemann 2019-05-21 08:26:27 +02:00
parent 9835a36263
commit b0f47458fd
3 changed files with 126 additions and 1 deletions

View File

@ -126,7 +126,7 @@ public class ConfigurationTest extends TestCase {
throw new RuntimeException(command.getName(), e);
}
private void clear() {
void clear() {
files.clear();
commands.clear();
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>D_FF</elementName>
<elementAttributes/>
<pos x="460" y="220"/>
</visualElement>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>CLK</string>
</entry>
<entry>
<string>Frequency</string>
<int>200</int>
</entry>
<entry>
<string>runRealTime</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="420" y="240"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>Q</string>
</entry>
</elementAttributes>
<pos x="560" y="220"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="520" y="240"/>
<p2 x="540" y="240"/>
</wire>
<wire>
<p1 x="420" y="240"/>
<p2 x="460" y="240"/>
</wire>
<wire>
<p1 x="440" y="180"/>
<p2 x="540" y="180"/>
</wire>
<wire>
<p1 x="440" y="220"/>
<p2 x="460" y="220"/>
</wire>
<wire>
<p1 x="520" y="220"/>
<p2 x="560" y="220"/>
</wire>
<wire>
<p1 x="440" y="180"/>
<p2 x="440" y="220"/>
</wire>
<wire>
<p1 x="540" y="180"/>
<p2 x="540" y="240"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>