Allow BPF structure passing and returning (#2100)

* Add BPF struct passing and returning tests
This commit is contained in:
jackcmay
2018-12-11 09:03:37 -08:00
committed by GitHub
parent 166945a461
commit e3dfd7b1ab
5 changed files with 68 additions and 21 deletions

View File

@ -0,0 +1,17 @@
#include <solana_sdk.h>
struct foo {const uint8_t *input;};
void foo(const uint8_t *input, struct foo foo) ;
extern bool entrypoint(const uint8_t *input) {
struct foo f;
f.input = input;
foo(input, f);
return true;
}
void foo(const uint8_t *input, struct foo foo) {
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
sol_assert(input == foo.input);
}

View File

@ -0,0 +1,18 @@
#include <solana_sdk.h>
struct foo {const uint8_t *input;};
struct foo bar(const uint8_t *input);
extern bool entrypoint(const uint8_t *input) {
struct foo foo = bar(input);
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
sol_assert(input == foo.input);
return true;
}
struct foo bar(const uint8_t *input) {
struct foo foo;
foo.input = input;
return foo;
}

View File

@ -18,6 +18,9 @@ fn main() {
println!("cargo:rerun-if-changed=../../bpf/c/src/bench_alu.c"); println!("cargo:rerun-if-changed=../../bpf/c/src/bench_alu.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/move_funds.c"); println!("cargo:rerun-if-changed=../../bpf/c/src/move_funds.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/noop.c"); println!("cargo:rerun-if-changed=../../bpf/c/src/noop.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/noop++.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/struct_pass.c");
println!("cargo:rerun-if-changed=../../bpf/c/src/struct_ret.c");
println!("cargo:warning=(not a warning) Compiling C-based BPF programs"); println!("cargo:warning=(not a warning) Compiling C-based BPF programs");
let status = Command::new("make") let status = Command::new("make")
.current_dir("../../bpf/c") .current_dir("../../bpf/c")

View File

@ -32,7 +32,7 @@ if [[ ! -r criterion-$machine-$version.md ]]; then
fi fi
# Install LLVM # Install LLVM
version=v0.0.5 version=v0.0.6
if [[ ! -f llvm-native-$machine-$version.md ]]; then if [[ ! -f llvm-native-$machine-$version.md ]]; then
( (
filename=solana-llvm-$machine.tar.bz2 filename=solana-llvm-$machine.tar.bz2

View File

@ -296,10 +296,18 @@ fn test_program_builtin_bpf_noop() {
#[cfg(feature = "bpf_c")] #[cfg(feature = "bpf_c")]
#[test] #[test]
fn test_program_bpf_noop_c() { fn test_program_bpf_c() {
logger::setup(); logger::setup();
let mut file = File::open(create_bpf_path("noop")).expect("file open failed"); let programs = [
"noop",
"struct_pass",
"struct_ret",
//"noop++" // TODO fails with buffer overflow
];
for program in programs.iter() {
println!("Test program: {:?}", program);
let mut file = File::open(create_bpf_path(program)).expect("file open failed");
let mut elf = Vec::new(); let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap(); file.read_to_end(&mut elf).unwrap();
@ -321,3 +329,4 @@ fn test_program_bpf_noop_c() {
loader.bank.process_transactions(&vec![tx.clone()]), loader.bank.process_transactions(&vec![tx.clone()]),
); );
} }
}