Skip to content

Commit

Permalink
Added basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwljwljwljw committed May 4, 2021
1 parent 01a0941 commit 1d6448f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ jobs:

- name: Compile
run: make compile

- name: Unit test
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
out/
.idea/
.idea_modules/
test_run_dir/

3 changes: 2 additions & 1 deletion src/main/scala/CacheParameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ case class CacheParameters(
sets: Int = 1024,
blockBytes: Int = 64,
replacement: String = "plru",
mshrs: Int = 16,
channelBytes: TLChannelBeatBytes = TLChannelBeatBytes(32),
echoField: Seq[BundleFieldBase] = Nil,
reqField: Seq[BundleFieldBase] = Nil, // master
Expand All @@ -23,5 +24,5 @@ case class CacheParameters(
respField: Seq[BundleFieldBase] = Nil) {
require(ways > 0)
require(sets > 0)
require(channelBytes.d.get >= 64)
require(channelBytes.d.get >= 8)
}
18 changes: 13 additions & 5 deletions src/main/scala/HuanCun.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ trait HasHuanCunParameters {
val cacheParams = p(CacheParamsKey)
val blockBytes = cacheParams.blockBytes

val mshrs = cacheParams.mshrs
val blocks = cacheParams.ways * cacheParams.sets
val sizeBytes = blocks * blockBytes
}

abstract class HuanCunModule(implicit p: Parameters) extends LazyModule with HasHuanCunParameters
abstract class HuanCunModule(implicit p: Parameters) extends Module with HasHuanCunParameters

class HuanCun(implicit p: Parameters) extends HuanCunModule {
class HuanCun(implicit p: Parameters) extends LazyModule with HasHuanCunParameters {

val xfer = TransferSizes(blockBytes, blockBytes)
val atom = TransferSizes(1, cacheParams.channelBytes.d.get)
Expand All @@ -31,7 +32,8 @@ class HuanCun(implicit p: Parameters) extends HuanCunModule {
name = cacheParams.name,
supports = TLSlaveToMasterTransferSizes(
probe = xfer
)
),
sourceId = IdRange(0, cacheParams.mshrs),
)
),
channelBytes = cacheParams.channelBytes,
Expand Down Expand Up @@ -62,7 +64,8 @@ class HuanCun(implicit p: Parameters) extends HuanCunModule {
beatBytes = 32,
minLatency = 2,
responseFields = cacheParams.respField,
requestKeys = cacheParams.reqKey
requestKeys = cacheParams.reqKey,
endSinkId = cacheParams.mshrs + 2
)
}
)
Expand All @@ -73,7 +76,12 @@ class HuanCun(implicit p: Parameters) extends HuanCunModule {

node.in.zip(node.out).foreach {
case ((in, edgeIn), (out, edgeOut)) =>
in <> out
out <> in
val header = s"======== HuanCun: ${cacheParams.name} ========"
println(header)
println("clients: " + edgeIn.client.clients.map(_.name).mkString(" "))
println("managers: " + edgeOut.manager.managers.map(_.name).mkString(" "))
println(header.map(_ => "=").mkString(""))
}

}
Expand Down
9 changes: 0 additions & 9 deletions src/test/scala/BasicTest.scala

This file was deleted.

37 changes: 37 additions & 0 deletions src/test/scala/BasicTester.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package HuanCun

import org.scalatest._
import chiseltest._
import chisel3._
import chiseltest.experimental.TestOptionBuilder.ChiselScalatestOptionBuilder
import freechips.rocketchip.diplomacy.{AddressSet, LazyModule, LazyModuleImp, LazyModuleImpLike}
import freechips.rocketchip.tilelink.{TLCacheCork, TLFuzzer, TLIdentityNode, TLRAM}

class BasicTester extends L2Tester {

class TestTop extends LazyModule {
val cache = LazyModule(new HuanCun())
val fuzzer = LazyModule(new TLFuzzer(
nOperations = 2 * cache.cacheParams.mshrs, inFlight = cache.cacheParams.mshrs
))
val ram = LazyModule(new TLRAM(AddressSet(0, 0xffff)))

ram.node := TLCacheCork() := cache.node := fuzzer.node
lazy val module = new LazyModuleImp(this){
val pass = IO(Output(Bool()))
pass := fuzzer.module.io.finished
}
}

it should "read and write TLRAM correctly" in {

val top = LazyModule(new TestTop)

test(top.module).withAnnotations(testAnnos) { dut =>
while(!dut.pass.peek().litToBoolean){
dut.clock.step(1)
}
}
}

}
11 changes: 11 additions & 0 deletions src/test/scala/L2Tester.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package HuanCun

import chipsalliance.rocketchip.config.Config
import chiseltest._
import chiseltest.internal.VerilatorBackendAnnotation
import firrtl.AnnotationSeq
import org.scalatest.flatspec._
import org.scalatest.matchers.should._

abstract class L2Tester extends AnyFlatSpec with ChiselScalatestTester with Matchers {
behavior of "L2"
implicit val defaultConfig = new Config((_, _, _) => {
case CacheParamsKey => CacheParameters()
})
var testAnnos: AnnotationSeq = Seq()
}

trait WithVerilatorBackend { this: L2Tester =>
testAnnos = testAnnos :+ VerilatorBackendAnnotation
}

0 comments on commit 1d6448f

Please sign in to comment.