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

chore: Use cfg(fuzz) instead of feature #4368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
runs-on: [kuberunner, github-runner-01]
env:
RUSTUP_HOME: /tmp/rustup_home
RUSTFLAGS: "--cfg fuzz"
steps:
- name: Cancel Previous Runs
if: ${{ github.event_name == 'pull_request' }}
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ fs4 = "0.11.1" # utils/gear-wasmer
bytes = "1.8.0" # utils/gear-wasmer-cache
loom = "0.7.2" # utils/gear-wasmer-cache

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(fuzz)'] }

[profile.dev.package.corosensei]
opt-level = 3

Expand Down
8 changes: 6 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ homepage.workspace = true
repository.workspace = true
rust-version.workspace = true

[lints]
workspace = true

[dependencies]
primitive-types = { workspace = true, features = ["scale-info"] }
log.workspace = true
derive_more.workspace = true
enum-iterator.workspace = true
fail = { workspace = true, features = [ "failpoints" ], optional = true }

# Internal deps
gear-core.workspace = true
Expand All @@ -35,6 +37,9 @@ frame-support.workspace = true
frame-system = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }

[target.'cfg(fuzz)'.dependencies]
fail = { workspace = true, features = [ "failpoints" ] }

[dev-dependencies]
hex-literal.workspace = true
proptest.workspace = true
Expand All @@ -59,4 +64,3 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"gear-wasm-instrument",
]
fuzz = ["fail"]
2 changes: 1 addition & 1 deletion common/src/gas_provider/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ where
let key = key.into();
let mut node = Self::get_node(key).ok_or_else(InternalError::node_not_found)?;

