calyxir / calyx

Intermediate Language (IL) for Hardware Accelerator Generators
https://calyxir.org
MIT License
453 stars 45 forks source link

[fud2] Basic testing setup #1954

Closed sampsyo closed 2 months ago

sampsyo commented 3 months ago

As described in #1878, fud2 needs tests. I want to do some refactoring at some point, so tests will be especially helpful for this.

This medium-level integration testing strategy uses snapshots of the Ninja code generation. That is, it doesn't test anything about actually running the Ninja code or any of the commands it might call—it just snapshots the build.ninja itself. This seems like a good compromise between specificity, convenience, and trustworthiness.

In particular, instead of invoking fud2 on the command line and using Runt or whatever, this setup uses Insta. This lets us control the environment for the driver a little more carefully: for example, we feed in a custom configuration instead of loading the configuration from disk. This also required a little refactoring of fud2 itself. Most dramatically, there is now a separate lib.rs from main.rs so that the tests can import the "meat" stuff from lib.rs. There are also a few little hooks in fud-core I had to add to help with the test-harness setup.

I have also added a separate CI action to run these tests. I did not add this to our monolithic rust.yml workflow because it does not seem necessary to have that big test-environment setup; these tests are simpler and more isolated and do not need any dependencies.

This PR contains just 2 simple tests to demonstrate the setup. We should add plenty more!