teaclave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ms...@apache.org
Subject [incubator-teaclave] branch develop updated: [tests] Start to use teaclave_test_utils
Date Wed, 29 Jan 2020 21:56:04 GMT
This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2857944  [tests] Start to use teaclave_test_utils
2857944 is described below

commit 28579449204c94ca30cdb442fe041546dc216644
Author: Mingshen Sun <bob@mssun.me>
AuthorDate: Wed Jan 29 13:43:00 2020 -0800

    [tests] Start to use teaclave_test_utils
---
 services/authentication/enclave/Cargo.toml         |  4 +-
 services/authentication/enclave/src/lib.rs         |  6 +-
 services/database/enclave/Cargo.toml               |  4 +-
 services/database/enclave/src/lib.rs               |  6 +-
 services/execution/enclave/Cargo.toml              |  6 +-
 services/execution/enclave/src/lib.rs              |  7 +-
 services/frontend/enclave/Cargo.toml               |  4 +-
 services/frontend/enclave/src/lib.rs               |  3 +-
 tests/functional_tests/enclave/Cargo.toml          |  3 +-
 tests/functional_tests/enclave/src/lib.rs          |  8 +-
 .../enclave/src/teaclave_authentication_service.rs |  9 ++-
 .../enclave/src/teaclave_database_service.rs       |  9 ++-
 .../enclave/src/teaclave_execution_service.rs      |  6 +-
 tests/integration_tests/app/src/main.rs            |  3 +-
 .../app/src/teaclave_config_tests.rs               |  8 +-
 tests/integration_tests/enclave/Cargo.toml         |  3 +-
 tests/integration_tests/enclave/src/lib.rs         | 10 ++-
 .../enclave/src/protected_fs_rs.rs                 |  6 +-
 .../enclave/src/rusty_leveldb_sgx.rs               |  6 +-
 .../integration_tests/enclave/src/teaclave_rpc.rs  |  6 +-
 .../enclave/src/teaclave_worker.rs                 |  7 +-
 tests/test_utils/src/lib.rs                        |  6 +-
 tests/unit_tests/enclave/src/lib.rs                | 12 +--
 types/Cargo.toml                                   |  4 +-
 types/src/crypto.rs                                |  7 +-
 types/src/lib.rs                                   |  7 +-
 types/src/unittest.rs                              | 86 ----------------------
 types/src/worker.rs                                |  4 +-
 worker/Cargo.toml                                  |  4 +-
 worker/src/function/mod.rs                         |  6 +-
 worker/src/lib.rs                                  |  6 +-
 worker/src/runtime/mod.rs                          |  6 +-
 32 files changed, 95 insertions(+), 177 deletions(-)