#[cfg(feature = "fuzz")]
#[cfg(fuzz)]
{
let s = fail::FailScenario::setup();
// This is a fail point with name `fail_fuzzer`.
Expand Down
1 change: 0 additions & 1 deletion pallets/gas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ runtime-benchmarks = [
"parity-wasm",
]
try-runtime = ["frame-support/try-runtime"]
fuzz = ["common/fuzz"]
4 changes: 3 additions & 1 deletion pallets/gear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ homepage.workspace = true
repository.workspace = true
readme = "README.md"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand Down Expand Up @@ -204,4 +207,3 @@ runtime-benchmarks = [
]
runtime-benchmarks-checkers = []
try-runtime = ["frame-support/try-runtime"]
fuzz = ["pallet-gear-gas/fuzz", "common/fuzz"]
8 changes: 4 additions & 4 deletions pallets/gear/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ pub const INSTR_BENCHMARK_BATCH_SIZE: u32 = 500;
/// To avoid potential stack overflow problems we have a panic in sandbox in case,
/// execution is ended with stack overflow error. So, process queue execution will be
/// stopped and we will be able to investigate the problem and decrease this constant if needed.
#[cfg(not(feature = "fuzz"))]
#[cfg(not(fuzz))]
pub const STACK_HEIGHT_LIMIT: u32 = 36_743;

/// For the fuzzer, we take the maximum possible stack limit calculated by the `calc-stack-height`
/// utility, which would be suitable for Linux machines. This has a positive effect on code coverage.
#[cfg(feature = "fuzz")]
#[cfg(fuzz)]
pub const FUZZER_STACK_HEIGHT_LIMIT: u32 = 65_000;

/// Maximum number of data segments in a wasm module.
Expand Down Expand Up @@ -823,9 +823,9 @@ impl<T: Config> Default for Schedule<T> {
impl Default for Limits {
fn default() -> Self {
Self {
#[cfg(not(feature = "fuzz"))]
#[cfg(not(fuzz))]
stack_height: Some(STACK_HEIGHT_LIMIT),
#[cfg(feature = "fuzz")]
#[cfg(fuzz)]
stack_height: Some(FUZZER_STACK_HEIGHT_LIMIT),
data_segments_amount: DATA_SEGMENTS_AMOUNT_LIMIT,
globals: 256,
Expand Down
4 changes: 3 additions & 1 deletion runtime/vara/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ build = "build.rs"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[lints]
workspace = true

[dependencies]
const-str.workspace = true
log.workspace = true
Expand Down Expand Up @@ -281,6 +284,5 @@ try-runtime = [
"pallet-bags-list/try-runtime",
"runtime-common/try-runtime",
]
fuzz = ["common/fuzz", "pallet-gear/fuzz", "pallet-gear-gas/fuzz"]
dev = ["pallet-gear-debug", "pallet-gear-eth-bridge", "pallet-sudo"]
metadata-hash = ["substrate-wasm-builder?/metadata-hash"]
4 changes: 2 additions & 2 deletions runtime/vara/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
fn main() {
substrate_build_script_utils::generate_cargo_keys();
#[cfg(all(feature = "std", not(feature = "fuzz")))]
#[cfg(all(feature = "std", not(fuzz)))]
{
substrate_wasm_builder::WasmBuilder::build_using_defaults()
}
Expand All @@ -28,7 +28,7 @@ fn main() {
#[cfg(all(feature = "std", feature = "metadata-hash"))]
fn main() {
substrate_build_script_utils::generate_cargo_keys();
#[cfg(all(feature = "std", not(feature = "fuzz")))]
#[cfg(all(feature = "std", not(fuzz)))]
{
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("VARA", 12)
Expand Down
2 changes: 1 addition & 1 deletion runtime/vara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![allow(non_local_definitions)]

// Make the WASM binary available.
#[cfg(all(feature = "std", not(feature = "fuzz")))]
#[cfg(all(feature = "std", not(fuzz)))]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use common::{storage::Messenger, DelegateFee};
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ EOF
}

gear_build() {
$CARGO build --workspace "$@" --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz
$CARGO build --workspace "$@"
}

fuzzer_build() {
$CARGO build "$@" -p runtime-fuzzer -p runtime-fuzzer-fuzz
RUSTFLAGS="--cfg fuzz" $CARGO build "$@" -p runtime-fuzzer -p runtime-fuzzer-fuzz
}

node_build() {
Expand Down
8 changes: 4 additions & 4 deletions scripts/src/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ EOF
}

gear_check() {
echo " >> Check workspace without crates that use runtime with 'fuzz' feature"
__GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo check --workspace "$@" --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz
echo " >> Check workspace"
__GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo check --workspace "$@"

echo " >> Check crates that use runtime with 'fuzz' feature"
cargo check "$@" -p runtime-fuzzer -p runtime-fuzzer-fuzz
echo " >> Check crates that use 'cfg(fuzz)"
RUSTFLAGS="--cfg fuzz" cargo check "$@" -p gear-common -p vara-runtime -p runtime-fuzzer -p runtime-fuzzer-fuzz
}

runtime_imports() {
Expand Down
8 changes: 5 additions & 3 deletions scripts/src/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ run_fuzzer() {
fi

# Run fuzzer
RUST_LOG="$LOG_TARGETS" cargo fuzz run --release --sanitizer=none main $CORPUS_DIR -- -rss_limit_mb=$RSS_LIMIT_MB -max_len=$MAX_LEN -len_control=0
RUSTFLAGS="--cfg fuzz" RUST_LOG="$LOG_TARGETS" \
cargo fuzz run --release --sanitizer=none main $CORPUS_DIR -- -rss_limit_mb=$RSS_LIMIT_MB -max_len=$MAX_LEN -len_control=0
}

run_lazy_pages_fuzzer() {
. $(dirname "$SELF")/fuzzer_consts.sh

ROOT_DIR="$1"
CORPUS_DIR="$2"
RUSTFLAGS="--cfg fuzz"

# Navigate to lazy pages fuzzer dir
cd $ROOT_DIR/utils/lazy-pages-fuzzer
Expand All @@ -122,7 +124,7 @@ run_lazy_pages_fuzzer() {

run_fuzzer_tests() {
# This includes property tests for runtime-fuzzer.
cargo nextest run -p runtime-fuzzer
RUSTFLAGS="--cfg fuzz" cargo nextest run -p runtime-fuzzer
}

# TODO this is likely to be merged with `pallet_test` or `workspace_test` in #1802
Expand All @@ -134,7 +136,7 @@ doc_test() {
MANIFEST="$1"
shift

__GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 $CARGO test --doc --workspace --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz --manifest-path="$MANIFEST" --no-fail-fast "$@"
__GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 $CARGO test --doc --workspace --manifest-path="$MANIFEST" --no-fail-fast "$@"
}

time_consuming_tests() {
Expand Down
4 changes: 2 additions & 2 deletions utils/gear-wasmer-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ homepage.workspace = true
repository.workspace = true
rust-version.workspace = true

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }
[lints]
workspace = true

[dependencies]
wasmer.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion utils/runtime-fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ runtime-primitives.workspace = true
gear-common.workspace = true
gear-core.workspace = true
gear-utils.workspace = true
vara-runtime = { workspace = true, features = ["std", "dev", "fuzz"] }
vara-runtime = { workspace = true, features = ["std", "dev"] }
pallet-gear.workspace = true
pallet-gear-bank.workspace = true

Expand Down