Allow BPF structure passing and returning (#2100)
* Add BPF struct passing and returning tests
This commit is contained in:
parent
166945a461
commit
e3dfd7b1ab
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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/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/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");
|
||||
let status = Command::new("make")
|
||||
.current_dir("../../bpf/c")
|
||||
|
|
|
@ -32,7 +32,7 @@ if [[ ! -r criterion-$machine-$version.md ]]; then
|
|||
fi
|
||||
|
||||
# Install LLVM
|
||||
version=v0.0.5
|
||||
version=v0.0.6
|
||||
if [[ ! -f llvm-native-$machine-$version.md ]]; then
|
||||
(
|
||||
filename=solana-llvm-$machine.tar.bz2
|
||||
|
|
|
@ -296,28 +296,37 @@ fn test_program_builtin_bpf_noop() {
|
|||
|
||||
#[cfg(feature = "bpf_c")]
|
||||
#[test]
|
||||
fn test_program_bpf_noop_c() {
|
||||
fn test_program_bpf_c() {
|
||||
logger::setup();
|
||||
|
||||
let mut file = File::open(create_bpf_path("noop")).expect("file open failed");
|
||||
let mut elf = Vec::new();
|
||||
file.read_to_end(&mut elf).unwrap();
|
||||
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();
|
||||
file.read_to_end(&mut elf).unwrap();
|
||||
|
||||
let loader = Loader::new_dynamic("solana_bpf_loader");
|
||||
let program = Program::new(&loader, &elf);
|
||||
let loader = Loader::new_dynamic("solana_bpf_loader");
|
||||
let program = Program::new(&loader, &elf);
|
||||
|
||||
// Call user program
|
||||
let tx = Transaction::new(
|
||||
&loader.mint.keypair(),
|
||||
&[],
|
||||
program.program.pubkey(),
|
||||
&vec![1u8],
|
||||
loader.mint.last_id(),
|
||||
0,
|
||||
);
|
||||
check_tx_results(
|
||||
&loader.bank,
|
||||
&tx,
|
||||
loader.bank.process_transactions(&vec![tx.clone()]),
|
||||
);
|
||||
// Call user program
|
||||
let tx = Transaction::new(
|
||||
&loader.mint.keypair(),
|
||||
&[],
|
||||
program.program.pubkey(),
|
||||
&vec![1u8],
|
||||
loader.mint.last_id(),
|
||||
0,
|
||||
);
|
||||
check_tx_results(
|
||||
&loader.bank,
|
||||
&tx,
|
||||
loader.bank.process_transactions(&vec![tx.clone()]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue