Open brenzi opened 4 years ago
generally speaking, cargo test
collects all #[test]
s and creates a binary with a fixed driver and libtest
. we don't have chance to change the compiler ad libtest
. so the only chance to use cargo test
is to test the untrusted app, not the enclave.
good news is that we can use inventory and a proc-macro to implement something very similar to #[test]
which collect every test fn pointer (decorated by the customized proc macro attribute) into a static array and then drive these test fn ptrs with our own prebuilt driver. in this way, though we cannot use #[test]
, we can construct an only with all test fn
s automatically, and export only 1 ECALL fn for triggering the tests.
though our initial PoC works, it has problem with ld from LLVM9, which optimizes out ctors. related issues: https://github.com/mmastrac/rust-ctor/issues/27 https://github.com/mmastrac/rust-ctor/issues/43
this approach is acceptable. important for us is that tests are collected automatically and results are summarized clearly
though our initial PoC works, it has problem with ld from LLVM9, which optimizes out ctors. related issues: mmastrac/rust-ctor#27 mmastrac/rust-ctor#43
Regarding the # [ctros] link issue, unused symbols are pruned, even if # [used] is used.
After testing, the following method can be used to temporarily solve this problem:
When linking test-enclave.a in your Makefile, use the whole-archice ld command line option
-Wl,-whole-archive -ltest-enclave -Wl,-no-whole-archive
@brenzi, please refer to this PR (https://github.com/apache/incubator-teaclave/pull/269) on how to use inventory to automatically collect test cases.
@mssun perhaps we could "downport" it to the sdk and make it available to developers like @brenzi
In addition to the automatic collection of test cases, we can also provide a cargo subcommand such as cargo teaclave
. When executing cargo teaclave test
, it can automatically provide an integration test driver.
The only thing bothers me about "downport" is that the update of SDK requires huge efforts. Test drivers, however, is not as stable as std. A better way is to implement this in the Teaclave platform first and stablize in the SDK when necessary.
In summary, @brenzi, you can simply implement your own test drivers first (similar with https://github.com/apache/incubator-teaclave/pull/269). Then, we can gradually improve the test toolchain in the SDK.
Is there any chance we can make
cargo test
work with our enclave code?it would be great if we could use standard
cargo test
. Right now we can only do handmade testing which is a lot less convenient to trackright now we get a clash between
std
andsgx_tstd
: