Cleanup features and fix build errors

This commit is contained in:
Michael Vines
2019-03-02 21:33:02 -08:00
committed by Grimes
parent 534619f72f
commit 109101c2dc
3 changed files with 137 additions and 124 deletions

1
Cargo.lock generated
View File

@ -2035,6 +2035,7 @@ dependencies = [
"solana-bpfloader 0.12.0",
"solana-logger 0.12.0",
"solana-native-loader 0.12.0",
"solana-runtime 0.12.0",
"solana-sdk 0.12.0",
]

View File

@ -22,4 +22,5 @@ solana = { path = "../../core", version = "0.12.0" }
solana-bpfloader = { path = "../bpf_loader", version = "0.12.0" }
solana-logger = { path = "../../logger", version = "0.12.0" }
solana-native-loader = { path = "../native_loader", version = "0.12.0" }
solana-runtime = { path = "../../runtime", version = "0.12.0" }
solana-sdk = { path = "../../sdk", version = "0.12.0" }

View File

@ -1,20 +1,19 @@
#[cfg(feature = "bpf_c")]
use solana_sdk::bpf_loader;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
use std::env;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
use std::fs::File;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
use std::io::Read;
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
use std::path::PathBuf;
mod bpf {
use solana_runtime::bank::Bank;
use solana_runtime::loader_utils::load_program;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::native_loader;
use solana_sdk::transaction::Transaction;
use std::env;
use std::fs::File;
use std::path::PathBuf;
/// BPF program file extension
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
const PLATFORM_FILE_EXTENSION_BPF: &str = "so";
/// Create a BPF program file name
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
fn create_bpf_path(name: &str) -> PathBuf {
/// BPF program file extension
const PLATFORM_FILE_EXTENSION_BPF: &str = "so";
/// Create a BPF program file name
fn create_bpf_path(name: &str) -> PathBuf {
let mut pathbuf = {
let current_exe = env::current_exe().unwrap();
PathBuf::from(current_exe.parent().unwrap().parent().unwrap())
@ -23,11 +22,16 @@ fn create_bpf_path(name: &str) -> PathBuf {
pathbuf.push(name);
pathbuf.set_extension(PLATFORM_FILE_EXTENSION_BPF);
pathbuf
}
}
#[cfg(feature = "bpf_c")]
#[test]
fn test_program_bpf_c_noop() {
#[cfg(feature = "bpf_c")]
mod bpf_c {
use super::*;
use solana_sdk::bpf_loader;
use std::io::Read;
#[test]
fn test_program_bpf_c_noop() {
solana_logger::setup();
let mut file = File::open(create_bpf_path("noop")).expect("file open failed");
@ -49,11 +53,10 @@ fn test_program_bpf_c_noop() {
);
bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
}
}
#[cfg(feature = "bpf_c")]
#[test]
fn test_program_bpf_c() {
#[test]
fn test_program_bpf_c() {
solana_logger::setup();
let programs = [
@ -94,21 +97,27 @@ fn test_program_bpf_c() {
bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
}
}
}
}
// Cannot currently build the Rust BPF program as part
// of the rest of the build due to recursive `cargo build` causing
// a build deadlock. Therefore you must build the Rust programs
// yourself first by calling `make all` in the Rust BPF program's directory
#[cfg(feature = "bpf_rust")]
#[test]
fn test_program_bpf_rust() {
// Cannot currently build the Rust BPF program as part
// of the rest of the build due to recursive `cargo build` causing
// a build deadlock. Therefore you must build the Rust programs
// yourself first by calling `make all` in the Rust BPF program's directory
#[cfg(feature = "bpf_rust")]
mod bpf_rust {
use super::*;
use std::io::Read;
#[test]
fn test_program_bpf_rust() {
solana_logger::setup();
let programs = ["solana_bpf_rust_noop"];
for program in programs.iter() {
println!("Test program: {:?}", program);
let mut file = File::open(create_bpf_path(program)).expect("file open failed");
let filename = create_bpf_path(program);
println!("Test program: {:?} from {:?}", program, filename);
let mut file = File::open(filename).unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
@ -134,4 +143,6 @@ fn test_program_bpf_rust() {
bank.process_transaction(&tx).unwrap();
assert_eq!(bank.get_signature_status(&tx.signatures[0]), Some(Ok(())));
}
}
}
}