Skip to content

Commit

Permalink
Rust unsigned ints (#25)
Browse files Browse the repository at this point in the history
* Unsigned ints

* Run tests on github
  • Loading branch information
virgil-serbanuta authored Dec 3, 2024
1 parent 07f9798 commit 9ea74d4
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: make -C pykwasm pyupgrade
- name: 'Run unit tests'
run: make -C pykwasm cov-unit
- name: 'Run Rust unit-tests'
run: make rust-tests

conformance-tests:
name: 'Conformance Tests'
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ proof_tests:=$(wildcard tests/proofs/*-spec.k)

test-prove: $(proof_tests:=.prove)

### Rust tests

rust-tests: erc20-rust-tests
.PHONY: rust-tests

erc20-rust-tests: tests/ulm/erc20/rust/src/*.rs tests/ulm/erc20/rust/Cargo.*
cd tests/ulm/erc20/rust && RUST_BACKTRACE=1 cargo test
.PHONY: erc20-rust-tests

# Analysis
# --------
Expand Down
Empty file added tests/ulm/erc20/erc20.wast
Empty file.
1 change: 1 addition & 0 deletions tests/ulm/erc20/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
124 changes: 124 additions & 0 deletions tests/ulm/erc20/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/ulm/erc20/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "erc20"
version = "0.1.0"
edition = "2021"

#[profile.dev]
#panic = "abort"

#[profile.release]
#panic = "abort"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
24 changes: 24 additions & 0 deletions tests/ulm/erc20/rust/src/assertions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#[cfg(not(test))]
use core::panic::PanicInfo;

use crate::ulm_hooks;

pub fn fail(msg: &str) -> ! {
ulm_hooks::failWrapper(msg);
}

#[cfg(not(test))]
#[panic_handler]
pub fn panic(_info: &PanicInfo) -> ! {
fail("Panic")
}

#[macro_export]
macro_rules! require {
( $cond:expr , $msg:expr ) => {
if ! $cond {
fail($msg);
}
}
}
7 changes: 7 additions & 0 deletions tests/ulm/erc20/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![cfg_attr(not(test), no_std)]

mod assertions;
mod unsigned;
mod ulm_hooks;

mod unsigned_tests;
25 changes: 25 additions & 0 deletions tests/ulm/erc20/rust/src/ulm_hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extern "C" {
#[allow(dead_code)]
pub fn fail(msg: *const u8, msg_len: usize) -> !;
}

#[cfg(test)]
pub mod overrides {
#[no_mangle]
pub extern "C" fn fail(_msg: *const u8, _msg_len: usize) -> ! {
panic!("fail called");
}
}

#[cfg(test)]
#[allow(non_snake_case)]
pub fn failWrapper(msg: &str) -> ! {
panic!("{}", msg);
}

#[cfg(not(test))]
#[allow(non_snake_case)]
pub fn failWrapper(msg: &str) -> ! {
let msg_bytes = msg.as_bytes();
unsafe { fail(msg_bytes.as_ptr(), msg_bytes.len()); }
}
Loading

0 comments on commit 9ea74d4

Please sign in to comment.