-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31c5b18
commit cdb3ea8
Showing
53 changed files
with
1,267 additions
and
595 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# How to write toolchain tests for an extension | ||
|
||
Make a `test` crate inside the extension folder. As an example, here is the structure of the `rv32im-extension-test` crate: | ||
|
||
``` | ||
extensions/rv32im/tests/ | ||
├── Cargo.toml | ||
├── src | ||
│ └── lib.rs | ||
├── programs | ||
│ └── Cargo.toml | ||
│ └── examples | ||
│ └── example1.rs | ||
│ └── example2.rs | ||
``` | ||
|
||
The `examples` folder contains the test programs in `rust`. | ||
|
||
`fibonacci.rs` example: | ||
```rust | ||
#![cfg_attr(not(feature = "std"), no_main)] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
openvm::entry!(main); | ||
|
||
pub fn main() { | ||
let n = core::hint::black_box(1 << 10); | ||
let mut a: u32 = 0; | ||
let mut b: u32 = 1; | ||
for _ in 1..n { | ||
let sum = a + b; | ||
a = b; | ||
b = sum; | ||
} | ||
if a == 0 { | ||
panic!(); | ||
} | ||
} | ||
``` | ||
|
||
|
||
And then to `transpile`, `run`, and `prove` the above program, in the `src/lib.rs` file, you can do: | ||
|
||
```rust | ||
fn test_fibonacci_prove() -> Result<()> { | ||
let elf = build_example_program_at_path(get_programs_dir!(), "fibonacci")?; | ||
let exe = VmExe::from_elf( | ||
elf, | ||
Transpiler::<F>::default() | ||
.with_extension(Rv32ITranspilerExtension) | ||
.with_extension(Rv32MTranspilerExtension) | ||
.with_extension(Rv32IoTranspilerExtension), | ||
)?; | ||
let config = Rv32IConfig::default(); | ||
new_air_test_with_min_segments(config, exe, vec![], 1, true); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
Note: If the crate with example is not in `./programs`, specify the path with `get_programs_dir!("path to the programs crate")`. |
Oops, something went wrong.