-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj1Test.scala
97 lines (84 loc) · 3.16 KB
/
j1Test.scala
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
/**
* Copyright 2023 Frank Zeyda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package j1.chisel.test
import j1.chisel.j1Config
import j1.chisel.j1System
import j1.miniasm.j1Asm
import j1.miniasm.j1Disasm
import chiseltest._
import org.scalatest.flatspec.AnyFlatSpec
import scala.io.AnsiColor._
class j1Test extends AnyFlatSpec with ChiselScalatestTester {
val MAX_STEPS = 100 // to bail out of simulation when non-termating
/* Load configuration from j1.conf properties file. */
Console.println(f"------ ${RED}CONFIG${RESET} ------")
/* For testing, ensure that we are not Chisel SyncReadMem. */
implicit val cfg = j1Config.load("j1.conf").without_bb_tdp
cfg.dump()
behavior of "j1Asm" /* execute sample test case */
it should "generate programs that execute correctly on the j1 core" in {
test(new j1System).runPeekPoke(dut => new j1PeekPokeTester(dut) {
info("See above console output for the execution trace.")
/* First of all clear all data in code memory. */
clearProgMem()
/* Creatie a j1 machine program for the test. */
val program = new j1Asm { /* the program is written in j1Asm's E-DSL */
push(1)
push(2)
plus
jmp("skip") // labels can be called before declaration
push(3)
label("skip")
call("subroutine")
plus.^ // we can also agument with .^^ or chain as in .^.x
softhalt // tells the simulator that we are done
label("subroutine")
push(-1)
push(-2)
plus.x
// exit
done
}
Console.println(f"------ ${RED}DISASM${RESET} ------")
program.disasm()
Console.println(f"------ ${RED}DEPLOY${RESET} ------")
program.deploy(this)
/* Carry out simulation until a software halt. */
Console.println(f"------- ${RED}INIT${RESET} -------")
reset()
dumpState()
step(1) // clears reboot flag
var halt = false
var step = 1
while (!halt && step <= MAX_STEPS) {
Console.println(f"------ ${RED}STEP ${step}${RESET} ------")
dumpState()
val pcOld = peek(dut.probe.pc)
step(1)
val pcNew = peek(dut.probe.pc)
// Detect software halt instruction (jmp $pc)
halt = (pcNew == pcOld)
step = step + 1
}
Console.println(f"------- ${RED}DONE${RESET} -------")
dumpState()
/* Assert a properties of the the resulting machine state. */
expect(peek(dut.probe.st0) == 0, f"-> ${UNDERLINED}st0 == 0${RESET}")
expect(peek(dut.probe.dsp) == 2, f"-> ${UNDERLINED}dsp == 2${RESET}")
expect(peek(dut.probe.rsp) == 0, f"-> ${UNDERLINED}rsp == 0${RESET}")
}
)}
}