Skip to content

Commit

Permalink
Use explicit protocol version for test Wasms. (#1439)
Browse files Browse the repository at this point in the history
### What

Also modified the makefile to regenerate Wasms in the directory
corresponding to the necessary protocol version.

I'm not sure yet if we need to maintain several versions of every Wasm,
so I'm only leaving the v20 Wasms checked-in for now (I did try to
generate v21 though just for a sanity check). Going forward I think we
could keep explicitly versioned Wasms around for tests that need them,
but otherwise have just a single version.

### Why

Preparing for adding p22 tests that need different versions of Wasm
(specifically, constructor tests).

### Known limitations

N/A
  • Loading branch information
dmkozh authored Aug 7, 2024
1 parent 00ddd27 commit 96832b6
Show file tree
Hide file tree
Showing 38 changed files with 202 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- os: ubuntu-latest
target: wasm32-unknown-unknown
test: false
- os: ubuntu-latest
- os: ubuntu-latest-16-cores
target: x86_64-unknown-linux-gnu
test: true
# TODO: Re-enable these builds if we see value in doing so.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 9 additions & 3 deletions soroban-bench-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ edition = "2021"
rust-version.workspace = true
publish = false

[dependencies]
soroban-env-common = { workspace = true }
tracking-allocator = "=0.4.0"
[target.'cfg(not(target_family = "wasm"))'.dependencies]
tracy-client = { version = "=0.16.4", features = ["enable", "timer-fallback"], default-features = false, optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
perf-event = "0.4.7"

[features]
tracy = ["soroban-env-common/tracy", "dep:tracy-client"]

[dependencies]
soroban-env-common = { workspace = true }
tracking-allocator = "=0.4.0"
10 changes: 5 additions & 5 deletions soroban-bench-utils/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub struct HostTracker<'a> {
mem_tracker: MemTracker,
start_time: Instant,
alloc_guard: Option<AllocationGuard<'a>>,
#[cfg(feature = "tracy")]
#[cfg(all(not(target_family = "wasm"), feature = "tracy"))]
tracy_span: Option<tracy_client::Span>,
}

Expand All @@ -146,16 +146,16 @@ impl<'a> HostTracker<'a> {
mem_tracker,
start_time: Instant::now(),
alloc_guard: None,
#[cfg(feature = "tracy")]
#[cfg(all(not(target_family = "wasm"), feature = "tracy"))]
tracy_span: None,
}
}

