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

cargo test #137

Closed
puzzlewolf opened this issue Jun 28, 2019 · 2 comments
Closed

cargo test #137

puzzlewolf opened this issue Jun 28, 2019 · 2 comments

Comments

@puzzlewolf
Copy link

Is it possible to use cargo test for the in-enclave code? E.g. in the hello-rust sample:

root@a6161d44ab7e:~/sgx/samplecode/hello-rust/enclave# cargo test --verbose
       Fresh sgx_types v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_build_helper v0.1.0 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_libc v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_trts v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_tprotected_fs v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_alloc v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_unwind v0.0.1 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
       Fresh sgx_tstd v1.0.8 (https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.8#21f9e7fc)
   Compiling Helloworldsampleenclave v1.0.0 (/root/sgx/samplecode/hello-rust/enclave)
     Running `rustc --crate-name helloworldsampleenclave src/lib.rs --color always --emit=dep-info,link -C debuginfo=2 --test --cfg 'feature="default"' -C metadata=6acf3f9c7ef64e5a -C extra-filename=-6acf3f9c7ef64e5a --out-dir /root/sgx/samplecode/hello-rust/enclave/target/debug/deps -C incremental=/root/sgx/samplecode/hello-rust/enclave/target/debug/incremental -L dependency=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps --extern sgx_tstd=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps/libsgx_tstd-d2deaab23709d4cd.rlib --extern sgx_types=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps/libsgx_types-97977d94443ce236.rlib`
error: duplicate lang item in crate `std`: `f32_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `f64_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `panic_impl`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `oom`.
  |
  = note: first defined in crate `sgx_trts`.

error: aborting due to 4 previous errors

error: Could not compile `Helloworldsampleenclave`.

Caused by:
  process didn't exit successfully: `rustc --crate-name helloworldsampleenclave src/lib.rs --color always --emit=dep-info,link -C debuginfo=2 --test --cfg 'feature="default"' -C metadata=6acf3f9c7ef64e5a -C extra-filename=-6acf3f9c7ef64e5a --out-dir /root/sgx/samplecode/hello-rust/enclave/target/debug/deps -C incremental=/root/sgx/samplecode/hello-rust/enclave/target/debug/incremental -L dependency=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps --extern sgx_tstd=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps/libsgx_tstd-d2deaab23709d4cd.rlib --extern sgx_types=/root/sgx/samplecode/hello-rust/enclave/target/debug/deps/libsgx_types-97977d94443ce236.rlib` (exit code: 1)

cargo build is fine.

The errors look like in #60, but that one is not related to cargo test. Is the solution applicable here, and if yes, how?

@dingelish
Copy link
Contributor

Hey there,

cargo test would generate a single binary for each #[test] function, along with a fixed main function and environment setup. If we can apply this model to Intel SGX, we need to change the Rust compiler's code base and let it construct an enclave using given sigining keys and Intel SGX toolchains. Obviously, it is impossible.

To solve this, we provide a very useful crate named sgx_tunittest. If you can mark a function with #[test], you can always put it to rsgx_unit_tests! and test it and get the number of total failed testcases from its return value. It outputs colorful information to stdout and almost the same to cargo test. You can refer to the ported tests of serde-sgx to see how to port #[test], #[test] #[should_panic]
to SGX, and enjoy testing a single closure || assert!(true) without defining a function.

I think you'd like it!

Best,
Yu

@puzzlewolf
Copy link
Author

Thank you, it works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants