Add sanity test to verify floating point std math lib works for BPF (#21013)

On-chain programs frequently require floating point operations. In
addition standard library functions are expected to be available.
This change adds a simple sanity check that such functions are
available and work correctly when compiled to BPF.
This commit is contained in:
Dmitri Makarov 2021-11-02 17:09:58 -07:00 committed by GitHub
parent 1adf255e3a
commit 346cb9a275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -62,6 +62,15 @@ pub fn process_instruction(
panic!();
}
{
// Test - float math functions
let zero = accounts[0].try_borrow_mut_data()?.len() as f64;
let num = zero + 8.0f64;
let num = num.powf(0.333f64);
// check that the result is in a correct interval close to 1.998614185980905
assert!(1.9986f64 < num && num < 2.0f64);
}
sol_log_compute_units();
Ok(())
}

View File

@ -1400,7 +1400,7 @@ fn assert_instruction_count() {
("solana_bpf_rust_noop", 480),
("solana_bpf_rust_param_passing", 146),
("solana_bpf_rust_rand", 487),
("solana_bpf_rust_sanity", 1716),
("solana_bpf_rust_sanity", 8397),
("solana_bpf_rust_secp256k1_recover", 25216),
("solana_bpf_rust_sha", 30704),
]);