pub fn start(&mut self, token: Option<&'a mut AllocationGroupToken>) {
// start the mem measurement
#[cfg(feature = "tracy")]
#[cfg(all(not(target_family = "wasm"), feature = "tracy"))]
{
self.tracy_span = Some(tracy_span!("tracker active"));
self.tracy_span = Some(tracy_client::span!("tracker active"));
}
self.mem_tracker.0.store(0, Ordering::SeqCst);
self.alloc_guard = if let Some(t) = token {
Expand All @@ -179,7 +179,7 @@ impl<'a> HostTracker<'a> {
let mem_bytes = self.mem_tracker.0.load(Ordering::SeqCst);
let time_nsecs = stop_time.duration_since(self.start_time).as_nanos() as u64;
self.alloc_guard = None;
#[cfg(feature = "tracy")]
#[cfg(all(not(target_family = "wasm"), feature = "tracy"))]
{
self.tracy_span = None
}
Expand Down
1 change: 1 addition & 0 deletions soroban-env-host/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-check-cfg=cfg(opt_build)");
let opt_level = std::env::var("OPT_LEVEL").unwrap_or_else(|_| "0".to_string());
if opt_level != "0" {
println!("cargo:rustc-cfg=opt_build");
Expand Down
4 changes: 3 additions & 1 deletion soroban-test-wasms/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
PROTOCOL_VERSION ?=

regenerate-test-wasms:
make -C wasm-workspace regenerate-test-wasms
make PROTOCOL_VERSION=$(PROTOCOL_VERSION) -C wasm-workspace regenerate-test-wasms
129 changes: 62 additions & 67 deletions soroban-test-wasms/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
//! This crate bundles together a bunch of pre-compiled WASM binaries as
//! This crate bundles together a bunch of pre-compiled Wasm binaries as
//! constants that can be used elsewhere in end-to-end tests of the host crate,
//! stellar-core, or other embeddings that need to have some well-formed and
//! meaningful WASM inputs to draw on.
//! meaningful Wasm inputs to draw on.
//!
//! They are generated in (and then here copied out of) the embedded workspace
//! `wasm-workspace` which, confusingly, uses both the adjacent (in-repo)
//! `soroban-env-guest` and `soroban-env-common` crates and _also_ the
//! (external) `soroban-sdk` crate, with its dependencies on `soroban-env-guest`
//! and `soroban-env-common` patched to use the local versions in this repo.
//!
//! Regeneration of the WASMs is _not_ totally automated: we do not know exactly
//! when the WASMs need to be regenerated, and so they _aren't_ unless you
//! Regeneration of the Wasms is _not_ totally automated: we do not know exactly
//! when the Wasms need to be regenerated, and so they _aren't_ unless you
//! manually run `make` in the `wasm-workspace` subdirectory.
//!
//! There are 3 reasons for this crate (and its adjacent .rs inputs) to exist:
//!
//! 1. To centralize the logic for compiling and embedding the .rs inputs into
//! WASM test binaries in a single location, so that other consumers of
//! test WASMs can just refer to this crate, in this repo, by its URL + git
//! Wasm test binaries in a single location, so that other consumers of
//! test Wasms can just refer to this crate, in this repo, by its URL + git
//! hash.
//!
//! 2. To break what would otherwise be an awkward and multi-step cross-repo
//! cyclical dependency between `rs-soroban-sdk` (or wherever the WASM test
//! cyclical dependency between `rs-soroban-sdk` (or wherever the Wasm test
//! inputs live) and the `rs-soroban-env` repo. Specifically when we make a
//! change to the env interface version number in
//! `rs-soroban-env/soroban-env-common`, we need to regenerate the WASMs so
//! that the WASM-based tests in `rs-soroban-env/soroban-env-host` still
//! pass; but if we store the test WASMs and their .rs inputs in a separate
//! `rs-soroban-env/soroban-env-common`, we need to regenerate the Wasms so
//! that the Wasm-based tests in `rs-soroban-env/soroban-env-host` still
//! pass; but if we store the test Wasms and their .rs inputs in a separate
//! repo (worst of all the SDK repo) we would need to patch it to refer
//! back to the local path of the `rs-soroban-env` repo containing our
//! change-in-progress to `rs-soroban-env/soroban-env-common`, and then
//! copy the WASMs back into `rs-soroban-env/soroban-env-host`. By storing
//! the WASMs and their .rs inputs in 'rs-soroban-env', here in the
//! copy the Wasms back into `rs-soroban-env/soroban-env-host`. By storing
//! the Wasms and their .rs inputs in 'rs-soroban-env', here in the
//! embedded `wasm-workspace` directory, we can (somewhat) contain this
//! mess, writing down the necessary patch directive permanently and
//! including the `.wasm` files directly from the embedded workspace.
Expand All @@ -42,60 +42,55 @@
//! documentation purpopses without having to worry about breaking tests in
//! the host here.

pub use curr::*;
// Protocol 20 Wasms.
pub const ADD_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_add_i32.wasm").as_slice();
pub const SUM_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_sum_i32.wasm").as_slice();
pub const ADD_F32: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_add_f32.wasm").as_slice();
pub const ALLOC: &[u8] = include_bytes!("../wasm-workspace/opt/20/example_alloc.wasm").as_slice();
pub const CREATE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_create_contract.wasm").as_slice();
pub const CONTRACT_STORAGE: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_contract_data.wasm").as_slice();
pub const LINEAR_MEMORY: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_linear_memory.wasm").as_slice();
pub const LOADGEN: &[u8] = include_bytes!("../wasm-workspace/opt/20/loadgen.wasm").as_slice();
pub const VEC: &[u8] = include_bytes!("../wasm-workspace/opt/20/example_vec.wasm").as_slice();
pub const INVOKE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_invoke_contract.wasm").as_slice();
pub const HOSTILE: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_hostile.wasm").as_slice();
pub const FIB: &[u8] = include_bytes!("../wasm-workspace/opt/20/example_fib.wasm").as_slice();
pub const FANNKUCH: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_fannkuch.wasm").as_slice();
pub const COMPLEX: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_complex.wasm").as_slice();
pub const SIMPLE_ACCOUNT_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_simple_account.wasm").as_slice();
pub const AUTH_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/auth_test_contract.wasm").as_slice();
pub const UPDATEABLE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_updateable_contract.wasm").as_slice();
pub const UPLOAD_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/example_upload_contract.wasm").as_slice();
pub const DELEGATED_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/test_delegated_account.wasm").as_slice();
pub const ERR: &[u8] = include_bytes!("../wasm-workspace/opt/20/example_err.wasm").as_slice();
pub const WRITE_BYTES: &[u8] =
include_bytes!("../wasm-workspace/opt/20/soroban_write_upgrade_bytes_contract.wasm").as_slice();
pub const CONDITIONAL_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/test_conditional_account.wasm").as_slice();
pub const SAC_REENTRY_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/sac_reentry_account.wasm").as_slice();
pub const CONTRACT_SAC_TRANSFER_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/contract_sac_transfer.wasm").as_slice();
pub const RECURSIVE_ACCOUNT_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/recursive_account.wasm").as_slice();

mod curr {
pub const ADD_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_add_i32.wasm").as_slice();
pub const SUM_I32: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_sum_i32.wasm").as_slice();
pub const ADD_F32: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_add_f32.wasm").as_slice();
pub const ALLOC: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_alloc.wasm").as_slice();
pub const CREATE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_create_contract.wasm").as_slice();
pub const CONTRACT_STORAGE: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_contract_data.wasm").as_slice();
pub const LINEAR_MEMORY: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_linear_memory.wasm").as_slice();
pub const LOADGEN: &[u8] = include_bytes!("../wasm-workspace/opt/curr/loadgen.wasm").as_slice();
pub const VEC: &[u8] = include_bytes!("../wasm-workspace/opt/curr/example_vec.wasm").as_slice();
pub const INVOKE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_invoke_contract.wasm").as_slice();
pub const HOSTILE: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_hostile.wasm").as_slice();
pub const FIB: &[u8] = include_bytes!("../wasm-workspace/opt/curr/example_fib.wasm").as_slice();
pub const FANNKUCH: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_fannkuch.wasm").as_slice();
pub const COMPLEX: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_complex.wasm").as_slice();
pub const SIMPLE_ACCOUNT_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_simple_account.wasm").as_slice();
pub const AUTH_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/auth_test_contract.wasm").as_slice();
pub const UPDATEABLE_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_updateable_contract.wasm").as_slice();
pub const UPLOAD_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/example_upload_contract.wasm").as_slice();
pub const DELEGATED_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/test_delegated_account.wasm").as_slice();
pub const ERR: &[u8] = include_bytes!("../wasm-workspace/opt/curr/example_err.wasm").as_slice();
pub const WRITE_BYTES: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/soroban_write_upgrade_bytes_contract.wasm")
.as_slice();
pub const CONDITIONAL_ACCOUNT_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/test_conditional_account.wasm").as_slice();
pub const SAC_REENTRY_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/sac_reentry_account.wasm").as_slice();
pub const CONTRACT_SAC_TRANSFER_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/contract_sac_transfer.wasm").as_slice();
pub const RECURSIVE_ACCOUNT_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/recursive_account.wasm").as_slice();
pub const HOSTILE_LARGE_VALUE: &[u8] =
include_bytes!("../wasm-workspace/opt/20/hostile_large_val.wasm").as_slice();

pub const HOSTILE_LARGE_VALUE: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/hostile_large_val.wasm").as_slice();

pub const DEPLOYER_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/curr/test_deployer.wasm").as_slice();
}
pub const DEPLOYER_TEST_CONTRACT: &[u8] =
include_bytes!("../wasm-workspace/opt/20/test_deployer.wasm").as_slice();
Loading

0 comments on commit 96832b6

Please sign in to comment.