You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2020/01/08 04:56:37 UTC

[incubator-teaclave] branch develop updated: [testsuite] Fix coverage issues, enable when COV=1

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 c1dcff5  [testsuite] Fix coverage issues, enable when COV=1
c1dcff5 is described below

commit c1dcff5ff7f2301049a29bdd2a87e65588727da6
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Tue Jan 7 17:07:16 2020 -0800

    [testsuite] Fix coverage issues, enable when COV=1
---
 cmake/tomls/Cargo.sgx_untrusted_app.toml       |  1 -
 cmake/tomls/Cargo.unix_app.toml                |  1 -
 services/frontend/enclave/Cargo.toml           |  3 +--
 services/frontend/enclave/src/lib.rs           |  7 ++-----
 services/frontend/enclave/src/service.rs       |  9 +--------
 testsuite/enclave_unit_test/enclave/Cargo.toml |  7 +++----
 utils/service_enclave_utils/Cargo.toml         |  3 ++-
 utils/service_enclave_utils/src/lib.rs         | 23 +++++++++++++++--------
 8 files changed, 24 insertions(+), 30 deletions(-)

diff --git a/cmake/tomls/Cargo.sgx_untrusted_app.toml b/cmake/tomls/Cargo.sgx_untrusted_app.toml
index ecc42b2..2d8f74f 100644
--- a/cmake/tomls/Cargo.sgx_untrusted_app.toml
+++ b/cmake/tomls/Cargo.sgx_untrusted_app.toml
@@ -10,6 +10,5 @@ exclude = [
 
 [patch.crates-io]
 # We cannot remove these crates, because proto crates depend on them
-sgx_cov = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
 sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
 sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
diff --git a/cmake/tomls/Cargo.unix_app.toml b/cmake/tomls/Cargo.unix_app.toml
index 5bbe1c2..9526b29 100644
--- a/cmake/tomls/Cargo.unix_app.toml
+++ b/cmake/tomls/Cargo.unix_app.toml
@@ -12,6 +12,5 @@ exclude = [
 [patch.crates-io]
 
 # We cannot remove these crates, because proto crates depend on them
-sgx_cov = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
 sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
 sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.0" }
diff --git a/services/frontend/enclave/Cargo.toml b/services/frontend/enclave/Cargo.toml
index 488ee61..e0230d7 100644
--- a/services/frontend/enclave/Cargo.toml
+++ b/services/frontend/enclave/Cargo.toml
@@ -22,7 +22,7 @@ mesalock_sgx = [
   "teaclave_service_enclave_utils/mesalock_sgx",
   "teaclave_types/mesalock_sgx",
 ]
-cov = ["sgx_cov"]
+cov = ["teaclave_service_enclave_utils/cov"]
 enclave_unit_test = ["teaclave_ipc/enclave_unit_test", "sgx_tunittest"]
 
 [dependencies]
@@ -40,7 +40,6 @@ teaclave_service_config        = { path = "../../../utils/service_config" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 
-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/frontend/enclave/src/lib.rs b/services/frontend/enclave/src/lib.rs
index c08d88b..e35a402 100644
--- a/services/frontend/enclave/src/lib.rs
+++ b/services/frontend/enclave/src/lib.rs
@@ -94,12 +94,9 @@ register_ecall_handler!(
 #[cfg(all(test_mode, feature = "enclave_unit_test", feature = "mesalock_sgx"))]
 pub mod tests {
     use super::*;
+    use sgx_tunittest::*;
 
     pub fn run_tests() -> usize {
-        let mut nfailed = 0;
-
-        nfailed += service::tests::run_service_tests();
-
-        nfailed
+        rsgx_unit_tests!(service::tests::test_user_login)
     }
 }
diff --git a/services/frontend/enclave/src/service.rs b/services/frontend/enclave/src/service.rs
index e6b886c..263f0a8 100644
--- a/services/frontend/enclave/src/service.rs
+++ b/services/frontend/enclave/src/service.rs
@@ -41,15 +41,8 @@ impl TeaclaveFrontend for TeaclaveFrontendService {
 #[cfg(all(test_mode, feature = "enclave_unit_test", feature = "mesalock_sgx"))]
 pub mod tests {
     use super::*;
-    use sgx_tunittest::*;
 
-    pub fn run_service_tests() -> usize {
-        let nfailed = rsgx_unit_tests!(test_user_login,);
-
-        nfailed
-    }
-
-    fn test_user_login() {
+    pub fn test_user_login() {
         let request = UserLoginRequest {
             id: "test_id".to_string(),
             password: "test_password".to_string(),
diff --git a/testsuite/enclave_unit_test/enclave/Cargo.toml b/testsuite/enclave_unit_test/enclave/Cargo.toml
index c6f8ade..a76af09 100644
--- a/testsuite/enclave_unit_test/enclave/Cargo.toml
+++ b/testsuite/enclave_unit_test/enclave/Cargo.toml
@@ -23,7 +23,7 @@ mesalock_sgx = [
   "teaclave_frontend_service_enclave/mesalock_sgx",
   "teaclave_frontend_service_enclave/enclave_unit_test"
 ]
-cov = ["sgx_cov"]
+cov = ["teaclave_service_enclave_utils/cov"]
 
 [dependencies]
 log         = { version = "0.4.6" }
@@ -31,6 +31,8 @@ anyhow      = { version = "1.0.26" }
 serde       = { version = "1.0.92" }
 thiserror   = { version = "1.0.9" }
 
+teaclave_frontend_service_enclave      = { path = "../../../services/frontend/enclave" }
+
 teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
 teaclave_ipc                   = { path = "../../../ipc" }
@@ -39,8 +41,5 @@ teaclave_service_config        = { path = "../../../utils/service_config" }
 teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
 teaclave_types                 = { path = "../../../types" }
 
-teaclave_frontend_service_enclave      = { path = "../../../services/frontend/enclave" }
-
-sgx_cov   = { version = "1.1.0", optional = true }
 sgx_tstd  = { version = "1.1.0", features = ["net", "thread", "backtrace"], optional = true }
 sgx_types = { version = "1.1.0" }
diff --git a/utils/service_enclave_utils/Cargo.toml b/utils/service_enclave_utils/Cargo.toml
index ccbf403..3997dc5 100644
--- a/utils/service_enclave_utils/Cargo.toml
+++ b/utils/service_enclave_utils/Cargo.toml
@@ -12,7 +12,7 @@ mesalock_sgx = [
     "sgx_tstd",
     "teaclave_service_config/mesalock_sgx",
 ]
-cov = ["sgx_cov"]
+cov = ["sgx_cov", "sgx_trts"]
 
 [dependencies]
 anyhow     = { version = "1.0.26" }
@@ -23,4 +23,5 @@ teaclave_service_config                   = { path = "../service_config" }
 teaclave_service_enclave_utils_proc_macro = { path = "./proc_macro" }
 
 sgx_cov  = { version = "1.1.0", optional = true }
+sgx_trts = { version = "1.1.0", optional = true }
 sgx_tstd = { version = "1.1.0", features = ["net", "backtrace"], optional = true }
diff --git a/utils/service_enclave_utils/src/lib.rs b/utils/service_enclave_utils/src/lib.rs
index 594f8ff..4be6246 100644
--- a/utils/service_enclave_utils/src/lib.rs
+++ b/utils/service_enclave_utils/src/lib.rs
@@ -3,14 +3,22 @@
 #[macro_use]
 extern crate sgx_tstd as std;
 
-use anyhow::{self, Result};
+use anyhow::{anyhow, Result};
 use teaclave_service_config as config;
-pub use teaclave_service_enclave_utils_proc_macro::teaclave_service;
 
 use log::debug;
 use log::error;
 use std::backtrace;
 
+#[cfg(feature = "cov")]
+use sgx_trts::global_dtors_object;
+#[cfg(feature = "cov")]
+global_dtors_object! {
+    SGX_COV_FINALIZE, sgx_cov_exit = {
+        sgx_cov::cov_writeout();
+    }
+}
+
 pub struct ServiceEnclave;
 
 impl ServiceEnclave {
@@ -23,22 +31,21 @@ impl ServiceEnclave {
             .is_err()
         {
             error!("Cannot enable backtrace");
-            return Err(anyhow::anyhow!("ecall error"));
+            return Err(anyhow!("ecall error"));
         }
         if !config::is_runtime_config_initialized() {
             error!("Runtime config is not initialized");
-            return Err(anyhow::anyhow!("ecall error"));
+            return Err(anyhow!("ecall error"));
         }
 
         Ok(())
     }
 
     pub fn finalize() -> Result<()> {
-        debug!("Enclave finalizing...");
-
-        #[cfg(feature = "cov")]
-        sgx_cov::cov_writeout();
+        debug!("Enclave finalizing");
 
         Ok(())
     }
 }
+
+pub use teaclave_service_enclave_utils_proc_macro::teaclave_service;


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