Unit Tests

This commit is contained in:
2025-04-25 15:18:36 +02:00
parent ca36cffd47
commit ac854ed4f1
13 changed files with 399 additions and 39 deletions

View File

@ -4,6 +4,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
public class Commands extends PICComponent implements CommandInterface {
private int wRegister;
private long totalExecutionTime;
private double executionTimeMultiplier = 1;
public Commands(){
super();
@ -22,7 +23,7 @@ public class Commands extends PICComponent implements CommandInterface {
}
public double getTotalExecutionTime() {
return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
return (totalExecutionTime * getExecutionTimeMultiplier());
}
public void resetTotalExecutionTime() {
@ -248,8 +249,6 @@ public class Commands extends PICComponent implements CommandInterface {
else{
System.out.println("Nicht gefunden!");
}
}
public void SLEEP() {
@ -557,9 +556,39 @@ public class Commands extends PICComponent implements CommandInterface {
}
}
public double getExecutionTimeMultiplier(){
return executionTimeMultiplier;
}
public void setExecutionTimeMultiplier(String option){
switch (option) {
case "8 MHZ":
executionTimeMultiplier = 0.5;
break;
case "4 MHZ":
executionTimeMultiplier = 1;
break;
case "1 MHZ":
executionTimeMultiplier = 4;
break;
case "500 HZ":
executionTimeMultiplier = 8;
break;
case "100 HZ":
executionTimeMultiplier = 40;
break;
case "32 HZ":
executionTimeMultiplier = 125;
break;
}
}
@Override
public void initialize(PICComponents picComponents) {
System.out.println("Commands");
super.initialize(picComponents);
}
}

View File

@ -43,13 +43,6 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
private int [][] read;
private int [] ind;
private PICComponents picComponents;
private double executionTimeMultiplier = 1;
public double getExecutionTimeMultiplier(){
return executionTimeMultiplier;
}
private boolean isBreakpointReached = false;
@ -160,29 +153,7 @@ public class Controller_Frontend extends PICComponent implements FrontendControl
private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue();
switch (selectedOption) {
case "8 MHZ":
executionTimeMultiplier = 0.5;
break;
case "4 MHZ":
executionTimeMultiplier = 1;
break;
case "1 MHZ":
executionTimeMultiplier = 4;
break;
case "500 HZ":
executionTimeMultiplier = 8;
break;
case "100 HZ":
executionTimeMultiplier = 40;
break;
case "32 HZ":
executionTimeMultiplier = 125;
break;
}
commands.setExecutionTimeMultiplier(selectedOption);
}
@FXML

View File

@ -36,6 +36,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
}
public long read (int address) {
if (address < 0) return 0;
FileReader reader;
try {
reader = new FileReader("eeprom.json");
@ -60,6 +61,7 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
}
public void write (int address, long data) {
if (address < 0) return;
FileReader reader;
try {
reader = new FileReader("eeprom.json");
@ -172,7 +174,6 @@ public class EEPROM extends PICComponent implements EEPROMInterface {
@Override
public void initialize(PICComponents picComponents) {
System.out.println("EEPROM");
super.initialize(picComponents);
}
}

View File

@ -5,7 +5,7 @@ import fabrik.simulator.pic16f84.interfaces.*;
public abstract class PICComponent {
DataRegisterInterface dataRegister;
EEPROMInterface eeprom;
PreScaler preScaler;
PreScalerInterface preScaler;
IOPortInterface ioPorts;
TimerInterface timer;
InterruptInterface interrupts;
@ -22,7 +22,7 @@ public abstract class PICComponent {
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
eeprom = (EEPROMInterface) picComponents.getComponent(EEPROMInterface.class);
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
preScaler = (PreScaler) picComponents.getComponent(PreScalerInterface.class);
preScaler = (PreScalerInterface) picComponents.getComponent(PreScalerInterface.class);
timer = (TimerInterface) picComponents.getComponent(TimerInterface.class);
interrupts = (InterruptInterface) picComponents.getComponent(InterruptInterface.class);
//table = (TableInterface) picComponents.getComponent(TableInterface.class);

View File

@ -26,7 +26,7 @@ public class WatchdogTimer extends PICComponent implements WatchdogTimerInterfac
}
else {
rawtimer++;
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
realtimer = (long) (rawtimer * commands.getExecutionTimeMultiplier());
}
}
}

View File

@ -10,4 +10,10 @@ public interface CommandInterface extends PICComponentInterface {
void decode(int i);
void resetTotalExecutionTime();
void addExecutionTime(int i);
double getExecutionTimeMultiplier();
void setExecutionTimeMultiplier(String option);
}

View File

@ -4,4 +4,8 @@ public interface EEPROMInterface extends PICComponentInterface {
void registerTime(boolean b);
void parse(int i, int content, int i1);
long read(int address);
void write (int address, long data);
}

View File

@ -1,7 +1,6 @@
package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface extends PICComponentInterface {
double getExecutionTimeMultiplier();
void sleep();