Use cargo-test-bpf

This commit is contained in:
Michael Vines 2020-11-04 20:36:06 -08:00
parent 64823d9968
commit 901d43f965
11 changed files with 34 additions and 77 deletions

2
.gitignore vendored
View File

@ -5,5 +5,3 @@ bin
config.json config.json
node_modules node_modules
./package-lock.json ./package-lock.json
*.so
*-dump.txt

View File

@ -10,6 +10,5 @@ if [[ $1 = -v ]]; then
export RUST_LOG=solana=debug export RUST_LOG=solana=debug
fi fi
bpf=1 cargo test cargo test
# TODO: bpf=0 not supported until native CPI rework in the monorepo completes cargo test-bpf
#bpf=0 cargo test

View File

@ -16,16 +16,17 @@ set -x
for Xargo_toml in $(git ls-files -- '*/Xargo.toml'); do for Xargo_toml in $(git ls-files -- '*/Xargo.toml'); do
program_dir=$(dirname "$Xargo_toml") program_dir=$(dirname "$Xargo_toml")
if [ "$program_dir" == "token-swap/program" ]; then if [ "$program_dir" == "token-swap/program" ]; then
address="SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8" address="SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8"
SWAP_PROGRAM_OWNER_FEE_ADDRESS="$address" cargo build-bpf --manifest-path=token-swap/program/Cargo.toml --dump --features production SWAP_PROGRAM_OWNER_FEE_ADDRESS="$address" cargo build-bpf \
mv spl_token_swap.so spl_token_swap_production.so --manifest-path=token-swap/program/Cargo.toml \
fi --dump --features production
mv target/deploy/spl_token_swap.so target/deploy/spl_token_swap_production.so
fi
cargo +"$rust_stable" build-bpf --manifest-path="$program_dir"/Cargo.toml --dump cargo +"$rust_stable" test-bpf --manifest-path="$program_dir"/Cargo.toml -- --nocapture
done done
cargo +"$rust_stable" build cargo +"$rust_stable" build
cargo +"$rust_stable" test -- --nocapture cargo +"$rust_stable" test -- --nocapture
cargo +"$rust_stable" run --manifest-path=utils/test-client/Cargo.toml cargo +"$rust_stable" run --manifest-path=utils/test-client/Cargo.toml

View File

@ -14,7 +14,7 @@
if [[ -n $SOLANA_VERSION ]]; then if [[ -n $SOLANA_VERSION ]]; then
solana_version="$SOLANA_VERSION" solana_version="$SOLANA_VERSION"
else else
solana_version=v1.4.4 solana_version=v1.4.5
fi fi
export solana_version="$solana_version" export solana_version="$solana_version"

View File

@ -1,21 +0,0 @@
use std::process::{exit, Command};
fn main() {
if std::env::var("XARGO").is_err()
&& 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()
);
if !Command::new("cargo")
.arg("build-bpf")
.status()
.expect("Failed to build BPF shared-memory program")
.success()
{
exit(1);
}
}
}

View File

