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

code coverage suite #848

Open
wants to merge 47 commits into
base: devnet-ready
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8e98f43
fix typo
sam0x17 Sep 26, 2024
a4ed75a
code coverage WIP
sam0x17 Sep 28, 2024
b63f4c4
coverage metadata scaffold
sam0x17 Sep 30, 2024
377bc66
set up deps
sam0x17 Sep 30, 2024
dda202a
basic parsing
sam0x17 Sep 30, 2024
d612fb9
pallet visitor
sam0x17 Oct 1, 2024
1c9acbf
PalletVisitor :boom:
sam0x17 Oct 1, 2024
3600b67
tweak mutability
sam0x17 Oct 1, 2024
898cce8
almost
sam0x17 Oct 1, 2024
b0c6806
procedural-fork tests properly ignored
sam0x17 Oct 1, 2024
2706ac2
revert
sam0x17 Oct 1, 2024
bbc7855
modify update.sh to append proper ignores to each file
sam0x17 Oct 1, 2024
f16fc18
detection of platform-specific sed behavior
sam0x17 Oct 1, 2024
d434181
in script: remove all `#[cfg(test)]` lines from `pallet/parse/mod.rs`
sam0x17 Oct 1, 2024
e329132
add update.sh section to add #[ignore] to all #[test]
sam0x17 Oct 1, 2024
845cde8
don't prepend `#[ignore]` to top of each file
sam0x17 Oct 1, 2024
6b7588b
fix
sam0x17 Oct 1, 2024
75b68b9
successfully identifying pallets
sam0x17 Oct 1, 2024
ef6244a
increase verbosity while we debug subtensor pallet
sam0x17 Oct 1, 2024
f70dd00
tweak
sam0x17 Oct 1, 2024
eb1b0a9
document a path forward for resolving #[import_section(..)]
sam0x17 Oct 2, 2024
daafe8e
works in principle!
sam0x17 Oct 2, 2024
5c1eb4c
clean up
sam0x17 Oct 2, 2024
661a63b
parallelize pallet section searching
sam0x17 Oct 2, 2024
ab44805
cleaned up parsing :tada:
sam0x17 Oct 2, 2024
b32d051
fix
sam0x17 Oct 2, 2024
9e21e5c
correct comment
sam0x17 Oct 3, 2024
d6ddd0e
refactor
sam0x17 Oct 3, 2024
dc00275
clean up significantly
sam0x17 Oct 4, 2024
24658d0
collect method calls
sam0x17 Oct 4, 2024
1257432
no need to hard-code `macros` directory
sam0x17 Oct 4, 2024
b0cc18b
WIP
sam0x17 Oct 4, 2024
84c687d
use a proper map-reduce for analyze_files
sam0x17 Oct 7, 2024
5269e3a
find_tests scaffold
sam0x17 Oct 7, 2024
5ee1d2b
accumulate list of tests in parallel
sam0x17 Oct 7, 2024
07084c1
collect TestInfo
sam0x17 Oct 7, 2024
e0f9f39
compiling report, still optimizing
sam0x17 Oct 7, 2024
5a8dc6e
preliminary coverage report working :tada:
sam0x17 Oct 7, 2024
f5d4c68
clippy fixes
sam0x17 Oct 9, 2024
56bb900
cargo fmt
sam0x17 Oct 9, 2024
f2461d9
cargo update
sam0x17 Oct 9, 2024
6de7b76
Merge remote-tracking branch 'origin/devnet-ready' into sam-test-cove…
sam0x17 Oct 9, 2024
867e252
Upgrade benchmarking v1 syntax to v2
keithtensor Oct 10, 2024
bdeb29e
Disallow V1 benchmarks syntax
keithtensor Oct 11, 2024
38d3b21
Merge branch 'devnet-ready' into sam-test-coverage
keithtensor Oct 15, 2024
fdd07d5
Collect benchmarks and mark cals inside of them as tested
keithtensor Oct 17, 2024
ba4ed6f
cargo fmt
keithtensor Oct 17, 2024
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
243 changes: 158 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ node-subtensor-runtime = { path = "runtime", version = "4.0.0-dev" }

