mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -04:00
refactored integration tests
This commit is contained in:
parent
491938e0c0
commit
4668f42a5f
@ -114,7 +114,7 @@ public class DataField {
|
|||||||
* @param addr the address
|
* @param addr the address
|
||||||
* @return the value
|
* @return the value
|
||||||
*/
|
*/
|
||||||
public long getData(int addr) {
|
public long getDataWord(int addr) {
|
||||||
if (addr >= data.length)
|
if (addr >= data.length)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
|
@ -74,7 +74,7 @@ public class LookUpTable extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
output.setValue(data.getData(addr));
|
output.setValue(data.getDataWord(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public class RAMDualPort extends Node implements Element, RAMInterface {
|
|||||||
@Override
|
@Override
|
||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
if (ld) {
|
if (ld) {
|
||||||
output.set(memory.getData(addr), false);
|
output.set(memory.getDataWord(addr), false);
|
||||||
} else {
|
} else {
|
||||||
output.setHighZ(true);
|
output.setHighZ(true);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class ROM extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
output.set(data.getData(addr), !sel);
|
output.set(data.getDataWord(addr), !sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,7 +144,7 @@ public class DataEditor extends JDialog {
|
|||||||
if (columnIndex == 0) {
|
if (columnIndex == 0) {
|
||||||
return new MyLong((long) rowIndex * cols);
|
return new MyLong((long) rowIndex * cols);
|
||||||
}
|
}
|
||||||
return new MyLong(dataField.getData(rowIndex * cols + (columnIndex - 1)));
|
return new MyLong(dataField.getDataWord(rowIndex * cols + (columnIndex - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,27 +13,27 @@ public class DataFieldTest extends TestCase {
|
|||||||
DataField data = new DataField(100, 8);
|
DataField data = new DataField(100, 8);
|
||||||
data.setData(9, 1);
|
data.setData(9, 1);
|
||||||
data = data.getMinimized();
|
data = data.getMinimized();
|
||||||
assertEquals(1, data.getData(9));
|
assertEquals(1, data.getDataWord(9));
|
||||||
data = data.getMinimized();
|
data = data.getMinimized();
|
||||||
assertEquals(1, data.getData(9));
|
assertEquals(1, data.getDataWord(9));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrow() throws Exception {
|
public void testGrow() throws Exception {
|
||||||
DataField data = new DataField(100, 8);
|
DataField data = new DataField(100, 8);
|
||||||
data.setData(9, 1);
|
data.setData(9, 1);
|
||||||
data = data.getMinimized();
|
data = data.getMinimized();
|
||||||
assertEquals(1, data.getData(9));
|
assertEquals(1, data.getDataWord(9));
|
||||||
data.setData(30, 1);
|
data.setData(30, 1);
|
||||||
assertEquals(1, data.getData(30));
|
assertEquals(1, data.getDataWord(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoad() throws Exception {
|
public void testLoad() throws Exception {
|
||||||
String data = "v2.0 raw\n0\n10\nAA\nFF";
|
String data = "v2.0 raw\n0\n10\nAA\nFF";
|
||||||
DataField df = new DataField(new StringReader(data));
|
DataField df = new DataField(new StringReader(data));
|
||||||
assertEquals(4, df.size());
|
assertEquals(4, df.size());
|
||||||
assertEquals(0x00, df.getData(0));
|
assertEquals(0x00, df.getDataWord(0));
|
||||||
assertEquals(0x10, df.getData(1));
|
assertEquals(0x10, df.getDataWord(1));
|
||||||
assertEquals(0xAA, df.getData(2));
|
assertEquals(0xAA, df.getDataWord(2));
|
||||||
assertEquals(0xFF, df.getData(3));
|
assertEquals(0xFF, df.getDataWord(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,61 +0,0 @@
|
|||||||
package de.neemann.digital.integration;
|
|
||||||
|
|
||||||
import de.neemann.digital.core.Model;
|
|
||||||
import de.neemann.digital.core.NodeException;
|
|
||||||
import de.neemann.digital.core.memory.DataField;
|
|
||||||
import de.neemann.digital.core.memory.RAMSinglePort;
|
|
||||||
import de.neemann.digital.draw.elements.Circuit;
|
|
||||||
import de.neemann.digital.draw.elements.PinException;
|
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
|
||||||
import de.neemann.digital.draw.model.ModelDescription;
|
|
||||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
|
||||||
import de.neemann.digital.gui.LibrarySelector;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hneemann
|
|
||||||
*/
|
|
||||||
public class TestProcessor extends TestCase {
|
|
||||||
|
|
||||||
private Model createModel(String file) throws IOException, PinException, NodeException {
|
|
||||||
File filename = new File(Resources.getRoot(), file);
|
|
||||||
ElementLibrary library = new ElementLibrary();
|
|
||||||
ShapeFactory shapeFactory = new ShapeFactory(library);
|
|
||||||
Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
|
|
||||||
LibrarySelector librarySelector = new LibrarySelector(library, shapeFactory, null);
|
|
||||||
librarySelector.setFilePath(filename.getParentFile());
|
|
||||||
|
|
||||||
ModelDescription md = new ModelDescription(circuit, library);
|
|
||||||
Model model = md.createModel();
|
|
||||||
model.init(true);
|
|
||||||
|
|
||||||
assertTrue(model.isFastRunModel());
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a simulated processor, which has already stored machine program that calculates the 15th
|
|
||||||
* fibonacci number with a simple recursive algorithm. The result (610) is stored in the first RAM word.
|
|
||||||
*
|
|
||||||
* @throws IOException IOException
|
|
||||||
* @throws NodeException NodeException
|
|
||||||
* @throws PinException PinException
|
|
||||||
*/
|
|
||||||
public void testFibonacci() throws IOException, NodeException, PinException {
|
|
||||||
Model model = createModel("dig/processor/Processor_fibonacci.dig");
|
|
||||||
|
|
||||||
assertEquals(98644, model.runToBreak()); // checks the number of cycles needed to calculate 610
|
|
||||||
|
|
||||||
List<RAMSinglePort> ramList = model.findNode(RAMSinglePort.class);
|
|
||||||
assertEquals(1, ramList.size());
|
|
||||||
|
|
||||||
DataField ram = ramList.get(0).getMemory(); // the rams content
|
|
||||||
assertEquals(610, ram.getData(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,34 +1,45 @@
|
|||||||
package de.neemann.digital.integration;
|
package de.neemann.digital.integration;
|
||||||
|
|
||||||
import de.neemann.digital.core.Model;
|
|
||||||
import de.neemann.digital.core.NodeException;
|
import de.neemann.digital.core.NodeException;
|
||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.core.memory.RAMSinglePort;
|
||||||
|
import de.neemann.digital.core.memory.Register;
|
||||||
import de.neemann.digital.draw.elements.PinException;
|
import de.neemann.digital.draw.elements.PinException;
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
|
||||||
import de.neemann.digital.draw.model.ModelDescription;
|
|
||||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class TestRunToBreak extends TestCase {
|
public class TestRunToBreak extends TestCase {
|
||||||
private ElementLibrary library = new ElementLibrary();
|
|
||||||
|
|
||||||
public void testRunToBreak() throws IOException, NodeException, PinException {
|
public void testRunToBreak() throws IOException, NodeException, PinException {
|
||||||
File filename = new File(Resources.getRoot(), "dig/runToBreak.dig");
|
new ToBreakRunner("dig/runToBreak.dig")
|
||||||
Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
|
.runToBreak(511);
|
||||||
|
}
|
||||||
|
|
||||||
ModelDescription md = new ModelDescription(circuit, library);
|
public void testCounterSplitter() throws IOException, NodeException, PinException {
|
||||||
Model model = md.createModel();
|
Register r = new ToBreakRunner("dig/CounterSplitter.dig")
|
||||||
model.init(true);
|
.runToBreak(2047)
|
||||||
|
.getSingleNode(Register.class);
|
||||||
|
|
||||||
assertTrue(model.isFastRunModel());
|
assertEquals(0x3ff, r.getOutputs()[0].getValue());
|
||||||
int halfClocks = model.runToBreak();
|
}
|
||||||
assertEquals(511, halfClocks);
|
|
||||||
|
/**
|
||||||
|
* Loads a simulated processor, which has already stored a machine program that calculates the 15th
|
||||||
|
* fibonacci number with a simple recursive algorithm. The result (610) is stored in the first RAM word.
|
||||||
|
*
|
||||||
|
* @throws IOException IOException
|
||||||
|
* @throws NodeException NodeException
|
||||||
|
* @throws PinException PinException
|
||||||
|
*/
|
||||||
|
public void testFibonacci() throws IOException, NodeException, PinException {
|
||||||
|
RAMSinglePort ram = new ToBreakRunner("dig/processor/Processor_fibonacci.dig")
|
||||||
|
.runToBreak(98644)
|
||||||
|
.getSingleNode(RAMSinglePort.class);
|
||||||
|
|
||||||
|
assertEquals(610, ram.getMemory().getDataWord(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package de.neemann.digital.integration;
|
||||||
|
|
||||||
|
import de.neemann.digital.core.Model;
|
||||||
|
import de.neemann.digital.core.Node;
|
||||||
|
import de.neemann.digital.core.NodeException;
|
||||||
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
|
import de.neemann.digital.draw.elements.PinException;
|
||||||
|
import de.neemann.digital.draw.library.ElementLibrary;
|
||||||
|
import de.neemann.digital.draw.model.ModelDescription;
|
||||||
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
|
import de.neemann.digital.gui.LibrarySelector;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public class ToBreakRunner {
|
||||||
|
|
||||||
|
private final Model model;
|
||||||
|
|
||||||
|
public ToBreakRunner(String file) throws IOException, PinException, NodeException {
|
||||||
|
File filename = new File(Resources.getRoot(), file);
|
||||||
|
ElementLibrary library = new ElementLibrary();
|
||||||
|
ShapeFactory shapeFactory = new ShapeFactory(library);
|
||||||
|
Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
|
||||||
|
LibrarySelector librarySelector = new LibrarySelector(library, shapeFactory, null);
|
||||||
|
librarySelector.setFilePath(filename.getParentFile());
|
||||||
|
|
||||||
|
ModelDescription md = new ModelDescription(circuit, library);
|
||||||
|
model = md.createModel();
|
||||||
|
model.init(true);
|
||||||
|
|
||||||
|
assertTrue(model.isFastRunModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToBreakRunner runToBreak(int steps) throws NodeException {
|
||||||
|
assertEquals(steps, model.runToBreak());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Node> T getSingleNode(Class<T> clazz) {
|
||||||
|
List<T> nodes = model.findNode(clazz);
|
||||||
|
assertEquals(1, nodes.size());
|
||||||
|
return nodes.get(0);
|
||||||
|
}
|
||||||
|
}
|
203
src/test/resources/dig/CounterSplitter.dig
Normal file
203
src/test/resources/dig/CounterSplitter.dig
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<circuit>
|
||||||
|
<version>1</version>
|
||||||
|
<visualElements>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Clock</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="120" y="180"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Counter</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Bits</string>
|
||||||
|
<int>5</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="180" y="180"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Value</string>
|
||||||
|
<int>0</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="160" y="200"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Counter</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Bits</string>
|
||||||
|
<int>5</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="180" y="280"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Splitter</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Input Splitting</string>
|
||||||
|
<string>5,5</string>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>Output Splitting</string>
|
||||||
|
<string>10</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="320" y="180"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Break</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="320" y="300"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Register</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Bits</string>
|
||||||
|
<int>10</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="400" y="180"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Out</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Bits</string>
|
||||||
|
<int>10</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="480" y="200"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Value</string>
|
||||||
|
<int>0</int>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="160" y="300"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Not</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="320" y="220"/>
|
||||||
|
<rotate>0</rotate>
|
||||||
|
</visualElement>
|
||||||
|
</visualElements>
|
||||||
|
<wires>
|
||||||
|
<wire>
|
||||||
|
<p1 x="120" y="180"/>
|
||||||
|
<p2 x="160" y="180"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="240" y="180"/>
|
||||||
|
<p2 x="320" y="180"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="340" y="180"/>
|
||||||
|
<p2 x="400" y="180"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="180"/>
|
||||||
|
<p2 x="180" y="180"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="260"/>
|
||||||
|
<p2 x="260" y="260"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="240" y="200"/>
|
||||||
|
<p2 x="260" y="200"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="280" y="200"/>
|
||||||
|
<p2 x="320" y="200"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="460" y="200"/>
|
||||||
|
<p2 x="480" y="200"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="200"/>
|
||||||
|
<p2 x="180" y="200"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="380" y="200"/>
|
||||||
|
<p2 x="400" y="200"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="280"/>
|
||||||
|
<p2 x="180" y="280"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="240" y="280"/>
|
||||||
|
<p2 x="280" y="280"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="240" y="300"/>
|
||||||
|
<p2 x="300" y="300"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="300"/>
|
||||||
|
<p2 x="180" y="300"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="300" y="300"/>
|
||||||
|
<p2 x="320" y="300"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="360" y="220"/>
|
||||||
|
<p2 x="400" y="220"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="300" y="220"/>
|
||||||
|
<p2 x="320" y="220"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="140"/>
|
||||||
|
<p2 x="380" y="140"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="260"/>
|
||||||
|
<p2 x="160" y="280"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="160" y="140"/>
|
||||||
|
<p2 x="160" y="180"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="260" y="200"/>
|
||||||
|
<p2 x="260" y="260"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="280" y="200"/>
|
||||||
|
<p2 x="280" y="280"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="300" y="220"/>
|
||||||
|
<p2 x="300" y="300"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="380" y="140"/>
|
||||||
|
<p2 x="380" y="200"/>
|
||||||
|
</wire>
|
||||||
|
</wires>
|
||||||
|
</circuit>
|
Loading…
x
Reference in New Issue
Block a user