From 766f3154fcfa56849d06d746ccdabb7f6a2b0eb4 Mon Sep 17 00:00:00 2001 From: Junhan Yang <junhany@student.unimelb.edu.au> Date: Thu, 30 Aug 2018 17:16:56 +1000 Subject: [PATCH] Task 2 implementation --- .../swen90006/machine/PartitioningTests.class | Bin 2229 -> 5355 bytes test/swen90006/machine/PartitioningTests.java | 504 ++++++++++++++++-- 2 files changed, 460 insertions(+), 44 deletions(-) diff --git a/classes/swen90006/machine/PartitioningTests.class b/classes/swen90006/machine/PartitioningTests.class index af52566636122d3ab4edeca3dfd4fb3e867aa1db..209c3ac177b18c8da68af96be8ead1f6b97dc2bc 100644 GIT binary patch literal 5355 zcmX^0Z`VEs1_l#`{ag$_3?=LgrCbb53?&>4W!wzq3>EAQm0S#L3?(3<ii4q=gQ13l zp_YT8j+FrdxVRYV85%ek8aWu6I2f8a7+N?OS~(cnI2hVF7&<r@Iyo4+I2gJ)7<xDu zdN~;SVEULj82ULFCU7uJgo!Y5FihfLn9RX2h4nuK{N-Sn%E2&=gJC)c!we3FnH&tW zI2dMgFwEg#n9IR152lfogJC`g!vYS5g&YivI2aalFf8F<Sjxe$jDul02g3>uhLs!) zt2h`|b1<yoU|7q+u#SUaJqN=E4u*{!44XI@HnTHqVQ1LN$iQZknU`5&$H>5}p&7== zz~Y>rlFG=yTAW%ETENI48C05Al9`(tmRX#cl#}Y1mzQ6XSdy8aSIo#D<da{NuAfz! zmsz6kl$w@blxoe$z)_N#Smcslp2x@_h$QcrR+3s|&B!2<mmlOB;+a=mQdF7@GAAUp zxP*~`%e5jowE)B~W@p&O$RL2E6{G@WaB4+CYH~?x3L}G-PjPu_o~40-fth}8Vsb`i zUaG!deo$&jX;EHSVoqr)+%#)O2Jzg|oRUmzmdd79q$Zb^q=x2Y=jE5@VK_=3i#48k zWr;bNDM)IO?NZ3gFLA|hs8DfkVopv_YH@mIaY<?s$a9PgLOF>=>8WUfqF}+W#2jD$ zFvq-<AlDFxVo|UOnBro2`9-;jIhYdcjxH_`t?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46&9yEx*VwF*lWwK@W=>XoAP$ zS8GNFNw8-@a-itY2W8UW%HopL++s!suJqIrm(;Yx(wq`T1{n<`bI{aUBZnuN93umJ zdTL2PVo3%ggEbb{MPp_bbc;Zmtzn4^#i_-N3_PG*@0gS0lbM%V%*fyXwF0gTtQlel zNDM8uv6TkM=^Pvsj10`FMMcQPP(V>;UP*9CQEFl?++msd`bffz4D1CUMLBtl45Cms zAx9i2!ui1}z-3PeDE%`sNI+Ghnq>`A%#vD>SprHco|<6{iVUg@YT#OklYtRburM$( zXfiM`2r@7-FfuSOuxf2*VB82+z{sG*puxZdmgZ$(082xqv>6x}*cccYbil&8gp}!l zmFdHki7~J+Ff%YPaEUN5i7+tjU|@mR2s73Itlki=-iU#Tfr){EL2Wk!YvgtYHXm&v z_MHqIObp@LLYy!L`%VTfCWajh+}O-Af}5oQwOd9@h-W(kug`7<zR2wi{JuKc+ZY5| zMHmEexW<@4gMk?w79tEx;IQD>%^)1Pok3(jIJ8U{7#LU>7#U0%K)&E+U}P|0U}P{$ zW-w=9WUzo+FTubH_BxM{DA@C2I~XJ|9n1tOqM<>b#=y(~s^pD@BzG`K`7-+LV35{k z-pe4fjX_pt2ZNm7at28&mQ4%_LW<iMlq5l{Z4AmRI~Y`SH!v_Va4<+PNHfSYFfv#( rFfd3mF#TtcW?*4wuwiGgWoNKsXRv2rWM^;?WpHF*U|?c!VqgFO^ePw# diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 5494b44..ca837b3 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -1,5 +1,15 @@ package swen90006.machine; +/* +* University of Melbourne +* SWEN90006 Software Testing and Reliability +* Semester 2 - 2018 +* Assignment 1 +* Author: Junhan Yang +* Login: junhany +* StudentID: 777738 +*/ + import java.util.List; import java.util.ArrayList; import java.nio.charset.Charset; @@ -12,79 +22,485 @@ import static org.junit.Assert.*; public class PartitioningTests { - //Any method annotated with "@Before" will be executed before each test, + // EC refers to equivalent class. + // These test cases are created to test equivalent classes derived from + //the test template tree drawn by the author from Task 1 + //using Equivalent Partitioning method. + + // Any method annotated with "@Before" will be executed before each test, //allowing the tester to set up some shared resources. @Before public void setUp() { } - //Any method annotated with "@After" will be executed after each test, + // Any method annotated with "@After" will be executed after each test, //allowing the tester to release any shared resources used in the setup. @After public void tearDown() { } - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() + // For EC1: + // This test aims to test the Machine's behaviour + //when there do not exist any RET instruction. + // The Machine's expected behaviour is to raise a NoReturnValueException. + @Test(expected = NoReturnValueException.class) + public void noRETInstructionTest() + throws Throwable { - //the assertEquals method used to check whether two values are - //equal, using the equals method - final int expected = 2; - final int actual = 1 + 1; - assertEquals(expected, actual); + List<String> lines = new ArrayList<String>(); + lines.add("MOV R1 10"); + Machine m = new Machine(); + m.execute(lines); } - @Test public void anotherTest() + // For EC2: + // This test aims to test the Machine's behaviour + //when there exist multiple RET instructions. + // We need to use MOV to closely verify such condition, so we assume that + //MOV executes correctly. + // The Machine's expected behaviour is to return the register's value from + //the first RET, and the remaining instructions after the first RET + //shouldn't be executed. + @Test public void multiRETInstructionTest() { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); + String err_msg = "Machine does not return the first RET value."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R1 10"); + lines.add("RET R1"); + lines.add("MOV R2 20"); + lines.add("RET R2"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 10); + } - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); + // For EC3: + // This test aims to test the Machine's behaviour + //when there exist unknown instructions that is + //attempting to be executed. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test(expected = InvalidInstructionException.class) + public void executeUnknownInstructionTest() + throws Throwable + { + String unknown_ins = "FOO R0 100"; + List<String> lines = new ArrayList<String>(); + lines.add(unknown_ins); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); } - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() + // For EC4: + // This test aims to test the Machine's behaviour + //when there exist unknown instructions that is not + //attempting to be executed. + // The Machine's expected behaviour is return a value normally. + @Test public void notExecuteUnknownInstructionTest() { - final List<String> lines = readInstructions("examples/array.s"); + String unknown_ins = "FOO R0 100"; + String err_msg = "Machine recognises unknown instruction " + + "that is not even attempting to execute."; + List<String> lines = new ArrayList<String>(); + lines.add("RET R0"); + lines.add(unknown_ins); Machine m = new Machine(); - assertEquals(m.execute(lines), 45); + assertEquals(err_msg, m.execute(lines), 0); } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() + + // For EC5: + // This test aims to test the Machine's behaviour + //when there exist register Rx such that x is int and x < 0. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test(expected = InvalidInstructionException.class) + public void smallResgisterTest() throws Throwable { - throw new java.io.IOException(); + List<String> lines = new ArrayList<String>(); + lines.add("RET R-1"); + Machine m = new Machine(); + m.execute(lines); } - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() + + // For EC6: + // This test aims to test the Machine's behaviour + //when there exist register Rx such that x is int and x > 31. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test(expected = InvalidInstructionException.class) + public void largeResgisterTest() + throws Throwable { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); + List<String> lines = new ArrayList<String>();; + lines.add("RET R32"); + Machine m = new Machine(); + m.execute(lines); } - //Read in a file containing a program and convert into a list of - //string instructions - private List<String> readInstructions(String file) + // For EC7: + // This test aims to test the Machine's behaviour + //when there exist some value val such that val is int and val > 65535 and + //the instructions consists of MOV and RET instructions only. + // RET is assumed to be correct in this test case, so that MOV's execution can + //be tested. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test(expected = InvalidInstructionException.class) + public void largeValMOVAndRETTest() + throws Throwable { - Charset charset = Charset.forName("UTF-8"); - List<String> lines = null; - try { - lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + List<String> lines = new ArrayList<String>(); + lines.add("MOV R1 65536"); + lines.add("RET R1"); + Machine m = new Machine(); + m.execute(lines); + } + + // For EC8: + // This test aims to test the Machine's behaviour + //when there exist some value val such that val is int and val < -65535 and + //the instructions consists of MOV and RET instructions only. + // RET is assumed to be correct in this test case, so that MOV's execution can + //be tested. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test(expected = InvalidInstructionException.class) + public void smallValMOVAndRETTest() + throws Throwable + { + List<String> lines = new ArrayList<String>(); + lines.add("MOV R1 -65536"); + lines.add("RET R1"); + Machine m = new Machine(); + m.execute(lines); + } + + // For EC9: + // This test aims to test the Machine's behaviour + //when there exist some value val such that val is int and 65535 <= val <= 65535 + //and the instructions consists of MOV and RET instructions only. + // RET is assumed to be correct in this test case, so that MOV's execution can + //be tested. + // The Machine's expected behaviour is to raise an InvalidInstructionException. + @Test public void normalValMOVAndRETTest() + { + String err_msg = "Machine does not execute MOV correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R1 0"); + lines.add("RET R1"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + // For EC10: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of ADD, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on ADD instruction. + // Passing this test means that ADD execute correctly. + // The Machine's expected behaviour is to return a value normally. + @Test public void ADDTest() + { + String err_msg = "Machine does not execute ADD correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 2"); + lines.add("MOV R1 1"); + lines.add("ADD R3 R0 R1"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 3); + } + + // For EC11: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of SUB, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on SUB instruction. + // Passing this test means that SUB execute correctly. + // The Machine's expected behaviour is to return a value normally. + @Test public void SUBTest() + { + String err_msg = "Machine does not execute SUB correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 3"); + lines.add("MOV R1 1"); + lines.add("SUB R3 R0 R1"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 2); + } + + + // For EC12: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of MUL, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on MUL instruction. + // Passing this test means that MUL execute correctly. + // The Machine's expected behaviour is to return a value normally. + @Test public void MULTest() + { + String err_msg = "Machine does not execute MUL correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 3"); + lines.add("MOV R1 -1"); + lines.add("MUL R3 R0 R1"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), -3); } - catch (Exception e){ - System.err.println("Invalid input file! (stacktrace follows)"); - e.printStackTrace(System.err); - System.exit(1); + + // For EC13: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JMP 1, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JMP instruction. + // Passing this test means that JMP 1 is a no-op. + // The Machine's expected behaviour is to return a value normally. + @Test public void JMPONETest() + { + String err_msg = "Machine does not execute JMP 1 correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("JMP 1"); + lines.add("MOV R0 10"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 10); + } + + // For EC14: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JMP, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JMP instruction. + // Passing this test means that JMP -2 will cause pc < 0 which breaks the + //loop and ends the execution immdiately without returning a value by RET. + // The Machine's expected behaviour is to raise a NoReturnValueException. + @Test(expected = NoReturnValueException.class) + public void JMPNegValAndSmallNewpcTest() + throws Throwable + { + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 10"); + lines.add("JMP -2"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); + } + + // For EC15: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JMP, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JMP instruction. + // Passing this test means that JMP 2 skip the next instruction and rightaway + //returning a value by RET. + // The Machine's expected behaviour is to return a value normally. + @Test public void JMPPosiValAndNormalNewpcTest() + { + String err_msg = "Machine does not execute JMP correctly with val > 1."; + List<String> lines = new ArrayList<String>(); + lines.add("JMP 2"); + lines.add("MOV R0 10"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + + // For EC16: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JMP, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JMP instruction. + // Passing this test means that JMP 3 will cause pc > progLength which breaks + //the loop and ends the execution immdiately without returning a value by RET. + // The Machine's expected behaviour is to raise a NoReturnValueException. + @Test(expected = NoReturnValueException.class) + public void JMPPosValAndLargeNewpcTest() + throws Throwable + { + List<String> lines = new ArrayList<String>(); + lines.add("JMP 3"); + lines.add("MOV R0 10"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); } - return lines; + + // For EC17: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JZ, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JZ instruction. + // Passing this test means that JZ with non-zero register is a no-op, + //and the pc will increment by 1. + // The Machine's expected behaviour is to return a value normally. + @Test public void JZNonZeroTest() + { + String err_msg = "Machine does not execute JZ correctly with non-zero register value."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 5"); + lines.add("JZ R0 10"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 5); + } + + // For EC18: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JZ, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JZ instruction. + // Passing this test means that JZ with zero register value will add val to pc, + //only if 0 <= pc < progLength. + // The Machine's expected behaviour is to return a value normally. + @Test public void JZZeroAndNormalNewpcTest() + { + String err_msg = "Machine does not execute JZ correctly with zero register value."; + List<String> lines = new ArrayList<String>(); + lines.add("JZ R0 2"); + lines.add("MOV R0 5"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + // For EC19: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JZ, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JZ instruction. + // Passing this test means that JZ with zero register will add val to pc, + //but causing pc < 0 so breaking the loop without executing RET. + // The Machine's expected behaviour is to raise a NoReturnValueException. + @Test(expected = NoReturnValueException.class) + public void JZZeroAndSmallNewpcTest() + throws Throwable + { + List<String> lines = new ArrayList<String>(); + lines.add("JZ R0 -1"); + lines.add("MOV R0 5"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); + } + + // For EC20: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of JZ, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on JZ instruction. + // Passing this test means that JZ with zero register will add val to pc, + //but causing pc >= progLength so breaking the loop without executing RET. + // The Machine's expected behaviour is to raise a NoReturnValueException. + @Test(expected = NoReturnValueException.class) + public void JZZeroAndLargeNewpcTest() + throws Throwable + { + List<String> lines = new ArrayList<String>(); + lines.add("JZ R0 3"); + lines.add("MOV R0 5"); + lines.add("RET R0"); + Machine m = new Machine(); + m.execute(lines); +} + + // For EC21: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of DIV, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on DIV instruction. + // Passing this test means that DIV by zero is a no-op. + // The Machine's expected behaviour is to return a value normally. + @Test public void DIVByZeroTest() + { + String err_msg = "Machine does not execute DIV by Zero correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 9"); + lines.add("MOV R1 0"); + lines.add("DIV R3 R0 R1"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + // For EC22: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of DIV, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on DIV instruction. + // Passing this test means that DIV by non-zero will obtain result normally. + // The Machine's expected behaviour is to return a value normally. + @Test public void DIVByNonZeroTest() + { + String err_msg = "Machine does not execute DIV by non-zero correctly."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 9"); + lines.add("MOV R1 3"); + lines.add("DIV R3 R0 R1"); + lines.add("RET R3"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 3); + } + + // For EC23: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of STR, LDR, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on STR and LDR instructions. + // Passing this test means that STR and LDR with b + v > 65535 is a no-op. + // The Machine's expected behaviour is to return a value normally. + @Test public void STRAndLDRLargeRegPlusValTest() + { + String err_msg = "Machine does not execute STR and/or LDR correctly with b + v > 65535."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 65535"); + lines.add("MOV R1 5"); + lines.add("STR R0 1 R1"); + lines.add("LDR R2 R0 1"); + lines.add("RET R2"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + // For EC24: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of STR, LDR, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on STR and LDR instruction. + // Passing this test means that STR and LDR with b + v < 0 is a no-op. + // The Machine's expected behaviour is to return a value normally. + @Test public void STRSmallRegisterValuePlusValTest() + { + String err_msg = "Machine does not execute STR and/or LDR correctly with b + v < 0."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 4"); + lines.add("MOV R1 5"); + lines.add("STR R0 -5 R1"); + lines.add("LDR R2 R0 -5"); + lines.add("RET R2"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 0); + } + + // For EC25: + // This test aims to test the Machine's behaviour + //for the correctness of executing combination of STR, LDR, MOV and RET only. + // This test assumes the correctness of RET and MOV executions so that we + //can test on STR and LDR instruction. + // Passing this test means that STR and LDR with 0 <= b + v <= 65535 works normally + //by assigning value on memory[b + v]. + // The Machine's expected behaviour is to return a value normally. + @Test public void STRNormalRegisterValuePlusValTest() + { + String err_msg = "Machine does not execute STR and/or LDR correctly 0 <= b + v <= 65535."; + List<String> lines = new ArrayList<String>(); + lines.add("MOV R0 -1"); + lines.add("MOV R1 2"); + lines.add("STR R0 1 R1"); + lines.add("LDR R2 R0 1"); + lines.add("RET R2"); + Machine m = new Machine(); + assertEquals(err_msg, m.execute(lines), 2); } } + +/*------------------------- END of Partitioning Tests -------------------------*/ -- GitLab