Crate sgx_tunittest[][src]

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:

extern crate sgx_tstd as std;
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() {

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.



This macro works as test case driver.


This macro implements the fail test.



Perform one test case at a time.


An epilogue function for Rust SGX unit testing.


A prologue function for Rust SGX unit testing.