Skip to content

Commit

Permalink
Use cargo-test-bpf
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Nov 7, 2020
1 parent 64823d9 commit 901d43f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ bin
config.json
node_modules
./package-lock.json
*.so
*-dump.txt
5 changes: 2 additions & 3 deletions associated-token-account/program/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ if [[ $1 = -v ]]; then
export RUST_LOG=solana=debug
fi

bpf=1 cargo test
# TODO: bpf=0 not supported until native CPI rework in the monorepo completes
#bpf=0 cargo test
cargo test
cargo test-bpf
17 changes: 9 additions & 8 deletions ci/cargo-build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ set -x
for Xargo_toml in $(git ls-files -- '*/Xargo.toml'); do
program_dir=$(dirname "$Xargo_toml")

if [ "$program_dir" == "token-swap/program" ]; then
address="SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"
SWAP_PROGRAM_OWNER_FEE_ADDRESS="$address" cargo build-bpf --manifest-path=token-swap/program/Cargo.toml --dump --features production
mv spl_token_swap.so spl_token_swap_production.so
fi

cargo +"$rust_stable" build-bpf --manifest-path="$program_dir"/Cargo.toml --dump
if [ "$program_dir" == "token-swap/program" ]; then
address="SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"
SWAP_PROGRAM_OWNER_FEE_ADDRESS="$address" cargo build-bpf \
--manifest-path=token-swap/program/Cargo.toml \
--dump --features production
mv target/deploy/spl_token_swap.so target/deploy/spl_token_swap_production.so
fi

cargo +"$rust_stable" test-bpf --manifest-path="$program_dir"/Cargo.toml -- --nocapture
done


cargo +"$rust_stable" build
cargo +"$rust_stable" test -- --nocapture
cargo +"$rust_stable" run --manifest-path=utils/test-client/Cargo.toml
Expand Down
2 changes: 1 addition & 1 deletion ci/solana-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if [[ -n $SOLANA_VERSION ]]; then
solana_version="$SOLANA_VERSION"
else
solana_version=v1.4.4
solana_version=v1.4.5
fi

export solana_version="$solana_version"
Expand Down
21 changes: 0 additions & 21 deletions shared-memory/program/build.rs

This file was deleted.

11 changes: 4 additions & 7 deletions shared-memory/program/tests/shared-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use solana_sdk::{
account::Account, keyed_account::KeyedAccount, process_instruction::MockInvokeContext,
};
use spl_shared_memory::entrypoint;
use std::{fs::File, io::Read, path::PathBuf};
use std::{fs::File, io::Read};

fn load_program(name: &str) -> Vec<u8> {
let mut path = PathBuf::new();
path.push(name);
path.set_extension("so");
let mut file = File::open(&path)
.unwrap_or_else(|err| panic!("Unable to open {}: {}", path.display(), err));
let mut file =
File::open(&name).unwrap_or_else(|err| panic!("Unable to open {}: {}", name, err));

let mut program = Vec::new();
file.read_to_end(&mut program).unwrap();
Expand All @@ -31,7 +28,7 @@ fn run_program(
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
let mut program_account = Account::default();
program_account.data = load_program("spl_shared_memory");
program_account.data = load_program("../../target/deploy/spl_shared_memory.so");
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
let executable = EbpfVm::<solana_bpf_loader_program::BPFError>::create_executable_from_elf(
Expand Down
22 changes: 13 additions & 9 deletions themis/client_ristretto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ fn main() {
&& std::env::var("RUSTC_WRAPPER").is_err()
&& std::env::var("RUSTC_WORKSPACE_WRAPPER").is_err()
{
println!("cargo:warning=(not a warning) Building BPF {} program", std::env::var("CARGO_PKG_NAME").unwrap());
println!(
"cargo:warning=(not a warning) Building BPF {} program",
std::env::var("CARGO_PKG_NAME").unwrap()
);
if !Command::new("cargo")
.args(&[
"build-bpf",
"--manifest-path",
"../program_ristretto/Cargo.toml",
])
.status()
.expect("Failed to build BPF themis program")
.success() {
.args(&[
"build-bpf",
"--manifest-path",
"../program_ristretto/Cargo.toml",
])
.status()
.expect("Failed to build BPF themis program")
.success()
{
exit(1);
}
}
Expand Down
7 changes: 3 additions & 4 deletions themis/client_ristretto/tests/assert_instruction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ use spl_themis_ristretto::{
instruction::ThemisInstruction,
state::{generate_keys, /*recover_scalar,*/ Policies, User},
};
use std::{fs::File, io::Read, path::PathBuf};
use std::{fs::File, io::Read};

fn load_program(name: &str) -> Vec<u8> {
let path = PathBuf::from(name).with_extension("so");
let mut file = File::open(path).unwrap();
let mut file = File::open(name).unwrap();

let mut program = Vec::new();
file.read_to_end(&mut program).unwrap();
Expand All @@ -37,7 +36,7 @@ fn run_program(
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
let mut program_account = Account::default();
program_account.data = load_program("spl_themis_ristretto");
program_account.data = load_program("../../target/deploy/spl_themis_ristretto.so");
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
invoke_context.bpf_compute_budget = BpfComputeBudget {
Expand Down
6 changes: 2 additions & 4 deletions themis/client_ristretto/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ use spl_themis_ristretto_client::{process_transactions_with_commitment, test_e2e
use std::{
fs::{remove_dir_all, File},
io::Read,
path::PathBuf,
};
use tokio::runtime::Runtime;

const DATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE

fn load_program(name: &str) -> Vec<u8> {
let path = PathBuf::from(name).with_extension("so");
let mut file = File::open(path).unwrap();
let mut file = File::open(name).unwrap();

let mut program = Vec::new();
file.read_to_end(&mut program).unwrap();
Expand Down Expand Up @@ -161,7 +159,7 @@ fn test_validator_e2e() {
..TestValidatorOptions::default()
});

let program = load_program("spl_themis_ristretto");
let program = load_program("../../target/deploy/spl_themis_ristretto.so");

Runtime::new().unwrap().block_on(async {
let mut banks_client = start_tcp_client(leader_data.rpc_banks).await.unwrap();
Expand Down
18 changes: 0 additions & 18 deletions token/perf-monitor/build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion token/perf-monitor/tests/assert_instruction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn run_program(
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
let mut program_account = SolanaAccount::default();
program_account.data = load_program("spl_token.so");
program_account.data = load_program("../../target/deploy/spl_token.so");
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();

Expand Down

0 comments on commit 901d43f

Please sign in to comment.