Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken benchmarks #205

Merged
merged 2 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "secp256k1"
path = "src/lib.rs"

[features]
unstable = []
unstable = ["recovery", "rand-std"]
default = ["std"]
std = ["secp256k1-sys/std"]
rand-std = ["rand/std"]
Expand Down
27 changes: 7 additions & 20 deletions no_std_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

//! # secp256k1 no-std test.
//! This binary is a short smallest rust code to produce a working binary *without libstd*.
//! This gives us 2 things:
//! This gives us 2 things:
//! 1. Test that the parts of the code that should work in a no-std enviroment actually work.
//! 2. Test that we don't accidentally import libstd into `secp256k1`.
//!
//!
//! The first is tested using the following command `cargo run --release | grep -q "Verified Successfully"`.
//! (Making sure that it successfully printed that. i.e. it didn't abort before that).
//!
//!
//! The second is tested by the fact that it compiles. if we accidentally link against libstd we should see the following error:
//! `error[E0152]: duplicate lang item found`.
//! Example:
Expand All @@ -33,11 +33,11 @@
//! |
//! = note: first defined in crate `panic_unwind` (which `std` depends on).
//! ```
//!
//! Notes:
//!
//! Notes:
//! * Requires `panic=abort` and `--release` to not depend on libunwind(which is provided usually by libstd) https://github.com/rust-lang/rust/issues/47493
//! * Requires linking with `libc` for calling `printf`.
//!
//!

#![feature(lang_items)]
#![feature(start)]
Expand All @@ -52,10 +52,10 @@ use core::fmt::{self, write, Write};
use core::intrinsics;
use core::panic::PanicInfo;

use secp256k1::ecdh::SharedSecret;
use secp256k1::rand::{self, RngCore};
use secp256k1::serde::Serialize;
use secp256k1::*;
use secp256k1::ecdh::SharedSecret;

use serde_cbor::de;
use serde_cbor::ser::SliceWrite;
Expand Down Expand Up @@ -111,24 +111,11 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
})}.unwrap();
assert_ne!(x_arr, [0u8; 32]);
assert_ne!(&y_arr[..], &[0u8; 32][..]);


unsafe { libc::printf("Verified Successfully!\n\0".as_ptr() as _) };
0
}

// These functions are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}

// This function may be needed based on the compilation target.
#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern "C" fn rust_eh_unwind_resume() {}

const MAX_PRINT: usize = 511;
struct Print {
loc: usize,
Expand Down
1 change: 0 additions & 1 deletion src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ mod benches {
let s = Secp256k1::signing_only();
let (sk, pk) = s.generate_keypair(&mut thread_rng());

let s = Secp256k1::new();
bh.iter( || {
let res = SharedSecret::new(&pk, &sk);
black_box(res);
Expand Down
4 changes: 4 additions & 0 deletions src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ mod tests {

#[cfg(all(test, feature = "unstable"))]
mod benches {
use rand::{thread_rng, RngCore};
use test::{Bencher, black_box};
use super::{Message, Secp256k1};

#[bench]
pub fn bench_recover(bh: &mut Bencher) {
let s = Secp256k1::new();
Expand Down