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/15 00:14:29 UTC
[incubator-teaclave] branch develop updated: [testsuite] Add
leveldb_tests
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 0d8e9ae [testsuite] Add leveldb_tests
0d8e9ae is described below
commit 0d8e9ae160c544534b71704dcb8e5d8bc85e3e85
Author: Mingshen Sun <bo...@mssun.me>
AuthorDate: Tue Jan 14 15:51:40 2020 -0800
[testsuite] Add leveldb_tests
---
cmake/tomls/Cargo.sgx_trusted_lib.toml | 1 +
cmake/tomls/Cargo.sgx_untrusted_app.toml | 1 +
ipc/src/protos/command.rs | 6 +-
ipc/src/protos/ecall.rs | 4 +-
testsuite/leveldb_tests/app/Cargo.toml | 19 ++++++
testsuite/leveldb_tests/app/build.rs | 51 ++++++++++++++++
.../app/src/main.rs | 8 +--
testsuite/leveldb_tests/enclave/Cargo.toml | 48 +++++++++++++++
testsuite/leveldb_tests/enclave/Enclave.config.xml | 12 ++++
.../leveldb_tests/enclave/src/leveldb_tests.rs | 68 ++++++++++++++++++++++
.../enclave/src/lib.rs | 15 ++---
testsuite/service_functional_test/app/src/main.rs | 8 +--
.../service_functional_test/enclave/src/lib.rs | 10 ++--
13 files changed, 223 insertions(+), 28 deletions(-)
diff --git a/cmake/tomls/Cargo.sgx_trusted_lib.toml b/cmake/tomls/Cargo.sgx_trusted_lib.toml
index df1e973..bc01716 100644
--- a/cmake/tomls/Cargo.sgx_trusted_lib.toml
+++ b/cmake/tomls/Cargo.sgx_trusted_lib.toml
@@ -4,6 +4,7 @@ members = [
"services/authentication/enclave",
"testsuite/enclave_unit_test/enclave",
"testsuite/service_functional_test/enclave",
+ "testsuite/leveldb_tests/enclave",
]
exclude = [
diff --git a/cmake/tomls/Cargo.sgx_untrusted_app.toml b/cmake/tomls/Cargo.sgx_untrusted_app.toml
index 34615bb..feca7e9 100644
--- a/cmake/tomls/Cargo.sgx_untrusted_app.toml
+++ b/cmake/tomls/Cargo.sgx_untrusted_app.toml
@@ -4,6 +4,7 @@ members = [
"services/authentication/app",
"testsuite/enclave_unit_test/app",
"testsuite/service_functional_test/app",
+ "testsuite/leveldb_tests/app",
]
exclude = [
diff --git a/ipc/src/protos/command.rs b/ipc/src/protos/command.rs
index 4a0e522..fc55967 100644
--- a/ipc/src/protos/command.rs
+++ b/ipc/src/protos/command.rs
@@ -22,7 +22,7 @@ pub enum ECallCommand {
FinalizeEnclave,
RunEnclaveUnitTest,
ServeConnection,
- RunServiceFunctionalTest,
+ RunFunctionalTest,
Unimplemented,
}
@@ -35,7 +35,7 @@ impl From<u32> for ECallCommand {
0x0000_1002 => ECallCommand::FinalizeEnclave,
0x0000_1003 => ECallCommand::RunEnclaveUnitTest,
0x0000_1004 => ECallCommand::ServeConnection,
- 0x0000_1005 => ECallCommand::RunServiceFunctionalTest,
+ 0x0000_1005 => ECallCommand::RunFunctionalTest,
_ => ECallCommand::Unimplemented,
}
}
@@ -50,7 +50,7 @@ impl Into<u32> for ECallCommand {
ECallCommand::FinalizeEnclave => 0x0000_1002,
ECallCommand::RunEnclaveUnitTest => 0x0000_1003,
ECallCommand::ServeConnection => 0x0000_1004,
- ECallCommand::RunServiceFunctionalTest => 0x0000_1005,
+ ECallCommand::RunFunctionalTest => 0x0000_1005,
ECallCommand::Unimplemented => 0xffff_ffff,
}
}
diff --git a/ipc/src/protos/ecall.rs b/ipc/src/protos/ecall.rs
index 99d4d72..785f3b8 100644
--- a/ipc/src/protos/ecall.rs
+++ b/ipc/src/protos/ecall.rs
@@ -58,10 +58,10 @@ pub struct RunEnclaveUnitTestOutput {
}
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
-pub struct RunServiceFunctionalTestInput;
+pub struct RunFunctionalTestInput;
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
-pub struct RunServiceFunctionalTestOutput;
+pub struct RunFunctionalTestOutput;
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct ServeConnectionInput {
diff --git a/testsuite/leveldb_tests/app/Cargo.toml b/testsuite/leveldb_tests/app/Cargo.toml
new file mode 100644
index 0000000..c345a2b
--- /dev/null
+++ b/testsuite/leveldb_tests/app/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "teaclave_leveldb_tests"
+version = "0.1.0"
+authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+description = "LevelDB functional tests"
+license = "Apache-2.0"
+build = "build.rs"
+edition = "2018"
+
+[dependencies]
+log = { version = "0.4.6" }
+env_logger = { version = "0.7.1" }
+anyhow = { version = "1.0.26" }
+
+teaclave_ipc = { path = "../../../ipc" }
+teaclave_service_app_utils = { path = "../../../utils/service_app_utils" }
+teaclave_binder = { path = "../../../binder" }
+
+sgx_types = { version = "1.1.0" }
diff --git a/testsuite/leveldb_tests/app/build.rs b/testsuite/leveldb_tests/app/build.rs
new file mode 100644
index 0000000..b92afb5
--- /dev/null
+++ b/testsuite/leveldb_tests/app/build.rs
@@ -0,0 +1,51 @@
+// 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.
+
+use std::env;
+use std::path::PathBuf;
+
+fn choose_sgx_dylib(is_sim: bool) {
+ if is_sim {
+ println!("cargo:rustc-link-lib=dylib=sgx_urts_sim");
+ println!("cargo:rustc-link-lib=dylib=sgx_uae_service_sim");
+ } else {
+ println!("cargo:rustc-link-lib=dylib=sgx_urts");
+ println!("cargo:rustc-link-lib=dylib=sgx_uae_service");
+ }
+}
+
+fn main() {
+ let sdk_dir = env::var("SGX_SDK").unwrap_or("/opt/intel/sgxsdk".into());
+ println!("cargo:rustc-link-search=native={}/lib64", sdk_dir);
+
+ let out_path = env::var_os("ENCLAVE_OUT_DIR").unwrap_or("out".into());
+ let out_dir = &PathBuf::from(out_path);
+
+ println!("cargo:rustc-link-search=native={}", out_dir.display());
+ println!("cargo:rustc-link-lib=static=Enclave_u");
+
+ let is_sim = match env::var("SGX_MODE") {
+ Ok(ref v) if v == "SW" => true,
+ Ok(ref v) if v == "HW" => false,
+ Err(env::VarError::NotPresent) => false,
+ _ => {
+ panic!("Stop build process, wrong SGX_MODE env provided.");
+ }
+ };
+
+ choose_sgx_dylib(is_sim);
+}
diff --git a/testsuite/service_functional_test/app/src/main.rs b/testsuite/leveldb_tests/app/src/main.rs
similarity index 82%
copy from testsuite/service_functional_test/app/src/main.rs
copy to testsuite/leveldb_tests/app/src/main.rs
index ec21d84..5f4fb60 100644
--- a/testsuite/service_functional_test/app/src/main.rs
+++ b/testsuite/leveldb_tests/app/src/main.rs
@@ -18,7 +18,7 @@
use anyhow;
use std::sync::Arc;
use teaclave_binder::TeeBinder;
-use teaclave_ipc::protos::ecall::{RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput};
+use teaclave_ipc::protos::ecall::{RunFunctionalTestInput, RunFunctionalTestOutput};
use teaclave_ipc::protos::ECallCommand;
use teaclave_service_app_utils::ServiceEnclaveBuilder;
@@ -30,10 +30,10 @@ fn main() -> anyhow::Result<()> {
}
fn start_enclave_unit_test_driver(tee: Arc<TeeBinder>) -> anyhow::Result<()> {
- let cmd = ECallCommand::RunServiceFunctionalTest;
- let _ = tee.invoke::<RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput>(
+ let cmd = ECallCommand::RunFunctionalTest;
+ let _ = tee.invoke::<RunFunctionalTestInput, RunFunctionalTestOutput>(
cmd.into(),
- RunServiceFunctionalTestInput,
+ RunFunctionalTestInput,
);
Ok(())
diff --git a/testsuite/leveldb_tests/enclave/Cargo.toml b/testsuite/leveldb_tests/enclave/Cargo.toml
new file mode 100644
index 0000000..f7c273a
--- /dev/null
+++ b/testsuite/leveldb_tests/enclave/Cargo.toml
@@ -0,0 +1,48 @@
+[package]
+name = "teaclave_leveldb_tests_enclave"
+version = "0.1.0"
+authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+description = "Service Functional Test"
+license = "Apache-2.0"
+edition = "2018"
+
+[lib]
+name = "teaclave_leveldb_tests_enclave"
+crate-type = ["staticlib"]
+
+[features]
+default = []
+mesalock_sgx = [
+ "sgx_tstd",
+ "teaclave_attestation/mesalock_sgx",
+ "teaclave_proto/mesalock_sgx",
+ "teaclave_ipc/mesalock_sgx",
+ "teaclave_rpc/mesalock_sgx",
+ "teaclave_service_config/mesalock_sgx",
+ "teaclave_service_enclave_utils/mesalock_sgx",
+ "teaclave_types/mesalock_sgx",
+ "rusty-leveldb/mesalock_sgx",
+]
+cov = ["teaclave_service_enclave_utils/cov"]
+
+[dependencies]
+log = { version = "0.4.6" }
+anyhow = { version = "1.0.26" }
+serde = { version = "1.0.92" }
+thiserror = { version = "1.0.9" }
+rand = { version = "0.7.0" }
+
+rusty-leveldb = { path = "../../../common/rusty_leveldb_sgx", default-features = false, optional = true }
+
+teaclave_attestation = { path = "../../../attestation" }
+teaclave_config = { path = "../../../config" }
+teaclave_ipc = { path = "../../../ipc" }
+teaclave_rpc = { path = "../../../rpc" }
+teaclave_service_config = { path = "../../../utils/service_config" }
+teaclave_service_enclave_utils = { path = "../../../utils/service_enclave_utils" }
+teaclave_types = { path = "../../../types" }
+teaclave_proto = { path = "../../../services/proto" }
+
+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/testsuite/leveldb_tests/enclave/Enclave.config.xml b/testsuite/leveldb_tests/enclave/Enclave.config.xml
new file mode 100644
index 0000000..705edcd
--- /dev/null
+++ b/testsuite/leveldb_tests/enclave/Enclave.config.xml
@@ -0,0 +1,12 @@
+<!-- Please refer to User's Guide for the explanation of each field -->
+<EnclaveConfiguration>
+ <ProdID>0</ProdID>
+ <ISVSVN>0</ISVSVN>
+ <StackMaxSize>0x200000</StackMaxSize>
+ <HeapMaxSize>0x1000000</HeapMaxSize>
+ <TCSNum>22</TCSNum>
+ <TCSPolicy>0</TCSPolicy>
+ <DisableDebug>0</DisableDebug>
+ <MiscSelect>0</MiscSelect>
+ <MiscMask>0xFFFFFFFF</MiscMask>
+</EnclaveConfiguration>
diff --git a/testsuite/leveldb_tests/enclave/src/leveldb_tests.rs b/testsuite/leveldb_tests/enclave/src/leveldb_tests.rs
new file mode 100644
index 0000000..bea62ed
--- /dev/null
+++ b/testsuite/leveldb_tests/enclave/src/leveldb_tests.rs
@@ -0,0 +1,68 @@
+use rand::distributions::Alphanumeric;
+use rand::Rng;
+use sgx_tunittest::*;
+use std::iter;
+use std::prelude::v1::*;
+use std::string::String;
+
+use rusty_leveldb::CompressionType;
+use rusty_leveldb::Options;
+use rusty_leveldb::DB;
+
+use std::error::Error;
+use std::io::{self, ErrorKind};
+use std::untrusted::fs;
+
+const KEY_LEN: usize = 16;
+const VAL_LEN: usize = 48;
+
+fn gen_string(len: usize) -> String {
+ let mut rng = rand::thread_rng();
+ iter::repeat(())
+ .map(|()| rng.sample(Alphanumeric))
+ .take(len)
+ .collect()
+}
+
+fn fill_db(db: &mut DB, entries: usize) -> Result<(), Box<dyn Error>> {
+ for i in 0..entries {
+ let (k, v) = (gen_string(KEY_LEN), gen_string(VAL_LEN));
+ db.put(k.as_bytes(), v.as_bytes())?;
+ if i % 1000 == 0 {
+ db.flush()?;
+
+ let v2 = db
+ .get(k.as_bytes())
+ .ok_or_else(|| Box::new(io::Error::new(ErrorKind::NotFound, "Key not found")))?;
+ assert_eq!(&v.as_bytes()[..], &v2[..]);
+
+ db.delete(k.as_bytes())?;
+ assert_eq!(true, db.get(k.as_bytes()).is_none());
+ }
+
+ if i % 100 == 0 {
+ db.flush()?;
+ }
+ }
+ Ok(())
+}
+
+fn test_write_a_lot() {
+ let key = [
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09,
+ 0x08,
+ ];
+ let mut opt = Options::new_disk_db_with(key);
+ opt.compression_type = CompressionType::CompressionSnappy;
+ let mut db = DB::open("/tmp/leveldb_testdb", opt).unwrap();
+
+ fill_db(&mut db, 32768).unwrap();
+
+ drop(db);
+
+ fs::remove_dir_all("/tmp/leveldb_testdb").expect("Cannot remove directory");
+}
+
+pub fn run_tests() {
+ rsgx_unit_tests!(test_write_a_lot);
+}
diff --git a/testsuite/service_functional_test/enclave/src/lib.rs b/testsuite/leveldb_tests/enclave/src/lib.rs
similarity index 80%
copy from testsuite/service_functional_test/enclave/src/lib.rs
copy to testsuite/leveldb_tests/enclave/src/lib.rs
index de8fe49..781d539 100644
--- a/testsuite/service_functional_test/enclave/src/lib.rs
+++ b/testsuite/leveldb_tests/enclave/src/lib.rs
@@ -29,21 +29,18 @@ use teaclave_types;
use teaclave_ipc::protos::ecall::{
FinalizeEnclaveInput, FinalizeEnclaveOutput, InitEnclaveInput, InitEnclaveOutput,
- RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput,
+ RunFunctionalTestInput, RunFunctionalTestOutput,
};
use teaclave_ipc::protos::ECallCommand;
use teaclave_ipc::{handle_ecall, register_ecall_handler};
use teaclave_service_enclave_utils::ServiceEnclave;
-mod teaclave_authentication_service;
+mod leveldb_tests;
#[handle_ecall]
-fn handle_run_enclave_unit_test(
- _args: &RunServiceFunctionalTestInput,
-) -> Result<RunServiceFunctionalTestOutput> {
- teaclave_authentication_service::run_functional_tests();
-
- Ok(RunServiceFunctionalTestOutput::default())
+fn handle_run_functional_test(_args: &RunFunctionalTestInput) -> Result<RunFunctionalTestOutput> {
+ leveldb_tests::run_tests();
+ Ok(RunFunctionalTestOutput::default())
}
#[handle_ecall]
@@ -60,7 +57,7 @@ fn handle_finalize_enclave(_args: &FinalizeEnclaveInput) -> Result<FinalizeEncla
register_ecall_handler!(
type ECallCommand,
- (ECallCommand::RunServiceFunctionalTest, RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput),
+ (ECallCommand::RunFunctionalTest, RunFunctionalTestInput, RunFunctionalTestOutput),
(ECallCommand::InitEnclave, InitEnclaveInput, InitEnclaveOutput),
(ECallCommand::FinalizeEnclave, FinalizeEnclaveInput, FinalizeEnclaveOutput),
);
diff --git a/testsuite/service_functional_test/app/src/main.rs b/testsuite/service_functional_test/app/src/main.rs
index ec21d84..5f4fb60 100644
--- a/testsuite/service_functional_test/app/src/main.rs
+++ b/testsuite/service_functional_test/app/src/main.rs
@@ -18,7 +18,7 @@
use anyhow;
use std::sync::Arc;
use teaclave_binder::TeeBinder;
-use teaclave_ipc::protos::ecall::{RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput};
+use teaclave_ipc::protos::ecall::{RunFunctionalTestInput, RunFunctionalTestOutput};
use teaclave_ipc::protos::ECallCommand;
use teaclave_service_app_utils::ServiceEnclaveBuilder;
@@ -30,10 +30,10 @@ fn main() -> anyhow::Result<()> {
}
fn start_enclave_unit_test_driver(tee: Arc<TeeBinder>) -> anyhow::Result<()> {
- let cmd = ECallCommand::RunServiceFunctionalTest;
- let _ = tee.invoke::<RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput>(
+ let cmd = ECallCommand::RunFunctionalTest;
+ let _ = tee.invoke::<RunFunctionalTestInput, RunFunctionalTestOutput>(
cmd.into(),
- RunServiceFunctionalTestInput,
+ RunFunctionalTestInput,
);
Ok(())
diff --git a/testsuite/service_functional_test/enclave/src/lib.rs b/testsuite/service_functional_test/enclave/src/lib.rs
index de8fe49..7b1e845 100644
--- a/testsuite/service_functional_test/enclave/src/lib.rs
+++ b/testsuite/service_functional_test/enclave/src/lib.rs
@@ -29,7 +29,7 @@ use teaclave_types;
use teaclave_ipc::protos::ecall::{
FinalizeEnclaveInput, FinalizeEnclaveOutput, InitEnclaveInput, InitEnclaveOutput,
- RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput,
+ RunFunctionalTestInput, RunFunctionalTestOutput,
};
use teaclave_ipc::protos::ECallCommand;
use teaclave_ipc::{handle_ecall, register_ecall_handler};
@@ -38,12 +38,10 @@ use teaclave_service_enclave_utils::ServiceEnclave;
mod teaclave_authentication_service;
#[handle_ecall]
-fn handle_run_enclave_unit_test(
- _args: &RunServiceFunctionalTestInput,
-) -> Result<RunServiceFunctionalTestOutput> {
+fn handle_run_enclave_unit_test(_args: &RunFunctionalTestInput) -> Result<RunFunctionalTestOutput> {
teaclave_authentication_service::run_functional_tests();
- Ok(RunServiceFunctionalTestOutput::default())
+ Ok(RunFunctionalTestOutput::default())
}
#[handle_ecall]
@@ -60,7 +58,7 @@ fn handle_finalize_enclave(_args: &FinalizeEnclaveInput) -> Result<FinalizeEncla
register_ecall_handler!(
type ECallCommand,
- (ECallCommand::RunServiceFunctionalTest, RunServiceFunctionalTestInput, RunServiceFunctionalTestOutput),
+ (ECallCommand::RunFunctionalTest, RunFunctionalTestInput, RunFunctionalTestOutput),
(ECallCommand::InitEnclave, InitEnclaveInput, InitEnclaveOutput),
(ECallCommand::FinalizeEnclave, FinalizeEnclaveInput, FinalizeEnclaveOutput),
);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org