Skip to content
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

Test runner. #1999

Merged
merged 11 commits into from
Oct 31, 2024
Merged

Test runner. #1999

merged 11 commits into from
Oct 31, 2024

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Oct 31, 2024

Simple command line utility that can run tests in a .asm file.

Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of moving the test runner to the pipeline crate? The we can use it to simplify tests like this

for (name, (_, val)) in analyzed
.definitions
.iter()
.filter(|(n, _)| n.starts_with("test::test_") || n.contains("::test::test_"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the tests in std/math/fp{2,4}.asm to start with test_?

}
print!("Running test: {name}...");
let function = symbols.lookup(name, &None).unwrap();
evaluator::evaluate_function_call::<F>(function, vec![], &mut symbols).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could provide a better error message (e.g. mention the name of the test) and continue running the other tests maybe?

Right now, a failing test looks like this:

Running test: std::math::fp2::test::test_add...  ok
Running test: std::math::fp2::test::test_mul...  ok
thread 'main' panicked at cli/src/test_runner.rs:58:80:
called `Result::unwrap()` on an `Err` value: FailedAssertion("Wrong subtraction result")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Running test: std::math::fp2::test::test_sub...% 

(test_sub failed)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting! I thought we implemented the built-in panic by using panic!(), but we actually return an Error. How convenient!

cli/src/main.rs Outdated
Comment on lines 380 to 383
/// Also run the tests inside the standard library.
#[arg(long)]
#[arg(default_value_t = false)]
include_std_tests: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this flag? Seems like a hack to be able to run all std tests (by passing any file to powdr test <file> --iclude-std-tests) before we have #2000, but seems like the cleaner solution would be to implement #2000 and do powdr test std?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It filters tests based on their namespace. Since std is always included, we need to filter the tests out. If you run powdr test std with the filter active, it will not run any tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but does this need to leak to the CLI? Or could we just say we never want to run the std tests, unless we pass std explicitly?

cli/src/main.rs Outdated
Comment on lines 380 to 383
/// Also run the tests inside the standard library.
#[arg(long)]
#[arg(default_value_t = false)]
include_std_tests: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but does this need to leak to the CLI? Or could we just say we never want to run the std tests, unless we pass std explicitly?

"std::protocols::fingerprint::test::test_fingerprint",
vec![],
fn std_tests() {
let test_count = 9;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it important to assert that there are 9 tests? In what scenario would it not run all tests? I don't see a good reason and it will be slightly annoying that we have to change this number when adding a new test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a safeguard against missing some tests because of the naming scheme or something.

Comment on lines 401 to 411
assert_eq!(
test_count,
run_tests(&std_analyzed::<GoldilocksField>(), true).unwrap()
);
assert_eq!(
test_count,
run_tests(&std_analyzed::<Bn254Field>(), true).unwrap()
);
assert_eq!(
test_count,
run_tests(&std_analyzed::<BabyBearField>(), true).unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have BabyBear and KoalaBear, actually!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this approach assumes that all tests should be run on all fields. I think we might have tests in the future that are only supposed to pass on some fields. But we we can also fix that when we get there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but then the test function should return early. We might find a more convenient way, though.

match evaluator::evaluate_function_call::<F>(function, vec![], &mut symbols) {
Err(e) => {
let msg = e.to_string();
println!("{padding}failed\n {msg}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful 😍

Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chriseth chriseth added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit b2a48d7 Oct 31, 2024
14 checks passed
@chriseth chriseth deleted the test_runner branch October 31, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants