Skip to content

Commit

Permalink
Remove temporary dir creation
Browse files Browse the repository at this point in the history
Seems like it's slow. Just use `test_run_dir`.

`./mill chiselv.test.testOnly chiselv.ALUSpec` change:

```
[86/86] chiselv.test.testOnly
...
Run completed in 15 seconds, 756 milliseconds.
```

```
[86/86] chiselv.test.testOnly
ALUSpec:
...
Run completed in 6 seconds, 329 milliseconds.
```
  • Loading branch information
uenoku committed Jun 23, 2024
1 parent 63095e5 commit 514990d
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions chiselv/test/src/ALUSpec.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
package chiselv

import chisel3._
import chiseltest._
import svsim._
import chisel3.simulator._
import com.carlosedp.riscvassembler.ObjectUtils.NumericManipulation
import org.scalatest._

import Instruction._
import flatspec._
import matchers._
import java.io.File
import scala.reflect.io.Directory

object EphemeralSimulator extends PeekPokeAPI {

def simulate[T <: RawModule](
module: => T
)(body: (T) => Unit
): Unit = {
val sim = makeSimulator

sim.simulate(module)({ module => body(module.wrapped) }).result
}

private class DefaultSimulator(val workspacePath: String) extends SingleBackendSimulator[verilator.Backend] {
val backend = verilator.Backend.initializeFromProcessEnvironment()
val tag = "default"
val commonCompilationSettings = CommonCompilationSettings()
val backendSpecificCompilationSettings = verilator.Backend.CompilationSettings()
sys.addShutdownHook {
(new Directory(new File(workspacePath))).deleteRecursively()
}
}
private def makeSimulator: DefaultSimulator = {
// TODO: Use ProcessHandle when we can drop Java 8 support
// val id = ProcessHandle.current().pid().toString()
val id = java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
val className = getClass().getName().stripSuffix("$")
new DefaultSimulator(s"test_run_dir/${className}_${id}")
}
}

import EphemeralSimulator._

class ALUSpec extends AnyFlatSpec with ChiselScalatestTester with should.Matchers {
class ALUSpec extends AnyFlatSpec with should.Matchers {
val one = BigInt(1)
val max = (one << 32) - one
val min_signed = one << 32 - 1
Expand Down Expand Up @@ -97,12 +130,12 @@ class ALUSpec extends AnyFlatSpec with ChiselScalatestTester with should.Matcher
dut.io.ALUPort.a.poke(i.to32Bit)
dut.io.ALUPort.b.poke(j.to32Bit)
dut.clock.step()
dut.io.ALUPort.x.peekInt() should be(out)
dut.io.ALUPort.x.peek().litValue should be(out)
}
def testCycle(
op: Type
) =
test(new ALU) { c =>
simulate(new ALU) { c =>
cases.foreach { i =>
cases.foreach { j =>
testDut(i, j, aluHelper(i, j, op).to32Bit, op, c)
Expand Down

0 comments on commit 514990d

Please sign in to comment.