Skip to content

Commit

Permalink
Make tests check CycleElement transactions
Browse files Browse the repository at this point in the history
This makes tests fail if there is any invalid CycleElement transaction
in any of the end-to-end tests.

Currently, tests are failing due to #139.
  • Loading branch information
lupino3 committed May 3, 2017
1 parent ddcd9d4 commit 3cf9657
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/edumips64/ui/common/CycleElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class CycleElement {
private LinkedList<String> states;
private Instruction instruction;

// Boolean storing whether this CycleElement contains one or more invalid transactions.
// Used for testing and debugging purposes.
private boolean hasInvalidTransaction = false;

private static final Logger logger = Logger.getLogger(CycleElement.class.getName());

/**
Expand Down Expand Up @@ -72,13 +76,18 @@ void addState(String newState) {
String lastState = states.getLast();

if (!validateStateTransition(lastState, newState)) {
hasInvalidTransaction = true;
logger.severe("Instruction: " + instruction + ", startTime: " + startTime);
logger.severe("State " + newState + " is not allowed after state " + lastState);
}

states.add(newState);
}

public boolean hasInvalidTransaction() {
return hasInvalidTransaction;
}

/**
* @return the whole list of stages in pipeline
*/
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/edumips64/EndToEndTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.edumips64.core.*;
import org.edumips64.core.is.*;
import org.edumips64.ui.common.CycleBuilder;
import org.edumips64.ui.common.CycleElement;
import org.edumips64.utils.ConfigKey;
import org.edumips64.utils.IrregularStringOfBitsException;
import org.edumips64.utils.io.FileUtils;
Expand Down Expand Up @@ -188,6 +189,13 @@ private CpuTestStatus runMipsTest(String testPath) throws Exception {
dinero.writeTraceData(w);
w.close();

// Check if the transactions in the CycleBuilder are all valid.
for (CycleElement el : builder.getElementsList()) {
if (el.hasInvalidTransaction()) {
throw new InvalidCycleElementTransactionException();
}
}

return new CpuTestStatus(cpu, tmp.getAbsolutePath());
} finally {
cpu.reset();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.edumips64;

/**
* Created by andrea on 03/05/17.
*/
public class InvalidCycleElementTransactionException extends Exception {
}

0 comments on commit 3cf9657

Please sign in to comment.