-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_test.java
105 lines (82 loc) · 3.39 KB
/
memory_test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public class memory_test
{
public static void main(String [] args) throws Exception
{
//Run all tests
bit_test.runTests();
longword_test.runTests();
rippleAdder_test.runTests();
multiplier_test.runTests();
ALU_test.runTests();
runTests();
}
public static void runTests() throws Exception
{
//Run memory tests
System.out.println("MEMORY UNIT TEST START ----------------------------------------------------------------------------");
testWrite();
testRead();
System.out.println("ALL UNIT TESTING HAS PASSED!");
}
public static void testWrite() throws Exception
{
//inputting 5 to address 1
longword input1 = new longword();
input1.set(5);
longword address = new longword();
address.set(1);
//writing 5 to address 1 in memory
memory mem1 = new memory();
mem1.write(address, input1);
longword output = mem1.read(address);
//If the output is not 5, throw new exception
if(output.getSigned()!=5) throw new Exception("write testing has failed.");
//Writing the value of 10 to address 2
longword input2 = new longword();
input1.set(10);
longword address2 = new longword();
address.set(2);
//Writing to memory
mem1.write(address2, input2);
//Reading from memory address 1, to see if overwritten
longword output2 = mem1.read(address);
//System.out.println(output.getSigned());
//System.out.println(output2.getSigned());
//if not overwrittenn, throw expection
if(output2.getSigned()==5) throw new Exception("write testing has failed.");
System.out.println("\twrite testing has passed");
}
public static void testRead() throws Exception
{
//inputting 7 to address 2
longword input1 = new longword();
input1.set(7);
longword address = new longword();
address.set(2);
//System.out.println("input1: "+input1.getSigned());
//System.out.println("address: "+address.getSigned());
//writing 7 to address 2 in memory
memory mem1 = new memory();
mem1.write(address, input1);
longword output = mem1.read(address);
//System.out.println("original output: " + output.getSigned());
//If the output is not 7, throw new exception
if(output.getSigned()!=7) throw new Exception("read testing has failed.");
//Writing the value of 15 to address 1
longword input2 = new longword();
input2.set(15);
longword address2 = new longword();
address2.set(1);
//System.out.println("input2: " + input2.getSigned());
//System.out.println("address2: "+address2.getSigned());
//Writing to memory
mem1.write(address2, input2);
//Reading from memory address 1, to see if overwritten
longword output2 = mem1.read(address2);
output = mem1.read(address);
//System.out.println("original output: "+output.getSigned());
//System.out.println("new address output: "+output2.getSigned());
if(output.getSigned()==7) throw new Exception("write testing has failed.");
System.out.println("\tread testing has passed");
}
}