diff --git a/services/authentication/enclave/Cargo.toml b/services/authentication/enclave/Cargo.toml
index 93ce9e3..6e5d8fa 100644
--- a/services/authentication/enclave/Cargo.toml
+++ b/services/authentication/enclave/Cargo.toml
@@ -24,7 +24,7 @@ mesalock_sgx = [
   "rusty-leveldb/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
-enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
+enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 anyhow    = { version = "1.0.26" }
@@ -46,7 +46,7 @@ teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
+teaclave_test_utils            = { path = "../../../tests/test_utils", optional = true }
 
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0", optional = true }
 sgx_types     = { version = "1.1.0" }
diff --git a/services/authentication/enclave/src/lib.rs b/services/authentication/enclave/src/lib.rs
index 1fb5a45..a57bc9b 100644
--- a/services/authentication/enclave/src/lib.rs
+++ b/services/authentication/enclave/src/lib.rs
@@ -119,10 +119,10 @@ register_ecall_handler!(
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
+    use teaclave_test_utils::*;
 
-    pub fn run_tests() -> usize {
-        rsgx_unit_tests!(
+    pub fn run_tests() -> bool {
+        run_tests!(
             service::tests::test_user_login,
             service::tests::test_user_authenticate,
             service::tests::test_user_register,
diff --git a/services/database/enclave/Cargo.toml b/services/database/enclave/Cargo.toml
index 9a67cce..b58158c 100644
--- a/services/database/enclave/Cargo.toml
+++ b/services/database/enclave/Cargo.toml
@@ -24,7 +24,7 @@ mesalock_sgx = [
   "rusty-leveldb/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
-enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
+enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 anyhow    = { version = "1.0.26" }
@@ -41,8 +41,8 @@ teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
+teaclave_test_utils            = { path = "../../../tests/test_utils", optional = true }
 
 
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0", optional = true }
 sgx_types     = { version = "1.1.0" }
diff --git a/services/database/enclave/src/lib.rs b/services/database/enclave/src/lib.rs
index 060e967..10af7cd 100644
--- a/services/database/enclave/src/lib.rs
+++ b/services/database/enclave/src/lib.rs
@@ -112,10 +112,10 @@ register_ecall_handler!(
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
+    use teaclave_test_utils::*;
 
-    pub fn run_tests() -> usize {
-        rsgx_unit_tests!(
+    pub fn run_tests() -> bool {
+        run_tests!(
             service::tests::test_get_key,
             service::tests::test_put_key,
             service::tests::test_delete_key,
diff --git a/services/execution/enclave/Cargo.toml b/services/execution/enclave/Cargo.toml
index cb0f68e..58d8e3a 100644
--- a/services/execution/enclave/Cargo.toml
+++ b/services/execution/enclave/Cargo.toml
@@ -24,7 +24,7 @@ mesalock_sgx = [
   "teaclave_worker/mesalock_sgx",
 ]
 cov = ["sgx_cov"]
-enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
+enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 log           = { version = "0.4.6" }
@@ -42,9 +42,9 @@ teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
-teaclave_worker                 = { path = "../../../worker" }
+teaclave_worker                = { path = "../../../worker" }
+teaclave_test_utils            = { path = "../../../tests/test_utils", optional = true }
 
 sgx_cov       = { version = "1.1.0", optional = true }
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0", optional = true }
 sgx_types     = { version = "1.1.0" }
diff --git a/services/execution/enclave/src/lib.rs b/services/execution/enclave/src/lib.rs
index c84abea..c33da8c 100644
--- a/services/execution/enclave/src/lib.rs
+++ b/services/execution/enclave/src/lib.rs
@@ -92,11 +92,8 @@ fn handle_finalize_enclave(_args: &FinalizeEnclaveInput) -> Result<FinalizeEncla
 
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
-    //use super::*;
-    //use sgx_tunittest::*;
 
-    pub fn run_tests() -> usize {
-        //rsgx_unit_tests!()
-        0
+    pub fn run_tests() -> bool {
+        true
     }
 }
diff --git a/services/frontend/enclave/Cargo.toml b/services/frontend/enclave/Cargo.toml
index e7aa5a7..67c4b42 100644
--- a/services/frontend/enclave/Cargo.toml
+++ b/services/frontend/enclave/Cargo.toml
@@ -23,7 +23,7 @@ mesalock_sgx = [
   "teaclave_config/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
-enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
+enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 anyhow    = { version = "1.0.26" }
@@ -42,7 +42,7 @@ teaclave_ipc                   = { path = "../../../ipc" }
 teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
+teaclave_test_utils            = { path = "../../../tests/test_utils" }
 
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0", optional = true }
 sgx_types     = { version = "1.1.0" }
diff --git a/services/frontend/enclave/src/lib.rs b/services/frontend/enclave/src/lib.rs
index b48eb1a..a7eab4c 100644
--- a/services/frontend/enclave/src/lib.rs
+++ b/services/frontend/enclave/src/lib.rs
@@ -90,7 +90,6 @@ register_ecall_handler!(
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
 
-    pub fn run_tests() -> usize {}
+    pub fn run_tests() -> bool {}
 }
diff --git a/tests/functional_tests/enclave/Cargo.toml b/tests/functional_tests/enclave/Cargo.toml
index 695db8d..1382713 100644
--- a/tests/functional_tests/enclave/Cargo.toml
+++ b/tests/functional_tests/enclave/Cargo.toml
@@ -21,6 +21,7 @@ mesalock_sgx = [
   "teaclave_config/mesalock_sgx",
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
+  "teaclave_test_utils/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
 
@@ -38,7 +39,7 @@ teaclave_rpc                   = { path = "../../../rpc" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 teaclave_proto                 = { path = "../../../services/proto" }
+teaclave_test_utils            = { path = "../../../tests/test_utils" }
 
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0" }
 sgx_types     = { version = "1.1.0" }
diff --git a/tests/functional_tests/enclave/src/lib.rs b/tests/functional_tests/enclave/src/lib.rs
index f236ece..8dfead3 100644
--- a/tests/functional_tests/enclave/src/lib.rs
+++ b/tests/functional_tests/enclave/src/lib.rs
@@ -41,9 +41,11 @@ mod teaclave_execution_service;
 
 #[handle_ecall]
 fn handle_run_test(_args: &RunTestInput) -> Result<RunTestOutput> {
-    teaclave_authentication_service::run_tests();
-    teaclave_database_service::run_tests();
-    teaclave_execution_service::run_tests();
+    let ret = teaclave_authentication_service::run_tests()
+        & teaclave_database_service::run_tests()
+        & teaclave_execution_service::run_tests();
+
+    assert_eq!(ret, true);
     Ok(RunTestOutput::default())
 }
 
diff --git a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
index b9aece9..61887b8 100644
--- a/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_authentication_service.rs
@@ -1,4 +1,3 @@
-use sgx_tunittest::*;
 use std::prelude::v1::*;
 use teaclave_attestation::verifier;
 use teaclave_config::RuntimeConfig;
@@ -9,15 +8,17 @@ use teaclave_rpc::config::SgxTrustedTlsClientConfig;
 use teaclave_rpc::endpoint::Endpoint;
 use teaclave_types::EnclaveInfo;
 
-pub fn run_tests() {
-    rsgx_unit_tests!(
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
+
+    run_tests!(
         test_login_success,
         test_login_fail,
         test_authenticate_success,
         test_authenticate_fail,
         test_register_success,
         test_register_fail,
-    );
+    )
 }
 
 fn test_login_success() {
diff --git a/tests/functional_tests/enclave/src/teaclave_database_service.rs b/tests/functional_tests/enclave/src/teaclave_database_service.rs
index f490f7d..0202090 100644
--- a/tests/functional_tests/enclave/src/teaclave_database_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_database_service.rs
@@ -1,10 +1,11 @@
-use sgx_tunittest::*;
 use std::prelude::v1::*;
 use teaclave_proto::teaclave_database_service::*;
 use teaclave_rpc::endpoint::Endpoint;
 
-pub fn run_tests() {
-    rsgx_unit_tests!(
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
+
+    run_tests!(
         test_get_success,
         test_get_fail,
         test_put_success,
@@ -12,7 +13,7 @@ pub fn run_tests() {
         test_enqueue_success,
         test_dequeue_success,
         test_dequeue_fail,
-    );
+    )
 }
 
 fn test_get_success() {
diff --git a/tests/functional_tests/enclave/src/teaclave_execution_service.rs b/tests/functional_tests/enclave/src/teaclave_execution_service.rs
index ddcdf8d..b7cf105 100644
--- a/tests/functional_tests/enclave/src/teaclave_execution_service.rs
+++ b/tests/functional_tests/enclave/src/teaclave_execution_service.rs
@@ -1,6 +1,5 @@
 use anyhow;
 use serde_json;
-use sgx_tunittest::*;
 use std::io::Write;
 use std::prelude::v1::*;
 use std::untrusted::fs;
@@ -9,8 +8,9 @@ use teaclave_proto::teaclave_execution_service::*;
 use teaclave_rpc::endpoint::Endpoint;
 use teaclave_types::AesGcm128CryptoInfo;
 
-pub fn run_tests() {
-    rsgx_unit_tests!(test_invoke_success,);
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
+    run_tests!(test_invoke_success,)
 }
 
 fn setup_client() -> TeaclaveExecutionClient {
diff --git a/tests/integration_tests/app/src/main.rs b/tests/integration_tests/app/src/main.rs
index f1369d8..ed3e53a 100644
--- a/tests/integration_tests/app/src/main.rs
+++ b/tests/integration_tests/app/src/main.rs
@@ -39,5 +39,6 @@ fn start_enclave_integration_tests(tee: &TeeBinder) -> anyhow::Result<()>
{
 }
 
 fn run_app_integration_tests() {
-    teaclave_config_tests::run_tests();
+    let ret = teaclave_config_tests::run_tests();
+    assert_eq!(ret, true);
 }
diff --git a/tests/integration_tests/app/src/teaclave_config_tests.rs b/tests/integration_tests/app/src/teaclave_config_tests.rs
index 39e0155..eb95c63 100644
--- a/tests/integration_tests/app/src/teaclave_config_tests.rs
+++ b/tests/integration_tests/app/src/teaclave_config_tests.rs
@@ -1,11 +1,11 @@
 use std::env;
 use teaclave_config;
 
-pub fn run_tests() {
-    teaclave_test_utils::tests!(runtime_config, runtime_config_with_env_vars);
+pub fn run_tests() -> bool {
+    teaclave_test_utils::run_tests!(test_runtime_config, test_runtime_config_with_env_vars)
 }
 
-fn runtime_config() {
+fn test_runtime_config() {
     env::remove_var("IAS_KEY");
     env::remove_var("IAS_SPID");
     let config =
@@ -34,7 +34,7 @@ fn runtime_config() {
     )
 }
 
-fn runtime_config_with_env_vars() {
+fn test_runtime_config_with_env_vars() {
     env::set_var("IAS_KEY", "12345678901234567890123456789012");
     env::set_var("IAS_SPID", "90123456789012345678901234567890");
     let config =
diff --git a/tests/integration_tests/enclave/Cargo.toml b/tests/integration_tests/enclave/Cargo.toml
index c4424d0..802b571 100644
--- a/tests/integration_tests/enclave/Cargo.toml
+++ b/tests/integration_tests/enclave/Cargo.toml
@@ -24,6 +24,7 @@ mesalock_sgx = [
   "rusty-leveldb/mesalock_sgx",
   "protected_fs_rs/mesalock_sgx",
   "teaclave_worker/mesalock_sgx",
+  "teaclave_test_utils/mesalock_sgx",
 ]
 cov = ["teaclave_service_enclave_utils/cov"]
 
@@ -47,7 +48,7 @@ teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils"
 teaclave_types                 = { path = "../../../types" }
 teaclave_proto                 = { path = "../../../services/proto" }
 teaclave_worker                = { path = "../../../worker" }
+teaclave_test_utils            = { path = "../../../tests/test_utils" }
 
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0" }
 sgx_types     = { version = "1.1.0" }
diff --git a/tests/integration_tests/enclave/src/lib.rs b/tests/integration_tests/enclave/src/lib.rs
index 04f0c31..ca4e12b 100644
--- a/tests/integration_tests/enclave/src/lib.rs
+++ b/tests/integration_tests/enclave/src/lib.rs
@@ -42,10 +42,12 @@ mod teaclave_worker;
 
 #[handle_ecall]
 fn handle_run_test(_args: &RunTestInput) -> Result<RunTestOutput> {
-    rusty_leveldb_sgx::run_tests();
-    protected_fs_rs::run_tests();
-    teaclave_rpc::run_tests();
-    teaclave_worker::run_tests();
+    let ret = rusty_leveldb_sgx::run_tests()
+        & protected_fs_rs::run_tests()
+        & teaclave_rpc::run_tests()
+        & teaclave_worker::run_tests();
+
+    assert_eq!(ret, true);
 
     Ok(RunTestOutput::default())
 }
diff --git a/tests/integration_tests/enclave/src/protected_fs_rs.rs b/tests/integration_tests/enclave/src/protected_fs_rs.rs
index 228f263..05eab3f 100644
--- a/tests/integration_tests/enclave/src/protected_fs_rs.rs
+++ b/tests/integration_tests/enclave/src/protected_fs_rs.rs
@@ -61,8 +61,8 @@ pub fn read_write_large_file() {
     assert_eq!(remove_protected_file(fname).is_ok(), true);
 }
 
-pub fn run_tests() {
-    use sgx_tunittest::*;
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
 
-    rsgx_unit_tests!(read_write_large_file);
+    run_tests!(read_write_large_file)
 }
diff --git a/tests/integration_tests/enclave/src/rusty_leveldb_sgx.rs b/tests/integration_tests/enclave/src/rusty_leveldb_sgx.rs
index 7b698a6..b215490 100644
--- a/tests/integration_tests/enclave/src/rusty_leveldb_sgx.rs
+++ b/tests/integration_tests/enclave/src/rusty_leveldb_sgx.rs
@@ -62,8 +62,8 @@ fn test_write_a_lot() {
     fs::remove_dir_all("/tmp/leveldb_testdb").expect("Cannot remove directory");
 }
 
-pub fn run_tests() {
-    use sgx_tunittest::*;
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
 
-    rsgx_unit_tests!(test_write_a_lot);
+    run_tests!(test_write_a_lot)
 }
diff --git a/tests/integration_tests/enclave/src/teaclave_rpc.rs b/tests/integration_tests/enclave/src/teaclave_rpc.rs
index ee99a95..f87c25a 100644
--- a/tests/integration_tests/enclave/src/teaclave_rpc.rs
+++ b/tests/integration_tests/enclave/src/teaclave_rpc.rs
@@ -1,7 +1,6 @@
 use anyhow::Result;
 use rustls::internal::pemfile;
 use serde::{Deserialize, Serialize};
-use sgx_tunittest::*;
 use std::io;
 use std::net::TcpListener;
 use std::prelude::v1::*;
@@ -78,8 +77,9 @@ impl EchoClient {
     }
 }
 
-pub fn run_tests() {
-    rsgx_unit_tests!(echo_success);
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
+    run_tests!(echo_success)
 }
 
 fn echo_success() {
diff --git a/tests/integration_tests/enclave/src/teaclave_worker.rs b/tests/integration_tests/enclave/src/teaclave_worker.rs
index 58fa711..bb31ca1 100644
--- a/tests/integration_tests/enclave/src/teaclave_worker.rs
+++ b/tests/integration_tests/enclave/src/teaclave_worker.rs
@@ -1,4 +1,3 @@
-use sgx_tunittest::*;
 use std::io::Write;
 use std::prelude::v1::*;
 use std::untrusted::fs;
@@ -81,6 +80,8 @@ fn test_start_worker() {
     assert_eq!(&result[..], &expected[..]);
 }
 
-pub fn run_tests() {
-    rsgx_unit_tests!(test_start_worker);
+pub fn run_tests() -> bool {
+    use teaclave_test_utils::*;
+
+    run_tests!(test_start_worker)
 }
diff --git a/tests/test_utils/src/lib.rs b/tests/test_utils/src/lib.rs
index 736c570..e56a784 100644
--- a/tests/test_utils/src/lib.rs
+++ b/tests/test_utils/src/lib.rs
@@ -23,7 +23,7 @@ macro_rules! should_panic {
 }
 
 #[macro_export]
-macro_rules! tests {
+macro_rules! run_tests {
     (
         $($f : expr),* $(,)?
     ) => {
@@ -41,7 +41,7 @@ pub fn test_start() {
     println!("\nstart running tests");
 }
 
-pub fn test_end(ntestcases: u64, failurecases: Vec<String>) -> usize {
+pub fn test_end(ntestcases: u64, failurecases: Vec<String>) -> bool {
     let ntotal = ntestcases as usize;
     let nsucc = ntestcases as usize - failurecases.len();
 
@@ -67,7 +67,7 @@ pub fn test_end(ntestcases: u64, failurecases: Vec<String>) ->
usize {
         nsucc,
         ntotal - nsucc
     );
-    failurecases.len()
+    failurecases.is_empty()
 }
 
 #[allow(clippy::print_literal)]
diff --git a/tests/unit_tests/enclave/src/lib.rs b/tests/unit_tests/enclave/src/lib.rs
index 7082239..8da42f3 100644
--- a/tests/unit_tests/enclave/src/lib.rs
+++ b/tests/unit_tests/enclave/src/lib.rs
@@ -40,11 +40,13 @@ use teaclave_worker;
 
 #[handle_ecall]
 fn handle_run_test(_args: &RunTestInput) -> Result<RunTestOutput> {
-    teaclave_database_service_enclave::tests::run_tests();
-    teaclave_execution_service_enclave::tests::run_tests();
-    teaclave_authentication_service_enclave::tests::run_tests();
-    teaclave_worker::tests::run_tests();
-    teaclave_types::tests::run_tests();
+    let ret = teaclave_database_service_enclave::tests::run_tests()
+        & teaclave_execution_service_enclave::tests::run_tests()
+        & teaclave_authentication_service_enclave::tests::run_tests()
+        & teaclave_worker::tests::run_tests()
+        & teaclave_types::tests::run_tests();
+
+    assert_eq!(ret, true);
 
     Ok(RunTestOutput::default())
 }
diff --git a/types/Cargo.toml b/types/Cargo.toml
index a3aeb5e..b9b60ec 100644
--- a/types/Cargo.toml
+++ b/types/Cargo.toml
@@ -14,7 +14,7 @@ mesalock_sgx = [
     "sgx_tstd",
     "protected_fs_rs/mesalock_sgx",
 ]
-enclave_unit_test = []
+enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 protected_fs_rs  = { path = "../common/protected_fs_rs", default-features = false}
@@ -27,4 +27,6 @@ toml         = { version = "0.5.3" }
 ring         = { version = "0.16.5" }
 thiserror    = { version = "1.0.9" }
 
+teaclave_test_utils = { path = "../tests/test_utils", optional = true }
+
 sgx_tstd = { version = "1.1.0", features = ["net", "backtrace"], optional = true }
\ No newline at end of file
diff --git a/types/src/crypto.rs b/types/src/crypto.rs
index 04bc7d3..41d0b80 100644
--- a/types/src/crypto.rs
+++ b/types/src/crypto.rs
@@ -160,11 +160,10 @@ pub fn aead_encrypt(
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use crate::unit_tests;
-    use crate::unittest::*;
+    use teaclave_test_utils::*;
 
-    pub fn run_tests() -> usize {
-        unit_tests!(test_aead_enc_then_dec, test_crypto_info,)
+    pub fn run_tests() -> bool {
+        run_tests!(test_aead_enc_then_dec, test_crypto_info,)
     }
 
     fn test_aead_enc_then_dec() {
diff --git a/types/src/lib.rs b/types/src/lib.rs
index 6d88c23..3abd5e6 100644
--- a/types/src/lib.rs
+++ b/types/src/lib.rs
@@ -19,8 +19,6 @@ mod crypto;
 pub use crypto::*;
 mod worker;
 pub use worker::*;
-mod unittest;
-pub use unittest::*;
 
 /// Status for Ecall
 #[repr(C)]
@@ -178,8 +176,7 @@ pub type TeaclaveServiceResponseResult<T> = std::result::Result<T,
TeaclaveServi
 pub mod tests {
     use super::*;
 
-    pub fn run_tests() {
-        worker::tests::run_tests();
-        crypto::tests::run_tests();
+    pub fn run_tests() -> bool {
+        worker::tests::run_tests() & crypto::tests::run_tests()
     }
 }
diff --git a/types/src/unittest.rs b/types/src/unittest.rs
deleted file mode 100644
index 47c438c..0000000
--- a/types/src/unittest.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#[cfg(feature = "mesalock_sgx")]
-use std::prelude::v1::*;
-
-use std::string::String;
-use std::vec::Vec;
-
-#[macro_export]
-macro_rules! unit_tests {
-    (
-        $($f : expr),* $(,)?
-    ) => {
-        {
-            unit_test_start();
-            let mut ntestcases : u64 = 0u64;
-            let mut failurecases : Vec<String> = Vec::new();
-            $(unit_test(&mut ntestcases, &mut failurecases, $f,stringify!($f));)*
-            unit_test_end(ntestcases, failurecases)
-        }
-    }
-}
-
-pub fn unit_test_start() {
-    println!("\nstart running tests");
-}
-
-pub fn unit_test_end(ntestcases: u64, failurecases: Vec<String>) -> usize {
-    let ntotal = ntestcases as usize;
-    let nsucc = ntestcases as usize - failurecases.len();
-
-    if !failurecases.is_empty() {
-        print!("\nfailures: ");
-        println!(
-            "    {}",
-            failurecases
-                .iter()
-                .fold(String::new(), |s, per| s + "\n    " + per)
-        );
-    }
-
-    if ntotal == nsucc {
-        print!("\ntest result \x1B[1;32mok\x1B[0m. ");
-    } else {
-        print!("\ntest result \x1B[1;31mFAILED\x1B[0m. ");
-    }
-
-    println!(
-        "{} tested, {} passed, {} failed",
-        ntotal,
-        nsucc,
-        ntotal - nsucc
-    );
-    failurecases.len()
-}
-
-pub fn unit_test<F, R>(ncases: &mut u64, failurecases: &mut Vec<String>,
f: F, name: &str)
-where
-    F: FnOnce() -> R + std::panic::UnwindSafe,
-{
-    *ncases += 1;
-    let ret = std::panic::catch_unwind(|| {
-        f();
-    });
-    if ret.is_ok() {
-        println!("testing {} ... \x1B[1;32mok\x1B[0m!", name);
-    } else {
-        println!("testing {} ... \x1B[1;31mfailed\x1B[0m!", name);
-        failurecases.push(String::from(name));
-    }
-}
diff --git a/types/src/worker.rs b/types/src/worker.rs
index 29a4248..de906c9 100644
--- a/types/src/worker.rs
+++ b/types/src/worker.rs
@@ -178,8 +178,8 @@ pub mod tests {
     //use crate::unit_tests;
     //use crate::unittest::*;
 
-    pub fn run_tests() -> usize {
+    pub fn run_tests() -> bool {
         //unit_tests!()
-        0
+        true
     }
 }
diff --git a/worker/Cargo.toml b/worker/Cargo.toml
index 0f2b73d..b8f8f92 100644
--- a/worker/Cargo.toml
+++ b/worker/Cargo.toml
@@ -17,7 +17,7 @@ mesalock_sgx = [
   "teaclave_types/mesalock_sgx",
 ]
 cov = ["sgx_cov"]
-enclave_unit_test = ["sgx_tunittest"]
+enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
 
 [dependencies]
 log           = { version = "0.4.6" }
@@ -27,8 +27,8 @@ serde         = { version = "1.0.92", features = ["derive"] }
 thiserror     = { version = "1.0.9" }
 gbdt          = { version = "0.1.0", features = ["input", "enable_training"] }
 teaclave_types = { path = "../types" }
+teaclave_test_utils = { path = "../tests/test_utils", optional = true }
 
 sgx_cov       = { version = "1.1.0", optional = true }
 sgx_tstd      = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional
= true }
-sgx_tunittest = { version = "1.1.0", optional = true }
 sgx_types     = { version = "1.1.0" }
diff --git a/worker/src/function/mod.rs b/worker/src/function/mod.rs
index 9255624..6465ed0 100644
--- a/worker/src/function/mod.rs
+++ b/worker/src/function/mod.rs
@@ -42,10 +42,10 @@ pub use mesapy::Mesapy;
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
+    use teaclave_test_utils::*;
 
-    pub fn run_tests() -> usize {
-        rsgx_unit_tests!(
+    pub fn run_tests() -> bool {
+        run_tests!(
             gbdt_training::tests::test_gbdt_parse_training_data,
             gbdt_training::tests::test_gbdt_training,
         )
diff --git a/worker/src/lib.rs b/worker/src/lib.rs
index a5be765..6183383 100644
--- a/worker/src/lib.rs
+++ b/worker/src/lib.rs
@@ -22,7 +22,6 @@ extern crate sgx_tstd as std;
 #[cfg(feature = "mesalock_sgx")]
 use std::prelude::v1::*;
 
-//#[macro_use]
 extern crate log;
 
 mod function;
@@ -35,8 +34,7 @@ pub use worker::Worker;
 pub mod tests {
     use super::*;
 
-    pub fn run_tests() {
-        function::tests::run_tests();
-        runtime::tests::run_tests();
+    pub fn run_tests() -> bool {
+        function::tests::run_tests() & runtime::tests::run_tests()
     }
 }
diff --git a/worker/src/runtime/mod.rs b/worker/src/runtime/mod.rs
index f702054..5fb32c4 100644
--- a/worker/src/runtime/mod.rs
+++ b/worker/src/runtime/mod.rs
@@ -37,10 +37,10 @@ pub use raw_io::RawIoRuntime;
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
+    use teaclave_test_utils::*;
 
-    pub fn run_tests() -> usize {
-        rsgx_unit_tests!(
+    pub fn run_tests() -> bool {
+        run_tests!(
             //DefultRuntime::tests::test_open_input();
             //DefultRuntime::tests::test_create_output();
         )


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org


Mime
View raw message