@@ -5,42 +5,82 @@ package chiselTests.simulator
55import java .io .File
66import org .scalatest .funspec .AnyFunSpec
77import org .scalatest .matchers .should .Matchers
8- import chisel3 .layer .{Layer , LayerConfig }
9- import chisel3 .simulator .LayerControl
8+ import chisel3 .RawModule
9+ import chisel3 .layer .{addLayer , Layer , LayerConfig }
10+ import chisel3 .simulator .{ChiselWorkspace , LayerControl }
11+ import svsim .Workspace
1012
1113class LayerControlSpec extends AnyFunSpec with Matchers {
14+
15+ object A extends Layer (LayerConfig .Extract ())
16+ object B extends Layer (LayerConfig .Extract ()) {
17+ object C extends Layer (LayerConfig .Extract ())
18+ }
19+ class Foo extends RawModule {
20+ Seq (A , B , B .C ).foreach(addLayer)
21+ }
22+
23+ val workspace = new Workspace (path = " test_run_dir/LayerControlSpec" )
24+ workspace.reset()
25+ val elaboratedModule = workspace.elaborateGeneratedModule({ () => new Foo })
26+
1227 describe(" LayerControl.EnableAll" ) {
13- it(" should always filter to true " ) {
28+ it(" should include all layer files " ) {
1429 val layerControl = LayerControl .EnableAll
15- layerControl.filter(new File (" foo" )) should be(true )
16- layerControl.filter(new File (" layers-foo-bar.sv" )) should be(true )
30+
31+ info(" non-layer files are ignored" )
32+ layerControl.shouldIncludeFile(elaboratedModule).isDefinedAt(new File (" Foo.sv" )) should be(false )
33+
34+ Seq (" layers-Foo-A.sv" , " layers-Foo-B.sv" , " layers-Foo-B-C.sv" ).map(new File (_)).foreach {
35+ case filename =>
36+ info(s " $filename is included " )
37+ layerControl.shouldIncludeFile(elaboratedModule)(filename) should be(true )
38+ }
1739 }
1840 }
1941 describe(" LayerControl.Enable()" ) {
20- it(" should return true for non-layers and false for layers " ) {
42+ it(" should include no layer files " ) {
2143 val layerControl = LayerControl .Enable ()
22- layerControl.filter(new File (" foo" )) should be(true )
23- layerControl.filter(new File (" layers-foo-bar.sv" )) should be(false )
44+
45+ info(" non-layer files are ignored" )
46+ layerControl.shouldIncludeFile(elaboratedModule).isDefinedAt(new File (" Foo.sv" )) should be(false )
47+
48+ Seq (" layers-Foo-A.sv" , " layers-Foo-B.sv" , " layers-Foo-B-C.sv" ).map(new File (_)).foreach {
49+ case filename =>
50+ info(s " $filename is excluded " )
51+ layerControl.shouldIncludeFile(elaboratedModule)(filename) should be(false )
52+ }
2453 }
2554 }
2655 describe(" LayerControl.DisableAll" ) {
27- it(" should return true for non-layers and false for layers" ) {
28- LayerControl .DisableAll .filter(new File (" foo" )) should be(true )
29- LayerControl .DisableAll .filter(new File (" layers-foo-bar.sv" )) should be(false )
56+ it(" should include no layer files" ) {
57+ val layerControl = LayerControl .Enable ()
58+
59+ info(" non-layer files are ignored" )
60+ layerControl.shouldIncludeFile(elaboratedModule).isDefinedAt(new File (" Foo.sv" )) should be(false )
61+
62+ Seq (" layers-Foo-A.sv" , " layers-Foo-B.sv" , " layers-Foo-B-C.sv" ).map(new File (_)).foreach {
63+ case filename =>
64+ info(s " $filename is excluded " )
65+ layerControl.shouldIncludeFile(elaboratedModule)(filename) should be(false )
66+ }
3067 }
3168 }
32- describe(" LayerControl.Enable" ) {
33- it(" should return true for non-layers and filter layers properly" ) {
34- object A extends Layer (LayerConfig .Extract ())
35- object B extends Layer (LayerConfig .Extract ()) {
36- object C extends Layer (LayerConfig .Extract ())
37- }
69+ describe(" LayerControl.Enable(A, B.C)" ) {
70+ it(" should include only specified layers" ) {
3871 val layerControl = LayerControl .Enable (A , B .C )
39- layerControl.filter(new File (" foo" )) should be(true )
40- layerControl.filter(new File (" layers-foo.sv" )) should be(false )
41- layerControl.filter(new File (" layers-foo-A.sv" )) should be(true )
42- layerControl.filter(new File (" layers-foo-A-B.sv" )) should be(false )
43- layerControl.filter(new File (" layers-foo-B-C.sv" )) should be(true )
72+
73+ info(" non-layer files are ignored" )
74+ layerControl.shouldIncludeFile(elaboratedModule).isDefinedAt(new File (" foo" )) should be(false )
75+
76+ Seq (" layers-Foo-A.sv" , " layers-Foo-B-C.sv" ).map(new File (_)).foreach {
77+ case filename =>
78+ info(s " $filename is included " )
79+ layerControl.shouldIncludeFile(elaboratedModule)(filename) should be(true )
80+ }
81+
82+ info(" layers-Foo-A-B.sv is excluded" )
83+ layerControl.shouldIncludeFile(elaboratedModule)(new File (" layers-Foo-A-B.sv" )) should be(false )
4484 }
4585 }
4686}
0 commit comments