Skip to content

Commit

Permalink
ci: test-checks.sh all sbf code & use nightly only (#30602)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun authored Mar 13, 2023
1 parent c4b2639 commit 7f58345
Show file tree
Hide file tree
Showing 35 changed files with 78 additions and 17 deletions.
11 changes: 5 additions & 6 deletions ci/test-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ echo --- build environment
export RUST_BACKTRACE=1
export RUSTFLAGS="-D warnings -A incomplete_features"

# run cargo check for all rust files in this monorepo for faster turnaround in
# case of any compilation/build error for nightly

# Only force up-to-date lock files on edge
if [[ $CI_BASE_BRANCH = "$EDGE_CHANNEL" ]]; then
# Exclude --benches as it's not available in rust stable yet
if _ scripts/cargo-for-all-lock-files.sh check --locked --tests --bins --examples; then
if _ scripts/cargo-for-all-lock-files.sh "+${rust_nightly}" check --locked --workspace --all-targets --features dummy-for-ci-check; then
true
else
check_status=$?
Expand All @@ -63,9 +65,6 @@ if [[ $CI_BASE_BRANCH = "$EDGE_CHANNEL" ]]; then
echo "$0: [tree (for outdated Cargo.lock sync)|check (for compilation error)|update -p foo --precise x.y.z (for your Cargo.toml update)] ..." >&2
exit "$check_status"
fi

# Ensure nightly and --benches
_ scripts/cargo-for-all-lock-files.sh "+${rust_nightly}" check --locked --all-targets
else
echo "Note: cargo-for-all-lock-files.sh skipped because $CI_BASE_BRANCH != $EDGE_CHANNEL"
fi
Expand All @@ -76,7 +75,7 @@ nightly_clippy_allows=()

# -Z... is needed because of clippy bug: https://github.com/rust-lang/rust-clippy/issues/4612
# run nightly clippy for `sdk/` as there's a moderate amount of nightly-only code there
_ scripts/cargo-for-all-lock-files.sh -- "+${rust_nightly}" clippy -Zunstable-options --all-targets -- \
_ scripts/cargo-for-all-lock-files.sh -- "+${rust_nightly}" clippy -Zunstable-options --workspace --all-targets --features dummy-for-ci-check -- \
--deny=warnings \
--deny=clippy::integer_arithmetic \
"${nightly_clippy_allows[@]}"
Expand Down
4 changes: 4 additions & 0 deletions programs/sbf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ edition = { workspace = true }
[features]
sbf_c = []
sbf_rust = []
dummy-for-ci-check = [
"sbf_c",
"sbf_rust",
]

[build-dependencies]
walkdir = "2"
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(test)]
#![cfg(feature = "sbf_c")]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::integer_arithmetic)]

use {solana_rbpf::memory_region::MemoryState, std::slice};

Expand Down
5 changes: 5 additions & 0 deletions programs/sbf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ fn rerun_if_changed(files: &[&str], directories: &[&str], excludes: &[&str]) {
}

