#intel-sgx #confidential-computing #sgx-sdk #unit #unit-testing #applications #tee

nightly sgx_tunittest

Rust SGX SDK provides the ability to write Intel SGX applications in Rust Programming Language

10 stable releases

1.1.1 Apr 2, 2020
1.1.0 Dec 19, 2019
1.0.9 Sep 16, 2019
1.0.8 Jun 11, 2019
0.9.8 Mar 27, 2018

#1949 in Hardware support

Custom license

325KB
5K SLoC

Note

Please visit our homepage for usage. Thanks!


lib.rs:

sgx_tunittest is for performing unit tests in enclaves.

To use this crate, import the assertion macros defined in sgx_tstd and this crate like this at first:

#[macro_use]
extern crate sgx_tstd as std;
#[macro_use]
extern crate sgx_tunittest;

Similar to #[test] in Rust, unit test functions are required to take zero arguments and return nothing. One test is success only when the test function returns without panic.

Different from Rust, we don't use features like #[test], #[should_panic] for unit test function declaration. Instead, to declare a unit test function, one just need implement it as normal.

Here is a sample unit test function:

fn foo() {
    assert!(true);
    assert_eq!(1,1);
    assert_ne!(1,0);
}

To launch the unit test, one should use the macro rsgx_unit_test!. For example, assuming that we have three unit test functions: foo, bar and zoo. To start the test, just write as the following:

rsgx_unit_tests!(foo, bar, zoo);

sgx_tunittest supports fail test (something must panic). But it does not provide it in Rust style (#[should_panic]). One should use macro should_panic! to assert the statement that would panic. For example:

fn foo_panic() {
    let v = vec![]
    should_panic!(vec[0]); // vec[0] would panic
}

In this way, vec[0] would panic. But should_panic! catches it. Thus foo_panic would pass the unit test.

Dependencies

~0–290KB