added consistency check for 74xx circuits

This commit is contained in:
hneemann 2017-05-13 21:43:28 +02:00
parent cb11ce8cca
commit e6d50cc87d
15 changed files with 1143 additions and 8 deletions

View File

@ -6,6 +6,10 @@
<string>isDIL</string>
<boolean>true</boolean>
</entry>
<entry>
<string>Description</string>
<string>Dual 4-bit D-type latches</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>

View File

@ -8,7 +8,7 @@
</entry>
<entry>
<string>Description</string>
<string>3-line to 8-line decoder/demultiplexer</string>
<string>3-line to 8-line decoder/demultiplexer, inverted out</string>
</entry>
<entry>
<string>lockedMode</string>

View File

@ -8,7 +8,11 @@
</entry>
<entry>
<string>Description</string>
<string>3-line to 8-line decoder/demultiplexer</string>
<string>Dual 2-line to 4-line decoder/demultiplexer</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,10 @@ counter; synchronous reset</string>
<alpha>255</alpha>
</awt-color>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>

View File

@ -6,6 +6,10 @@
<string>isDIL</string>
<boolean>true</boolean>
</entry>
<entry>
<string>Description</string>
<string>8-BIT SHIFT REGISTERS</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>

View File

@ -10,6 +10,10 @@
<string>Description</string>
<string>3-line to 8-line decoder/demultiplexer</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>

View File

@ -10,6 +10,10 @@
<string>Description</string>
<string>DUAL 5-INPUT NOR GATE</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>

View File

@ -8,7 +8,11 @@
</entry>
<entry>
<string>Description</string>
<string>BCD to 7-segment decoder</string>
<string>BCD to 7-segment decoder, active high</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>

View File

@ -8,7 +8,11 @@
</entry>
<entry>
<string>Description</string>
<string>BCD to 7-segment decoder</string>
<string>BCD to 7-segment decoder, active low</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>

View File

@ -10,6 +10,10 @@
<string>Description</string>
<string>2-Input/3-Input And-Or invert Gate</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>

View File

@ -10,6 +10,10 @@
<string>Description</string>
<string>DUAL J-K FLIP-FLOPS WITH PRESET AND CLEAR</string>
</entry>
<entry>
<string>lockedMode</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>

View File

@ -44,7 +44,7 @@ public class FileScanner {
if (f.getName().endsWith(".dig")) {
try {
test.check(f);
} catch (Exception e) {
} catch (Throwable e) {
errors.add(new Error(f, e));
}
count++;
@ -62,9 +62,9 @@ public class FileScanner {
private static class Error {
private final File f;
private final Exception e;
private final Throwable e;
private Error(File f, Exception e) {
private Error(File f, Throwable e) {
this.f = f;
this.e = e;
}

View File

@ -0,0 +1,79 @@
package de.neemann.digital.integration;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.core.io.In;
import de.neemann.digital.core.io.Out;
import de.neemann.digital.draw.elements.Circuit;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.library.ElementNotFoundException;
import junit.framework.TestCase;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
/**
* Tests the files in the 74xx/lib folder for consistency.
* Created by hneemann on 13.05.17.
*/
public class Test74xx extends TestCase {
private HashMap<String, File> descrMap;
public void test74xx() throws Exception {
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig/74xx/lib");
descrMap = new HashMap<>();
new FileScanner(this::check).scan(examples);
}
private void check(File dig) throws PinException, NodeException, ElementNotFoundException, IOException {
System.out.println(dig);
Circuit circuit = new ToBreakRunner(dig).getCircuit();
assertTrue("is not DIL", circuit.getAttributes().get(Keys.IS_DIL));
assertTrue("is not locked", circuit.getAttributes().get(Keys.LOCKED_MODE));
final String descr = circuit.getAttributes().get(Keys.DESCRIPTION);
assertTrue("missing description", descr.length() > 0);
File f = descrMap.get(descr);
if (f != null)
fail("duplicate description '"+descr+"' in " + f + " and " + dig);
descrMap.put(descr, dig);
PinChecker pc = new PinChecker();
for (VisualElement e : circuit.getElements()) {
if (e.equalsDescription(In.DESCRIPTION))
pc.checkPin(e);
if (e.equalsDescription(Out.DESCRIPTION))
pc.checkPin(e);
}
}
private class PinChecker {
private final HashSet<Integer> pinMap;
private final HashSet<String> nameMap;
private PinChecker() {
pinMap = new HashSet<>();
nameMap = new HashSet<>();
}
private void checkPin(VisualElement e) {
int pn = e.getElementAttributes().get(Keys.PINNUMBER);
final String label = e.getElementAttributes().getLabel();
assertTrue("missing pin number: " + label, pn != 0);
assertFalse("non unique pin number: " + pn, pinMap.contains(pn));
pinMap.add(pn);
assertFalse("non unique pin name: " + label, nameMap.contains(label));
nameMap.add(label);
assertTrue("missing pin label", label.length() > 0);
}
}
}

View File

@ -28,7 +28,7 @@ public class TestExamples extends TestCase {
*/
public void testDistExamples() throws Exception {
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig");
assertEquals(144, new FileScanner(this::check).scan(examples));
assertEquals(145, new FileScanner(this::check).scan(examples));
assertEquals(74, testCasesInFiles);
}