fn main() {
if env::var("CARGO_FEATURE_DUMMY_FOR_CI_CHECK").is_ok() {
println!("cargo:warning=(not a warning) Compiling with host toolchain for CI...");
return;
}

let sbf_c = env::var("CARGO_FEATURE_SBF_C").is_ok();
if sbf_c {
let install_dir = "OUT_DIR=../target/".to_string() + &env::var("PROFILE").unwrap() + "/sbf";
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/128bit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program tests loop iteration
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{custom_heap_default, custom_panic_default, entrypoint::SUCCESS};

Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/128bit_dep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Solana Rust-based SBF program utility functions and types
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;

pub fn uadd(x: u128, y: u128) -> u128 {
Expand Down
4 changes: 3 additions & 1 deletion programs/sbf/rust/alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program that test dynamic memory allocation
#![allow(clippy::integer_arithmetic)]

#[macro_use]
extern crate alloc;
use {
Expand Down Expand Up @@ -37,7 +39,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
*ptr.add(i) = i as u8;
}
for i in 0..ITERS {
assert_eq!(*ptr.add(i as usize), i as u8);
assert_eq!(*ptr.add(i), i as u8);
}
sol_log_64(0x3, 0, 0, 0, u64::from(*ptr.add(42)));
assert_eq!(*ptr.add(42), 42);
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/custom_heap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF that tests out using a custom heap
#![allow(clippy::integer_arithmetic)]

use {
solana_program::{
account_info::AccountInfo,
Expand Down
3 changes: 2 additions & 1 deletion programs/sbf/rust/deprecated_loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Example Rust-based SBF program that supports the deprecated loader
#![allow(unreachable_code)]
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{
Expand All @@ -23,7 +24,7 @@ fn return_sstruct() -> SStruct {
#[no_mangle]
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
// Full panic reporting
msg!(&format!("{}", info));
msg!(&format!("{info}"));
}

solana_program::entrypoint_deprecated!(process_instruction);
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/dup_accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program that tests duplicate accounts passed via accounts
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{
account_info::AccountInfo,
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/external_spend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program that moves a lamport from one account to another
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ custom_heap_default!();
#[no_mangle]
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
// Full panic reporting
msg!(&format!("{}", info));
msg!(&format!("{info}"));
}
2 changes: 1 addition & 1 deletion programs/sbf/rust/instruction_introspection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn process_instruction(
msg!(&format!("id: {}", instruction.program_id));

msg!(&format!("data[0]: {}", instruction.data[0]));
msg!(&format!("index: {}", current_instruction));
msg!(&format!("index: {current_instruction}"));

if instruction_data.len() == 2 {
// CPI ourself with the same arguments to confirm the instructions sysvar reports the same
Expand Down
1 change: 1 addition & 0 deletions programs/sbf/rust/invoked/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Example Rust-based SBF program that issues a cross-program-invocation
#![cfg(feature = "program")]
#![allow(clippy::integer_arithmetic)]

use {
crate::instructions::*,
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/iter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program tests loop iteration
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{
custom_heap_default, custom_panic_default, entrypoint::SUCCESS, log::sol_log_64,
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/many_args/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program tests loop iteration
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::log::*;

Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/many_args_dep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Solana Rust-based SBF program utility functions and types
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{log::sol_log_64, msg};

Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/mem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ edition = { workspace = true }

[features]
no-entrypoint = []
test-bpf = []
dummy-for-ci-check = ["test-bpf"]

[dependencies]
solana-program = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/mem/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Test mem functions
#[cfg(not(feature = "no-entrypoint"))]
#[cfg(any(not(feature = "no-entrypoint"), feature = "test-bpf"))]
pub mod entrypoint;

pub trait MemOps {
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/mem/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "test-bpf")]

use {
solana_program_test::*,
solana_sbf_rust_mem::entrypoint::process_instruction,
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/panic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
// Note: Full panic reporting is included here for testing purposes
solana_program::msg!("program custom panic enabled");
solana_program::msg!(&format!("{}", info));
solana_program::msg!(&format!("{info}"));
}

extern crate solana_program;
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/param_passing_dep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example Rust-based SBF program tests loop iteration
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions programs/sbf/rust/sanity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = { workspace = true }

[features]
test-bpf = []
dummy-for-ci-check = ["test-bpf"]

[dependencies]
solana-program = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions programs/sbf/rust/sanity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Example Rust-based SBF sanity program that prints out the parameters passed to it
#![allow(unreachable_code)]
#![allow(clippy::integer_arithmetic)]

extern crate solana_program;
use solana_program::{
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/sanity/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
};

#[tokio::test]
async fn test_sysvars() {
async fn test_sanity() {
let program_id = Pubkey::new_unique();
let program_test = ProgramTest::new(
"solana_sbf_rust_sanity",
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/secp256k1_recover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn test_secp256k1_recover_malleability() {
let signature = libsecp256k1::Signature::parse_standard_slice(&signature_bytes).unwrap();

// Flip the S value in the signature to make a different but valid signature.
let mut alt_signature = signature.clone();
let mut alt_signature = signature;
alt_signature.s = -alt_signature.s;
let alt_recovery_id = libsecp256k1::RecoveryId::parse(recovery_id ^ 1).unwrap();

Expand Down
1 change: 1 addition & 0 deletions programs/sbf/rust/sibling_inner_instruction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Example Rust-based SBF program that queries sibling instructions
#![cfg(feature = "program")]
#![allow(clippy::integer_arithmetic)]

use solana_program::{
account_info::AccountInfo,
Expand Down
4 changes: 3 additions & 1 deletion programs/sbf/rust/simulation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::integer_arithmetic)]

use {
solana_program::{
account_info::{next_account_info, AccountInfo},
Expand Down Expand Up @@ -29,7 +31,7 @@ pub fn process_instruction(
let slot: u64 = u64::from_le_bytes(data[data.len() - 8..].try_into().unwrap());

let clock_from_cache = Clock::get().unwrap();
let clock_from_account = Clock::from_account_info(&clock_account_info).unwrap();
let clock_from_account = Clock::from_account_info(clock_account_info).unwrap();

msg!("next_slot from slot history is {:?} ", slot);
msg!("clock from cache is in slot {:?} ", clock_from_cache.slot);
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/simulation/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
};

#[tokio::test]
async fn no_panic() {
async fn no_panic_banks_client() {
let program_id = Pubkey::new_unique();
let program_test = ProgramTest::new(
"solana_sbf_rust_simulation",
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/rust/simulation/tests/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
};

#[test]
fn no_panic() {
fn no_panic_rpc_client() {
solana_logger::setup_with_default("solana_program_runtime=debug");
let program_id = Pubkey::new_unique();

Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/spoof1_system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::integer_arithmetic)]

use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

solana_program::entrypoint!(process_instruction);
Expand Down
4 changes: 4 additions & 0 deletions programs/sbf/rust/sysvar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ edition = { workspace = true }
[dependencies]
solana-program = { workspace = true }

[features]
test-bpf = []
dummy-for-ci-check = ["test-bpf"]

[dev-dependencies]
solana-program-runtime = { workspace = true }
solana-program-test = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/rust/sysvar/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "test-bpf")]

use {
solana_program_test::*,
solana_sbf_rust_sysvar::process_instruction,
Expand Down
9 changes: 9 additions & 0 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#![cfg(any(feature = "sbf_c", feature = "sbf_rust"))]
#![allow(clippy::clone_on_copy)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::redundant_clone)]
#![allow(clippy::needless_borrow)]
#![allow(clippy::cmp_owned)]
#![allow(clippy::needless_collect)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::uninlined_format_args)]

#[macro_use]
extern crate solana_bpf_loader_program;
Expand Down
3 changes: 3 additions & 0 deletions version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ solana-frozen-abi = { workspace = true }
solana-frozen-abi-macro = { workspace = true }
solana-sdk = { workspace = true }

[features]
dummy-for-ci-check = []

[lib]
name = "solana_version"

Expand Down

0 comments on commit 7f58345

Please sign in to comment.