-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: SpinalTestBench #968
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this seems nice to use. I also like the little touches, like that compiles the DUT lazily, which should speed of looped tests where many of the tests are filtered out.
The small thing that I'd add is to be able to specify a random seed via the scalatest command line, to reproduce a failure w/o changing the test (via testOnly ... -- -Dseed=x
or similar - environment variable doesn't catch that since I wouldn't want to restart sbt for every seed change). (and yes, I'm aware of the irony that I'll contradict myself immediately ;-))
My major concern is that this feels like you tried to account for every possibility, rather than provide something for 90% of the cases that is easy to explain. If I want to mess with the used seed then I can:
- change the environment variable for it
- override the seed member
- pass a seed to the
bench
- use
withSeed
or pass a seed totest
- (if we'd add it pass the seed on the scalatest invocation)
This seems to complicated for such a simple thing, hard to document, explain and to provide help in e.g. the Gitter.
Another one I'd cut back is syntax variants of running a test: I'd choose either the FlatSpec style or thetest
function - no reason to have both?
I think you could should be able to drop the type parameter and simplify this a bit. On some other technical notes I'd try to move Bench
and (some?) of the other classes out of the copy of the Spec
to avoid confusion between bench
and Bench
Edit: I still have to try it here, I'd like to have a look at the naming of the testcases with the various features. Being able to filter for specific testcases is one of the most used scalatest features for me...
About seed from scalatest command line, can you point me to an example of code getting this value from the Scala code? Never used that so far. Actually I never set the seed myself, so I don't really know the use case. How do you think should we manage this? Not having the seed in the code at all would be great I think, so maybe just get the optional flag as you suggested, else let Spinal manage the seed with environment variables? Why having both About About moving stuff outside, I don't want to pollute the namespace, and as far as these are only used in |
I found that, for |
As far as I know, the usual way to do that in scala would be to put the classes in a companion object. That way they don't show up in intellisense (if you use such a thing) or the global namespace. They also don't get a closure of the surrounding class.
Sorry, I thought you might have seen it when I posted the link on your original PR. I also had to look for it for quite some time: https://github.com/andreasWallner/spinalStuff/blob/dbde3792e46be4230995291ec727e38fffbc31eb/src/test/scala/andreasWallner/SpinalFunSuite.scala#L36
Fair, I had thought it might avoid confusion to have 2 ways to do the exact same thing, with only minor wording diff. |
I'm trying to move My bad, I hadn't noticed that part of your code the first time and I didn't think to look at it for About |
I had a quick look in the webinterface and only found a single reference to
No worries, I did want to send you hunting though^^
Seems ok Btw. I noticed that the code in |
You are right, With both this version and the previous one, it is not allowed to do
|
2303cd4
to
f49dcab
Compare
Rebased on @andreasWallner I think I have nothing left to modify, waiting for your approval 😃 |
f49dcab
to
2fd27c4
Compare
So should all overridable defaults be |
@andreasWallner can you review, please? |
Sorry for the delay, I was in a workshop the last few days, will have a look in the evening. |
@andreasWallner Great! Also, please don't merge it now: the way you modified |
Small comment on naming:
Where only the first part is true here, not the second. (actually less true if you do the move ;-) ) |
Let's not have scala-test in lib, but in tester ? add this utility in the tester/main and add tester in the releases as a library ? |
@Dolu1990 So for the user who wants to use the feature in this PR it implies that:
|
@numero-744 Yes |
Also, instead of SpinalSpec, what's about SpinalTest ? |
@andreasWallner @Dolu1990 The current name is after I have set this PR as draft, I'll commit forward so that you can identify the new suggestions. I'll rebase when we agree on the result before removing draft status. |
About atomicity of the compilatoin cache, it is implemented, but maybe there is holes in it. Do you have a way to more or less reproduce the issue ? |
@Dolu1990 For now I think it is a |
FYI short example of use is available in numero-744/Aes/tb/spinal/aes/AesTestBench.scala Btw I could use |
Not a big fan of DUT since that would be the Component that we are testing itself? What I could offer would be |
I would say the component class name should be describing what it does, and only in the context of the testbench it becomes the "device under test" so we can say "the dut is a Dut": val dut: Dut[MyComponent] = Dut(MyComponent(cfg))
// ^^^^^^^^ the dut is a Dut
// but for better test reports it is better to use a good name
val myComponent = Dut(MyComponent(cfg))
myComponent should "work" inSim { dut =>
// hello
}
// => "myComponent should work" test passed I had taken a look at diagrams like https://www.chipverify.com/systemverilog/systemverilog-simple-testbench to rename the the |
73d03af
to
05d8fe0
Compare
05d8fe0
to
e18bda9
Compare
Ready for final review and merge if you have time, else it can wait for |
About the directory, is it more clean that if we have Because the tester is a standalone package for the user. |
I don't know for other items, but for If there is a consensus it is really an issue, I'll move it to the Also, still in the case we move it to |
e18bda9
to
9711e4e
Compare
To be honest I have no idea how well that plays with other JVM tools, at least for java it would be a no-no to not have the correct library name in the package name. I noticed that scala seems to care less about it. Apart from that I thought a bit about whether the |
I don't know… If it is an issue with tools, then isn't having package |
Sadly I don't know - why not stick with it until some issue pops up? |
Maybe the library is too big, so mixing the core, simulation, and library together is not a good idea. |
Yes, the decision is really hard to make. Also, as we discussed before, if we organize tester structure the same with things to be tested, it would be convenient, which support the method one. |
@numero-744 Is there any problem left for this PR? |
You have put it into the tester/main subproject, so that it is only required in user's test case. I think it's nice. |
To me it is about things like splitting The relationship with #1001 is that while moving tests, there were testing utilities that were common to different tested things, so I have put them into |
Because the SpinalTestBench is in spinal.core.sim, so we can just use the path it is now as tester/src/main/scala/spinal/core/sim/SpinalTestBench.scala. I think the PR is best to be decoupled, so that things would be simplified. |
Also the |
Continuation of #965 (thanks for your feedback @andreasWallner @Readon)
Context, Motivation & Description
Scalatest is useful to quickly write unit / regression tests, but it is not really practical for hardware description testing:
import scalatest.funs…
no,anyfuns…
Err, is itFlatSuite
?"This PR mixes Spinal's
doSim
anddoSimUntilVoid
functions withscalatest
features to provide the user a unifiedSpinalTestBench
, which is a part ofspinal.core.sim._
so no need to import more things!What is a
SpinalTestBench
?A
SpinalTestBench
contains at least aDut[Device]
, which is kind of aSimCompiled[Device]
but with more context to give you neatscalatest
reports.The goal of a bench is to run tests, isn't it? Two ways to do so:
Just created 3 tests. Three? Yes, three:
myDut compiles
myDut should do something
myDut test: some test
So if compilation fails, the failure is reported, and tests on this bench are cancelled. ✨ If it succeeds (why would it fail? 🤔) it is not re-compiled by default (but it can be configured, see below).
(Btw, it sometimes happened to me to get immediate "all tests are successful" just because compilation failed before the tests, so now it won't happen anymore 😃)
Configurable components
For a configurable component, I suggest to use
TestSuite
Oh, btw, if you just want to check that a configuration is valid or not, you can!
Configuration
You can configure:
config: SpinalSimConfig
(defaults toSimConfig
) by overridingdefaultConfig
in the spec or withbench(finalConfig=...)
caching: Boolean
(defaults totrue
) to cacheSimCompiled
in a bench, adding a test for bench compilation. Setting it to false removes the test for compilation and re-compiles on each test, so if compilation fails, all tests on this bench fail. Configure it by overridingdefaultCaching
in the spec or when callingbench(finalCaching=...)
.seed: Option[Int]
(defaults toNone
) by overridingdefaultSeed
in the spec or usingtestOnly MyComponentSpec -- -Dseed=123
Other features
More examples in the file with tests.
Note: The workspace is named after the
Dut
, to have consistent names instead of "MyComponent_XXX".Checklist
/** */
?