[build-dependencies]
subtensor-linting = { path = "support/linting", version = "0.1.0" }
subtensor-code-coverage = { path = "support/code-coverage", version = "0.1.0" }
build-print.workspace = true
syn.workspace = true
quote.workspace = true
proc-macro2.workspace = true
walkdir.workspace = true
rayon = "1.10"
rayon.workspace = true

[workspace]
members = [
Expand All @@ -34,8 +36,8 @@ members = [
"support/macros",
"support/linting",
"support/procedural-fork",
"support/code-coverage",
]
exclude = ["support/procedural-fork"]
resolver = "2"

[workspace.lints.clippy]
Expand All @@ -46,6 +48,8 @@ unwrap-used = "deny"
manual_inspect = "allow"

[workspace.dependencies]
rayon = "1"
build-print = "0.1"
cargo-husky = { version = "1", default-features = false }
clap = "4.5.4"
codec = { version = "3.2.2", default-features = false }
Expand Down Expand Up @@ -157,6 +161,8 @@ substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1" }
frame-metadata = "16"

procedural-fork = { version = "1.10.0-rc3", path = "support/procedural-fork" }

[profile.release]
panic = "unwind"

Expand Down
44 changes: 7 additions & 37 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use rayon::prelude::*;
use std::{
env, fs,
path::{Path, PathBuf},
str::FromStr,
sync::mpsc::channel,
};
use walkdir::WalkDir;
use std::{env, fs, path::Path, str::FromStr, sync::mpsc::channel};
use subtensor_code_coverage::collect_rust_files;

use subtensor_linting::*;

Expand All @@ -14,7 +9,6 @@ fn main() {
println!("cargo:rerun-if-changed=pallets");
println!("cargo:rerun-if-changed=node");
println!("cargo:rerun-if-changed=runtime");
println!("cargo:rerun-if-changed=lints");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src");
println!("cargo:rerun-if-changed=support");
Expand All @@ -25,6 +19,9 @@ fn main() {
// Collect all Rust source files in the workspace
let rust_files = collect_rust_files(workspace_root);

// Generate code coverage report
subtensor_code_coverage::analyze_files(&rust_files, workspace_root);

// Channel used to communicate errors back to the main thread from the parallel processing
// as we process each Rust file
let (tx, rx) = channel();
Expand All @@ -49,8 +46,7 @@ fn main() {
for error in errors {
let loc = error.span().start();
let file_path = relative_path.display();
// note that spans can't go across thread boundaries without losing their location
// info so we we serialize here and send a String
// note that spans can't go across thread boundaries so we serialize here and send a String
tx.send(format!(
"cargo:warning={}:{}:{}: {}",
file_path, loc.line, loc.column, error,
Expand All @@ -59,6 +55,7 @@ fn main() {
}
};

track_lint(DisallowV1Benchmarks::lint(&parsed_file));
track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file));
track_lint(RequireFreezeStruct::lint(&parsed_file));
track_lint(RequireExplicitPalletIndex::lint(&parsed_file));
Expand All @@ -71,30 +68,3 @@ fn main() {
println!("{error}");
}
}

/// Recursively collects all Rust files in the given directory
fn collect_rust_files(dir: &Path) -> Vec<PathBuf> {
let mut rust_files = Vec::new();

for entry in WalkDir::new(dir) {
let Ok(entry) = entry else {
continue;
};
let path = entry.path();

// Skip any path that contains "target" directory
if path
.components()
.any(|component| component.as_os_str() == "target")
|| path.ends_with("build.rs")
{
continue;
}

if path.is_file() && path.extension().and_then(|ext| ext.to_str()) == Some("rs") {
rust_files.push(path.to_path_buf());
}
}

rust_files
}
Loading
Loading