diff --git a/TEST-swen90006.machine.BoundaryTests.txt b/TEST-swen90006.machine.BoundaryTests.txt new file mode 100644 index 0000000000000000000000000000000000000000..478cada02ca97ad9a793af2ec33fbc8c719d5f5b --- /dev/null +++ b/TEST-swen90006.machine.BoundaryTests.txt @@ -0,0 +1,16 @@ +Testsuite: swen90006.machine.BoundaryTests +Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.266 sec + +Testcase: register_min_on_point_boundary_test took 0.003 sec +Testcase: register_min_off_point_boundary_test took 0.001 sec +Testcase: register_max_off_point_boundary_test took 0 sec +Testcase: value_min_off_point_boundary_test took 0 sec +Testcase: value_min_on_point_boundary_test took 0.001 sec +Testcase: value_max_off_point_boundary_test took 0.001 sec +Testcase: anotherTest took 0 sec +Testcase: aFileOpenTest took 0.026 sec +Testcase: aTest took 0 sec +Testcase: overflow_max_on_point_boundary_test took 0.21 sec +Testcase: register_max_on_point_boundary_test took 0 sec +Testcase: anExceptionTest took 0 sec +Testcase: value_max_on_point_boundary_test took 0 sec diff --git a/TEST-swen90006.machine.PartitioningTests.txt b/TEST-swen90006.machine.PartitioningTests.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca1768452a9cc4cdeaf09c30e497ae69e2642279 --- /dev/null +++ b/TEST-swen90006.machine.PartitioningTests.txt @@ -0,0 +1,26 @@ +Testsuite: swen90006.machine.PartitioningTests +Tests run: 23, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.072 sec + +Testcase: mov_para_test took 0.002 sec +Testcase: arith_add_para_test took 0.001 sec +Testcase: arith_div_test took 0 sec +Testcase: ldr_str_jmp_jz_test took 0.007 sec +Testcase: ret_para_test took 0 sec +Testcase: arith_mul_test took 0.001 sec +Testcase: arith_sub_para_test took 0 sec +Testcase: ret_test took 0 sec +Testcase: anotherTest took 0.001 sec +Testcase: mov_test took 0 sec +Testcase: aFileOpenTest took 0.024 sec +Testcase: aTest took 0 sec +Testcase: ldr_para_test took 0 sec +Testcase: str_para_test took 0 sec +Testcase: arith_mul_para_test took 0 sec +Testcase: arith_div_para_test took 0.001 sec +Testcase: arith_sub_test took 0.001 sec +Testcase: jz_para_test took 0 sec +Testcase: jmp_para_test took 0.001 sec +Testcase: anExceptionTest took 0 sec +Testcase: no_retrun_test took 0 sec +Testcase: arith_add_test took 0.001 sec +Testcase: infiniteLoop took 2.005 sec diff --git a/classes/swen90006/machine/BoundaryTests.class b/classes/swen90006/machine/BoundaryTests.class index 75ca15dbf4f906cd2b7beec235fa91a8de079579..e8ed9ab0dd8ee8922dea435dfe500460a20698bd 100644 Binary files a/classes/swen90006/machine/BoundaryTests.class and b/classes/swen90006/machine/BoundaryTests.class differ diff --git a/classes/swen90006/machine/PartitioningTests.class b/classes/swen90006/machine/PartitioningTests.class index af52566636122d3ab4edeca3dfd4fb3e867aa1db..ccd57eec247887c54a805dc451aa27ff7c49f306 100644 Binary files a/classes/swen90006/machine/PartitioningTests.class and b/classes/swen90006/machine/PartitioningTests.class differ diff --git a/mutants/mutant-1/swen90006/machine/Machine.java b/mutants/mutant-1/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..9f8349ff4d1884e2f13c35001a87223f89c6dafe 100644 --- a/mutants/mutant-1/swen90006/machine/Machine.java +++ b/mutants/mutant-1/swen90006/machine/Machine.java @@ -106,7 +106,7 @@ public class Machine private int parseReg(String s) throws InvalidInstructionException { - if (s.length() < 2){ + if (s.length() <= 2){ throw new InvalidInstructionException(); } if (s.charAt(0) != 'r'){ diff --git a/mutants/mutant-2/swen90006/machine/Machine.java b/mutants/mutant-2/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..e0040cf5bf8ce1f33bcf98a289f3b84bac5a2b55 100644 --- a/mutants/mutant-2/swen90006/machine/Machine.java +++ b/mutants/mutant-2/swen90006/machine/Machine.java @@ -266,7 +266,7 @@ public class Machine throw new InvalidInstructionException(); } int offs = parseOffset(toks[1]); - pc = pc + offs; + pc = pc - offs; count++; continue; /* avoid default increment of pc below */ } else if (toks[0].equals(INSTRUCTION_JZ)){ diff --git a/mutants/mutant-3/swen90006/machine/Machine.java b/mutants/mutant-3/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..ac758b249ee686ec6de37d6085673fae9ad10e40 100644 --- a/mutants/mutant-3/swen90006/machine/Machine.java +++ b/mutants/mutant-3/swen90006/machine/Machine.java @@ -287,7 +287,7 @@ public class Machine throw new InvalidInstructionException(); } count++; - pc = pc + 1; + pc = pc / 1; } /* got here without returning already... */ diff --git a/mutants/mutant-4/swen90006/machine/Machine.java b/mutants/mutant-4/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..b5e30fece5c128170bb00ca00c1be86950edda9f 100644 --- a/mutants/mutant-4/swen90006/machine/Machine.java +++ b/mutants/mutant-4/swen90006/machine/Machine.java @@ -278,7 +278,7 @@ public class Machine if (regs[ra] == 0){ pc = pc + offs; }else{ - pc = pc + 1; + pc = pc * 1; } count++; continue; /* avoid default increment the pc below */ diff --git a/mutants/mutant-5/swen90006/machine/Machine.java b/mutants/mutant-5/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..fa8eff7d7384130979f1b52a437f59a44e49c23c 100644 --- a/mutants/mutant-5/swen90006/machine/Machine.java +++ b/mutants/mutant-5/swen90006/machine/Machine.java @@ -278,7 +278,7 @@ public class Machine if (regs[ra] == 0){ pc = pc + offs; }else{ - pc = pc + 1; + pc = pc / 1; } count++; continue; /* avoid default increment the pc below */ diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 61ce1ca647f325fbf452047408c1e22d9befcb99..c38691644ea1f8a259df734e18d295aa0d9e11d2 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -34,6 +34,119 @@ public class BoundaryTests assertEquals(expected, actual); } + @Test + public void value_min_on_point_boundary_test() { + ArrayList var1 = new ArrayList(); + var1.add("MOV R1 -65535"); + var1.add("RET R1"); + Machine var2 = new Machine(); + Assert.assertEquals((long)var2.execute(var1), -65535); + } + + @Test(expected = InvalidInstructionException.class) + public void value_min_off_point_boundary_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 -65536"); + lines.add("RET R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test + public void value_max_on_point_boundary_test() { + ArrayList var1 = new ArrayList(); + var1.add("MOV R1 65535"); + var1.add("RET R1"); + Machine var2 = new Machine(); + Assert.assertEquals((long)var2.execute(var1), 65535); + } + + + @Test(expected = InvalidInstructionException.class) + public void value_max_off_point_boundary_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 65536"); + lines.add("RET R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test(expected = InvalidInstructionException.class) + public void register_max_off_point_boundary_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R-1 1"); + lines.add("RET R-1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test(expected = InvalidInstructionException.class) + public void register_min_off_point_boundary_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R32 1"); + lines.add("RET R32"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test + public void register_min_on_point_boundary_test() { + ArrayList var1 = new ArrayList(); + var1.add("MOV R0 1"); + var1.add("RET R0"); + Machine var2 = new Machine(); + Assert.assertEquals((long)var2.execute(var1), 1); + } + + @Test + public void register_max_on_point_boundary_test() { + ArrayList var1 = new ArrayList(); + var1.add("MOV R31 1"); + var1.add("RET R31"); + Machine var2 = new Machine(); + Assert.assertEquals((long)var2.execute(var1), 1); + } + + + // Should overflow, but the system does not give a correct answer? + @Test + public void overflow_max_on_point_boundary_test() { + ArrayList var1 = new ArrayList(); + var1.add("MOV R3 4000"); + var1.add("MOV R2 1"); + var1.add("MOV R1 0"); + var1.add("MOV R0 100"); + var1.add("SUB R4 R3 R1"); + var1.add("JZ R4 5"); + var1.add("STR R0 0 R1"); + var1.add("ADD R1 R1 R2"); + var1.add("ADD R0 R0 R2"); + var1.add("JMP -5"); + var1.add("MOV R1 0"); + var1.add("MOV R0 100"); + var1.add("MOV R5 0"); + var1.add("SUB R4 R3 R1"); + var1.add("JZ R4 6"); + var1.add("LDR R4 R0 0"); + var1.add("ADD R5 R5 R4"); + var1.add("ADD R0 R0 R2"); + var1.add("ADD R1 R1 R2"); + var1.add("JMP -6"); + var1.add("RET R5"); + Machine var2 = new Machine(); + Assert.assertEquals((long)var2.execute(var1), 7998000); + } + + + @Test public void anotherTest() { List<String> list = new ArrayList<String>(); @@ -63,13 +176,13 @@ public class BoundaryTests //This test should fail. //To provide additional feedback when a test fails, an error message //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); - } +// @Test public void aFailedTest() +// { +// //include a message for better feedback +// final int expected = 2; +// final int actual = 1 + 2; +// assertEquals("Some failure message", expected, actual); +// } //Read in a file containing a program and convert into a list of //string instructions diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 5494b44f4615351a610fc7b0b649d30b4b2d0a40..e86233a84f917428162dbc6852e2f948fab03114 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -6,8 +6,11 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Files; import java.nio.file.FileSystems; +import java.util.concurrent.TimeoutException; import org.junit.*; +import org.omg.CORBA.DynAnyPackage.Invalid; + import static org.junit.Assert.*; public class PartitioningTests @@ -24,6 +27,291 @@ public class PartitioningTests { } + // ======= 10 operands ======= + // Arithmetic: ADD/SUB/MUL/DIV + @Test(expected = InvalidInstructionException.class) + public void arith_add_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("ADD R3 R1"); + lines.add("ADD R3"); + lines.add("ADD"); + lines.add("ADD R3 R1 R4 R5"); + lines.add("RET R3"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void arith_add_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("ADD R3 R1 R2"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); + } + + @Test(expected = InvalidInstructionException.class) + public void arith_sub_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("SUB R3 R1"); + lines.add("SUB R3"); + lines.add("SUB"); + lines.add("SUB R3 R1 R4 R5"); + lines.add("RET R3"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void arith_sub_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("SUB R3 R1 R2"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(m.execute(lines), -1); + } + + @Test(expected = InvalidInstructionException.class) + public void arith_mul_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("MUL R3 R1"); + lines.add("MUL R3"); + lines.add("MUL"); + lines.add("MUL R3 R1 R4 R5"); + lines.add("RET R3"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void arith_mul_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 -2"); + lines.add("MOV R2 -3"); + lines.add("MUL R3 R1 R2"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 6); + } + + @Test(expected = InvalidInstructionException.class) + public void arith_div_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV R2 3"); + lines.add("DIV R3 R1"); + lines.add("DIV R3"); + lines.add("DIV"); + lines.add("DIV R3 R1 R4 R5"); + lines.add("RET R3"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void arith_div_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 -9"); + lines.add("MOV R2 3"); + lines.add("DIV R3 R1 R2"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(m.execute(lines), -3); + } + + @Test(expected = InvalidInstructionException.class) + public void mov_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 2"); + lines.add("MOV "); + lines.add("MOV R1"); + lines.add("MOV 2"); + lines.add("RET R3"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void mov_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R0 2"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 2); + } + + @Test(expected = InvalidInstructionException.class) + public void ret_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("RET"); + lines.add("RET R3 R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test public void ret_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 0); + } + + @Test(expected = InvalidInstructionException.class) + public void ldr_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("LDR"); + lines.add("LDR R1 2"); + lines.add("LDR R1 R2 0 R3"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test(expected = InvalidInstructionException.class) + public void str_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("STR"); + lines.add("STR 2"); + lines.add("STR R1 3"); + lines.add("STR R1 R2 0 R3"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test(expected = InvalidInstructionException.class) + public void jmp_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("JMP"); + lines.add("JMP R1 3"); + lines.add("JMP R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test(expected = InvalidInstructionException.class) + public void jz_para_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("JZ"); + lines.add("JZ 3"); + lines.add("JZ R5"); + lines.add("JZ R0 5 10"); + lines.add("JZ 5 10"); + Machine m = new Machine(); + m.execute(lines); + } + + public void jmp_jz_pair_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R3 10"); + lines.add("MOV R2 1"); + lines.add("MOV R1 0"); + lines.add("MOV R0 100"); + lines.add("SUB R4 R3 R1"); + lines.add("JZ R4 5"); + lines.add("STR R0 0 R1"); + lines.add("ADD R1 R1 R2"); + lines.add("ADD R0 R0 R2"); + lines.add("JMP -3"); + + lines.add("MOV R1 0"); + lines.add("MOV R0 100"); + lines.add("MOV R5 0"); + + lines.add("LDR R4 R0 2"); + lines.add("ADD R5 R5 R4"); + + lines.add("RET R5"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 0); + } + + @Test + public void infiniteLoop() throws Exception { + Thread t = new Thread(new Runnable() { + public void run() { + jmp_jz_pair_test(); + } + }); + t.start(); + t.join(2000); + assertTrue(t.isAlive()); + t.interrupt(); // dont know if this works + } + + @Test public void ldr_str_jmp_jz_test() + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R3 10"); + lines.add("MOV R2 1"); + lines.add("MOV R1 0"); + lines.add("MOV R0 100"); + lines.add("SUB R4 R3 R1"); + lines.add("JZ R4 5"); + lines.add("STR R0 0 R1"); + lines.add("ADD R1 R1 R2"); + lines.add("ADD R0 R0 R2"); + lines.add("JMP -5"); + lines.add("MOV R1 0"); + lines.add("MOV R0 100"); + lines.add("MOV R5 0"); + lines.add("SUB R4 R3 R1"); + lines.add("JZ R4 6"); + lines.add("LDR R4 R0 0"); + lines.add("ADD R5 R5 R4"); + lines.add("ADD R0 R0 R2"); + lines.add("ADD R1 R1 R2"); + lines.add("JMP -6"); + lines.add("RET R5"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 45); + } + + + @Test(expected = NoReturnValueException.class) + public void no_retrun_test() + throws Throwable + { + final List<String> lines = new ArrayList<String>();; + lines.add("MOV R1 10"); + lines.add("MOV R2 10"); + Machine m = new Machine(); + m.execute(lines); + } + + //Any method annotation with "@Test" is executed as a test. @Test public void aTest() { @@ -63,13 +351,13 @@ public class PartitioningTests //This test should fail. //To provide additional feedback when a test fails, an error message //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); - } +// @Test public void aFailedTest() +// { +// //include a message for better feedback +// final int expected = 2; +// final int actual = 1 + 2; +// assertEquals("Some failure message", expected, actual); +// } //Read in a file containing a program and convert into a list of //string instructions @@ -87,4 +375,6 @@ public class PartitioningTests } return lines; } + + }