@ -11,14 +11,11 @@ use solana_sdk::{
account::Account, keyed_account::KeyedAccount, process_instruction::MockInvokeContext, account::Account, keyed_account::KeyedAccount, process_instruction::MockInvokeContext,
}; };
use spl_shared_memory::entrypoint; 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> { fn load_program(name: &str) -> Vec<u8> {
let mut path = PathBuf::new(); let mut file =
path.push(name); File::open(&name).unwrap_or_else(|err| panic!("Unable to open {}: {}", name, err));
path.set_extension("so");
let mut file = File::open(&path)
.unwrap_or_else(|err| panic!("Unable to open {}: {}", path.display(), err));
let mut program = Vec::new(); let mut program = Vec::new();
file.read_to_end(&mut program).unwrap(); file.read_to_end(&mut program).unwrap();
@ -31,7 +28,7 @@ fn run_program(
instruction_data: &[u8], instruction_data: &[u8],
) -> Result<u64, InstructionError> { ) -> Result<u64, InstructionError> {
let mut program_account = Account::default(); 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 loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default(); let mut invoke_context = MockInvokeContext::default();
let executable = EbpfVm::<solana_bpf_loader_program::BPFError>::create_executable_from_elf( let executable = EbpfVm::<solana_bpf_loader_program::BPFError>::create_executable_from_elf(

View File

@ -5,16 +5,20 @@ fn main() {
&& std::env::var("RUSTC_WRAPPER").is_err() && std::env::var("RUSTC_WRAPPER").is_err()
&& std::env::var("RUSTC_WORKSPACE_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") if !Command::new("cargo")
.args(&[ .args(&[
"build-bpf", "build-bpf",
"--manifest-path", "--manifest-path",
"../program_ristretto/Cargo.toml", "../program_ristretto/Cargo.toml",
]) ])
.status() .status()
.expect("Failed to build BPF themis program") .expect("Failed to build BPF themis program")
.success() { .success()
{
exit(1); exit(1);
} }
} }

View File

@ -20,11 +20,10 @@ use spl_themis_ristretto::{
instruction::ThemisInstruction, instruction::ThemisInstruction,
state::{generate_keys, /*recover_scalar,*/ Policies, User}, 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> { fn load_program(name: &str) -> Vec<u8> {
let path = PathBuf::from(name).with_extension("so"); let mut file = File::open(name).unwrap();
let mut file = File::open(path).unwrap();
let mut program = Vec::new(); let mut program = Vec::new();
file.read_to_end(&mut program).unwrap(); file.read_to_end(&mut program).unwrap();
@ -37,7 +36,7 @@ fn run_program(
instruction_data: &[u8], instruction_data: &[u8],
) -> Result<u64, InstructionError> { ) -> Result<u64, InstructionError> {
let mut program_account = Account::default(); 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 loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default(); let mut invoke_context = MockInvokeContext::default();
invoke_context.bpf_compute_budget = BpfComputeBudget { invoke_context.bpf_compute_budget = BpfComputeBudget {

View File

@ -16,15 +16,13 @@ use spl_themis_ristretto_client::{process_transactions_with_commitment, test_e2e
use std::{ use std::{
fs::{remove_dir_all, File}, fs::{remove_dir_all, File},
io::Read, io::Read,
path::PathBuf,
}; };
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
const DATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE const DATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE
fn load_program(name: &str) -> Vec<u8> { fn load_program(name: &str) -> Vec<u8> {
let path = PathBuf::from(name).with_extension("so"); let mut file = File::open(name).unwrap();
let mut file = File::open(path).unwrap();
let mut program = Vec::new(); let mut program = Vec::new();
file.read_to_end(&mut program).unwrap(); file.read_to_end(&mut program).unwrap();
@ -161,7 +159,7 @@ fn test_validator_e2e() {
..TestValidatorOptions::default() ..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 { Runtime::new().unwrap().block_on(async {
let mut banks_client = start_tcp_client(leader_data.rpc_banks).await.unwrap(); let mut banks_client = start_tcp_client(leader_data.rpc_banks).await.unwrap();

View File

@ -1,18 +0,0 @@
use std::process::{exit, Command};
fn main() {
if std::env::var("XARGO").is_err()
&& std::env::var("RUSTC_WRAPPER").is_err()
&& std::env::var("RUSTC_WORKSPACE_WRAPPER").is_err()
{
println!("cargo:warning=(not a warning) Building BPF token program");
if !Command::new("cargo")
.args(&["build-bpf", "--manifest-path", "../program/Cargo.toml"])
.status()
.expect("Failed to build BPF token program")
.success()
{
exit(1);
}
}
}

View File

@ -35,7 +35,7 @@ fn run_program(
instruction_data: &[u8], instruction_data: &[u8],
) -> Result<u64, InstructionError> { ) -> Result<u64, InstructionError> {
let mut program_account = SolanaAccount::default(); 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 loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default(); let mut invoke_context = MockInvokeContext::default();