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 87916e9 [common] Make leveldb sgx only and enable unit test (#243)
87916e9 is described below
commit 87916e990ae7b993a8c5ace85ebf6e337d3a5d64
Author: Zhaofeng Chen <[email protected]>
AuthorDate: Sun Mar 22 22:42:06 2020 -0700
[common] Make leveldb sgx only and enable unit test (#243)
---
common/rusty_leveldb_sgx/Cargo.toml | 5 +-
common/rusty_leveldb_sgx/src/disk_env.rs | 273 +++++++++----------------------
common/rusty_leveldb_sgx/src/env.rs | 26 +--
common/rusty_leveldb_sgx/src/lib.rs | 27 +--
common/rusty_leveldb_sgx/src/mem_env.rs | 8 +-
common/rusty_leveldb_sgx/src/options.rs | 138 +++++-----------
tests/unit/enclave/Cargo.toml | 5 +-
tests/unit/enclave/src/lib.rs | 2 +
8 files changed, 153 insertions(+), 331 deletions(-)
diff --git a/common/rusty_leveldb_sgx/Cargo.toml
b/common/rusty_leveldb_sgx/Cargo.toml
index 251d53b..c3a9a78 100644
--- a/common/rusty_leveldb_sgx/Cargo.toml
+++ b/common/rusty_leveldb_sgx/Cargo.toml
@@ -12,17 +12,18 @@ publish = true
edition = "2018"
[features]
-default = []
+default = ["mesalock_sgx"]
mesalock_sgx = ["protected_fs_rs/mesalock_sgx", "sgx_libc", "sgx_tstd",
"sgx_types", "sgx_trts"]
+enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
[dependencies]
crc = { version = "2.0" }
rand = { version = "0.7" }
snap = { version = "0.2" }
-cfg-if = { version = "0.1.9" }
integer-encoding = { version = "1.0" }
protected_fs_rs = { path = "../protected_fs_rs", optional = true }
+teaclave_test_utils = { path = "../../tests/utils", optional = true }
sgx_tstd = { version = "1.1.0", optional = true }
sgx_trts = { version = "1.1.0", optional = true }
diff --git a/common/rusty_leveldb_sgx/src/disk_env.rs
b/common/rusty_leveldb_sgx/src/disk_env.rs
index af81ee3..7232de4 100644
--- a/common/rusty_leveldb_sgx/src/disk_env.rs
+++ b/common/rusty_leveldb_sgx/src/disk_env.rs
@@ -7,22 +7,15 @@ use crate::error::{err, Result, Status, StatusCode};
use std::collections::HashMap;
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- use std::untrusted::fs;
- use std::untrusted::path::PathEx;
- use protected_fs;
- use std::io::{Seek, SeekFrom};
-
- pub type DBPersistKey = [u8; 16];
- } else {
- use std::fs;
- }
-}
+use protected_fs;
+use std::io::{Seek, SeekFrom};
+use std::untrusted::fs;
+use std::untrusted::path::PathEx;
+
+pub type DBPersistKey = [u8; 16];
use std::io::{self, Read, Write};
use std::iter::FromIterator;
-use std::os::unix::io::IntoRawFd;
use std::path::{Path, PathBuf};
use std::sync::{Arc, SgxMutex as Mutex};
@@ -36,26 +29,15 @@ type FileDescriptor = i32;
#[derive(Clone)]
pub struct PosixDiskEnv {
- locks: Arc<Mutex<HashMap<String, FileDescriptor>>>,
- #[cfg(feature = "mesalock_sgx")]
+ locks: Arc<Mutex<HashMap<String, protected_fs::ProtectedFile>>>,
key: DBPersistKey,
}
impl PosixDiskEnv {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- pub fn new_with(key: DBPersistKey) -> PosixDiskEnv {
- PosixDiskEnv {
- locks: Arc::new(Mutex::new(HashMap::new())),
- key
- }
- }
- } else {
- pub fn new() -> PosixDiskEnv {
- PosixDiskEnv {
- locks: Arc::new(Mutex::new(HashMap::new())),
- }
- }
+ pub fn new_with(key: DBPersistKey) -> PosixDiskEnv {
+ PosixDiskEnv {
+ locks: Arc::new(Mutex::new(HashMap::new())),
+ key,
}
}
}
@@ -71,90 +53,39 @@ fn map_err_with_name(method: &'static str, f: &Path, e:
io::Error) -> Status {
// error conversion using std::convert::From.
impl Env for PosixDiskEnv {
fn open_sequential_file(&self, p: &Path) -> Result<Box<dyn Read>> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- Ok(Box::new(
- protected_fs::OpenOptions::default()
- .read(true)
- .open_ex(p, &self.key)
- .map_err(|e| map_err_with_name("open_sgx (seq)", p,
e))?,
- ))
- } else {
- Ok(Box::new(
- fs::OpenOptions::new()
- .read(true)
- .open(p)
- .map_err(|e| map_err_with_name("open (seq)", p, e))?,
- ))
- }
- }
+ Ok(Box::new(
+ protected_fs::OpenOptions::default()
+ .read(true)
+ .open_ex(p, &self.key)
+ .map_err(|e| map_err_with_name("open_sgx (seq)", p, e))?,
+ ))
}
fn open_random_access_file(&self, p: &Path) -> Result<Box<dyn
RandomAccess>> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- Ok(protected_fs::OpenOptions::default()
- .read(true)
- .open_ex(p, &self.key)
- .map(|f| {
- let b: Box<dyn RandomAccess> = Box::new(f);
- b
- })
- .map_err(|e| map_err_with_name("open_sgx (randomaccess)",
p, e))?)
- } else {
- Ok(fs::OpenOptions::new()
- .read(true)
- .open(p)
- .map(|f| {
- let b: Box<dyn RandomAccess> = Box::new(f);
- b
- })
- .map_err(|e| map_err_with_name("open (randomaccess)", p,
e))?)
- }
- }
+ Ok(protected_fs::OpenOptions::default()
+ .read(true)
+ .open_ex(p, &self.key)
+ .map(|f| {
+ let b: Box<dyn RandomAccess> = Box::new(f);
+ b
+ })
+ .map_err(|e| map_err_with_name("open_sgx (randomaccess)", p, e))?)
}
fn open_writable_file(&self, p: &Path) -> Result<Box<dyn Write>> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- Ok(Box::new(
- protected_fs::OpenOptions::default()
- .write(true)
- .append(false)
- .open_ex(p, &self.key)
- .map_err(|e| map_err_with_name("open_sgx (write)", p,
e))?,
- ))
- }
- else {
- Ok(Box::new(
- fs::OpenOptions::new()
- .create(true)
- .write(true)
- .append(false)
- .open(p)
- .map_err(|e| map_err_with_name("open (write)", p, e))?,
- ))
- }
- }
+ Ok(Box::new(
+ protected_fs::OpenOptions::default()
+ .write(true)
+ .append(false)
+ .open_ex(p, &self.key)
+ .map_err(|e| map_err_with_name("open_sgx (write)", p, e))?,
+ ))
}
fn open_appendable_file(&self, p: &Path) -> Result<Box<dyn Write>> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- Ok(Box::new(
- protected_fs::OpenOptions::default()
- .append(true)
- .open_ex(p, &self.key)
- .map_err(|e| map_err_with_name("open_sgx
(append_sgx)", p, e))?,
- ))
- } else {
- Ok(Box::new(
- fs::OpenOptions::new()
- .create(true)
- .write(true)
- .append(true)
- .open(p)
- .map_err(|e| map_err_with_name("open (append)", p,
e))?,
- ))
- }
- }
+ Ok(Box::new(
+ protected_fs::OpenOptions::default()
+ .append(true)
+ .open_ex(p, &self.key)
+ .map_err(|e| map_err_with_name("open_sgx (append_sgx)", p,
e))?,
+ ))
}
fn exists(&self, p: &Path) -> Result<bool> {
Ok(p.exists())
@@ -175,20 +106,12 @@ impl Env for PosixDiskEnv {
}
fn size_of(&self, p: &Path) -> Result<usize> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- let mut f = protected_fs::OpenOptions::default()
- .read(true)
- .open_ex(p, &self.key)
- .map_err(|e| map_err_with_name("size_of (open)", p,
e))?;
- let size = f.seek(SeekFrom::End(0))?;
- Ok(size as usize)
- }
- else {
- let meta = fs::metadata(p).map_err(|e|
map_err_with_name("size_of", p, e))?;
- Ok(meta.len() as usize)
- }
- }
+ let mut f = protected_fs::OpenOptions::default()
+ .read(true)
+ .open_ex(p, &self.key)
+ .map_err(|e| map_err_with_name("size_of (open)", p, e))?;
+ let size = f.seek(SeekFrom::End(0))?;
+ Ok(size as usize)
}
fn delete(&self, p: &Path) -> Result<()> {
@@ -201,26 +124,26 @@ impl Env for PosixDiskEnv {
Ok(fs::remove_dir_all(p).map_err(|e| map_err_with_name("rmdir", p,
e))?)
}
fn rename(&self, old: &Path, new: &Path) -> Result<()> {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- let old_name = old.file_name()
- .ok_or(map_err_with_name("rename1", old,
io::Error::from_raw_os_error(21)))?;
- let new_name = new.file_name()
- .ok_or(map_err_with_name("rename2", old,
io::Error::from_raw_os_error(21)))?;
-
- {
- let f = protected_fs::OpenOptions::default()
- .append(true)
- .open_ex(old, &self.key)
- .map_err(|e| map_err_with_name("rename_meta
(open)", old, e))?;
- f.rename_meta(&old_name, &new_name)?;
- }
+ let old_name = old.file_name().ok_or(map_err_with_name(
+ "rename1",
+ old,
+ io::Error::from_raw_os_error(21),
+ ))?;
+ let new_name = new.file_name().ok_or(map_err_with_name(
+ "rename2",
+ old,
+ io::Error::from_raw_os_error(21),
+ ))?;
- Ok(fs::rename(old, new).map_err(|e|
map_err_with_name("rename", old, e))?)
- } else {
- Ok(fs::rename(old, new).map_err(|e|
map_err_with_name("rename", old, e))?)
- }
+ {
+ let f = protected_fs::OpenOptions::default()
+ .append(true)
+ .open_ex(old, &self.key)
+ .map_err(|e| map_err_with_name("rename_meta (open)", old, e))?;
+ f.rename_meta(&old_name, &new_name)?;
}
+
+ Ok(fs::rename(old, new).map_err(|e| map_err_with_name("rename", old,
e))?)
}
fn lock(&self, p: &Path) -> Result<FileLock> {
@@ -229,31 +152,13 @@ impl Env for PosixDiskEnv {
if locks.contains_key(&p.to_str().unwrap().to_string()) {
Err(Status::new(StatusCode::AlreadyExists, "Lock is held"))
} else {
- let f = fs::OpenOptions::new()
+ let f = protected_fs::OpenOptions::default()
.write(true)
- .create(true)
- .open(p)
- .map_err(|e| map_err_with_name("lock", p, e))?;
-
- let fd = f.into_raw_fd();
- // FIXME:
- //let result = unsafe { libc::flock(fd as libc::c_int,
libc::LOCK_EX | libc::LOCK_NB) };
- let result = 0;
-
- if result < 0 {
- if libc::errno() == libc::EWOULDBLOCK {
- return Err(Status::new(
- StatusCode::LockError,
- "lock on database is already held by different
process",
- ));
- }
- return Err(Status::new(
- StatusCode::Errno(libc::errno()),
- &format!("unknown lock error on fd {} (file {})", fd,
p.display()),
- ));
- }
+ .append(false)
+ .open_ex(p, &self.key)
+ .map_err(|e| map_err_with_name("lock_sgx: ", p, e))?;
- locks.insert(p.to_str().unwrap().to_string(), fd);
+ locks.insert(p.to_str().unwrap().to_string(), f);
let lock = FileLock {
id: p.to_str().unwrap().to_string(),
};
@@ -268,20 +173,7 @@ impl Env for PosixDiskEnv {
&format!("unlocking a file that is not locked: {}", l.id),
);
} else {
- let fd = locks.remove(&l.id).unwrap();
- let result = unsafe {
- let ok = libc::ocall::fcntl_arg0(fd, libc::F_GETFD);
- if ok < 0 {
- // Likely EBADF when already closed. In that case, the
lock is released and all is fine.
- return Ok(());
- }
- // FIXME::
- //libc::flock(fd, libc::LOCK_UN)
- 0
- };
- if result < 0 {
- return err(StatusCode::LockError, &format!("unlock failed:
{}", l.id));
- }
+ locks.remove(&l.id).unwrap();
Ok(())
}
}
@@ -296,19 +188,22 @@ impl Env for PosixDiskEnv {
}
}
-#[cfg(test)]
-mod tests {
+#[cfg(feature = "enclave_unit_test")]
+pub mod tests {
use super::*;
-
use std::convert::AsRef;
use std::io::Write;
use std::iter::FromIterator;
+ use teaclave_test_utils::*;
+
+ pub fn run_tests() -> bool {
+ run_tests!(test_files, test_locking, test_dirs,)
+ }
- #[test]
fn test_files() {
let n = "testfile.xyz".to_string();
let name = n.as_ref();
- let env = PosixDiskEnv::new();
+ let env = PosixDiskEnv::new_with([0u8; 16]);
// exists, size_of, delete
assert!(env.open_appendable_file(name).is_ok());
@@ -332,13 +227,7 @@ mod tests {
// rename
let newname = Path::new("testfile2.xyz");
assert!(env.rename(name, newname).is_ok());
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- assert_eq!(false, env.size_of(newname).is_err());
- } else {
- assert_eq!(6, env.size_of(newname).unwrap());
- }
- }
+ assert_eq!(false, env.size_of(newname).is_err());
assert!(!env.exists(name).unwrap());
// rename back so that the remaining tests can use the file.
assert!(env.rename(newname, name).is_ok());
@@ -350,10 +239,9 @@ mod tests {
assert!(env.delete(name).is_ok());
}
- #[test]
fn test_locking() {
- let env = PosixDiskEnv::new();
- let n = "testfile.123".to_string();
+ let env = PosixDiskEnv::new_with([0u8; 16]);
+ let n = "acquire_lock.123".to_string();
let name = n.as_ref();
{
@@ -381,11 +269,10 @@ mod tests {
assert!(env.delete(name).is_ok());
}
- #[test]
fn test_dirs() {
let d = "subdir/";
let dirname = d.as_ref();
- let env = PosixDiskEnv::new();
+ let env = PosixDiskEnv::new_with([0u8; 16]);
assert!(env.mkdir(dirname).is_ok());
assert!(env
diff --git a/common/rusty_leveldb_sgx/src/env.rs
b/common/rusty_leveldb_sgx/src/env.rs
index 64ead57..33ce983 100644
--- a/common/rusty_leveldb_sgx/src/env.rs
+++ b/common/rusty_leveldb_sgx/src/env.rs
@@ -6,36 +6,18 @@ use std::prelude::v1::*;
use crate::error::Result;
use std::io::prelude::*;
-use std::os::unix::fs::FileExt;
use std::path::{Path, PathBuf};
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- use protected_fs::ProtectedFile;
- use crate::error::Status;
- use std::untrusted::fs::File;
- } else {
- use std::fs::File;
- }
-}
+use crate::error::Status;
+use protected_fs::ProtectedFile;
pub trait RandomAccess {
fn read_at(&self, off: usize, dst: &mut [u8]) -> Result<usize>;
}
-impl RandomAccess for File {
+impl RandomAccess for ProtectedFile {
fn read_at(&self, off: usize, dst: &mut [u8]) -> Result<usize> {
- Ok((self as &dyn FileExt).read_at(dst, off as u64)?)
- }
-}
-
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- impl RandomAccess for ProtectedFile {
- fn read_at(&self, off: usize, dst: &mut [u8]) -> Result<usize> {
- self.read_at(off, dst).map_err(|e| Status::from(e))
- }
- }
+ self.read_at(off, dst).map_err(|e| Status::from(e))
}
}
diff --git a/common/rusty_leveldb_sgx/src/lib.rs
b/common/rusty_leveldb_sgx/src/lib.rs
index dd90aa9..b305145 100644
--- a/common/rusty_leveldb_sgx/src/lib.rs
+++ b/common/rusty_leveldb_sgx/src/lib.rs
@@ -28,18 +28,10 @@
#[macro_use]
extern crate sgx_tstd as std;
-#[macro_use]
-extern crate cfg_if;
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- extern crate sgx_libc as libc;
- extern crate sgx_trts;
- extern crate sgx_types;
- extern crate protected_fs;
- } else {
- extern crate libc;
- }
-}
+extern crate protected_fs;
+extern crate sgx_libc as libc;
+extern crate sgx_trts;
+extern crate sgx_types;
extern crate crc;
extern crate integer_encoding;
@@ -97,3 +89,14 @@ pub use crate::types::LdbIterator;
pub use crate::write_batch::WriteBatch;
pub use db_impl::DB;
pub use disk_env::PosixDiskEnv;
+
+#[cfg(feature = "enclave_unit_test")]
+pub mod tests {
+ use super::*;
+ use std::prelude::v1::*;
+ use teaclave_test_utils::check_all_passed;
+
+ pub fn run_tests() -> bool {
+ check_all_passed!(disk_env::tests::run_tests())
+ }
+}
diff --git a/common/rusty_leveldb_sgx/src/mem_env.rs
b/common/rusty_leveldb_sgx/src/mem_env.rs
index 986caba..366df23 100644
--- a/common/rusty_leveldb_sgx/src/mem_env.rs
+++ b/common/rusty_leveldb_sgx/src/mem_env.rs
@@ -12,13 +12,7 @@ use std::io::{self, Read, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- use std::sync::{Arc, SgxMutex as Mutex};
- } else {
- use std::sync::{Arc, Mutex};
- }
-}
+use std::sync::{Arc, SgxMutex as Mutex};
/// BufferBackedFile is a simple type implementing RandomAccess on a Vec<u8>.
pub type BufferBackedFile = Vec<u8>;
diff --git a/common/rusty_leveldb_sgx/src/options.rs
b/common/rusty_leveldb_sgx/src/options.rs
index d9ce94c..edd57d0 100644
--- a/common/rusty_leveldb_sgx/src/options.rs
+++ b/common/rusty_leveldb_sgx/src/options.rs
@@ -14,13 +14,7 @@ use crate::types::{share, Shared};
use std::rc::Rc;
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- use disk_env::DBPersistKey;
- } else {
- use std::default::Default;
- }
-}
+use disk_env::DBPersistKey;
const KB: usize = 1 << 10;
const MB: usize = KB * KB;
@@ -68,76 +62,48 @@ pub struct Options {
pub filter_policy: filter::BoxedFilterPolicy,
}
-cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- impl Options {
- pub fn new_disk_db_with(key: DBPersistKey) -> Options {
- Options {
- cmp: Rc::new(Box::new(DefaultCmp)),
- env:
Rc::new(Box::new(disk_env::PosixDiskEnv::new_with(key))),
- log: None,
- create_if_missing: true,
- error_if_exists: false,
- paranoid_checks: false,
- write_buffer_size: WRITE_BUFFER_SIZE,
- max_open_files: 1 << 10,
- max_file_size: 2 << 20,
- // 2000 elements by default
- block_cache: share(Cache::new(BLOCK_CACHE_CAPACITY /
BLOCK_MAX_SIZE)),
- block_size: BLOCK_MAX_SIZE,
- block_restart_interval: 16,
- reuse_logs: true,
- reuse_manifest: true,
- compression_type: CompressionType::CompressionNone,
- filter_policy:
Rc::new(Box::new(filter::BloomPolicy::new(DEFAULT_BITS_PER_KEY))),
- }
- }
-
- pub fn new_mem_db() -> Options {
- Options {
- cmp: Rc::new(Box::new(DefaultCmp)),
- env: Rc::new(Box::new(MemEnv::new())),
- log: None,
- create_if_missing: true,
- error_if_exists: false,
- paranoid_checks: false,
- write_buffer_size: WRITE_BUFFER_SIZE,
- max_open_files: 1 << 10,
- max_file_size: 2 << 20,
- // 2000 elements by default
- block_cache: share(Cache::new(BLOCK_CACHE_CAPACITY /
BLOCK_MAX_SIZE)),
- block_size: BLOCK_MAX_SIZE,
- block_restart_interval: 16,
- reuse_logs: true,
- reuse_manifest: true,
- compression_type: CompressionType::CompressionNone,
- filter_policy:
Rc::new(Box::new(filter::BloomPolicy::new(DEFAULT_BITS_PER_KEY))),
- }
- }
+impl Options {
+ pub fn new_disk_db_with(key: DBPersistKey) -> Options {
+ Options {
+ cmp: Rc::new(Box::new(DefaultCmp)),
+ env: Rc::new(Box::new(disk_env::PosixDiskEnv::new_with(key))),
+ log: None,
+ create_if_missing: true,
+ error_if_exists: false,
+ paranoid_checks: false,
+ write_buffer_size: WRITE_BUFFER_SIZE,
+ max_open_files: 1 << 10,
+ max_file_size: 2 << 20,
+ // 2000 elements by default
+ block_cache: share(Cache::new(BLOCK_CACHE_CAPACITY /
BLOCK_MAX_SIZE)),
+ block_size: BLOCK_MAX_SIZE,
+ block_restart_interval: 16,
+ reuse_logs: true,
+ reuse_manifest: true,
+ compression_type: CompressionType::CompressionNone,
+ filter_policy:
Rc::new(Box::new(filter::BloomPolicy::new(DEFAULT_BITS_PER_KEY))),
}
- } else {
- impl Default for Options {
- fn default() -> Options {
- Options {
- cmp: Rc::new(Box::new(DefaultCmp)),
- env: Rc::new(Box::new(MemEnv::new()));
- log: None,
- create_if_missing: true,
- error_if_exists: false,
- paranoid_checks: false,
- write_buffer_size: WRITE_BUFFER_SIZE,
- max_open_files: 1 << 10,
- max_file_size: 2 << 20,
- // 2000 elements by default
- block_cache: share(Cache::new(BLOCK_CACHE_CAPACITY /
BLOCK_MAX_SIZE)),
- block_size: BLOCK_MAX_SIZE,
- block_restart_interval: 16,
- reuse_logs: true,
- reuse_manifest: true,
- compression_type: CompressionType::CompressionNone,
- filter_policy:
Rc::new(Box::new(filter::BloomPolicy::new(DEFAULT_BITS_PER_KEY))),
- }
- }
+ }
+
+ pub fn new_mem_db() -> Options {
+ Options {
+ cmp: Rc::new(Box::new(DefaultCmp)),
+ env: Rc::new(Box::new(MemEnv::new())),
+ log: None,
+ create_if_missing: true,
+ error_if_exists: false,
+ paranoid_checks: false,
+ write_buffer_size: WRITE_BUFFER_SIZE,
+ max_open_files: 1 << 10,
+ max_file_size: 2 << 20,
+ // 2000 elements by default
+ block_cache: share(Cache::new(BLOCK_CACHE_CAPACITY /
BLOCK_MAX_SIZE)),
+ block_size: BLOCK_MAX_SIZE,
+ block_restart_interval: 16,
+ reuse_logs: true,
+ reuse_manifest: true,
+ compression_type: CompressionType::CompressionNone,
+ filter_policy:
Rc::new(Box::new(filter::BloomPolicy::new(DEFAULT_BITS_PER_KEY))),
}
}
}
@@ -145,27 +111,11 @@ cfg_if! {
/// Returns Options that will cause a database to exist purely in-memory
instead of being stored on
/// disk. This is useful for testing or ephemeral databases.
pub fn in_memory() -> Options {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- Options::new_mem_db()
- } else {
- let mut opt = Options::default();
- opt.env = Rc::new(Box::new(MemEnv::new()));
- opt
- }
- }
+ Options::new_mem_db()
}
pub fn for_test() -> Options {
- cfg_if! {
- if #[cfg(feature = "mesalock_sgx")] {
- let mut o = Options::new_mem_db();
- } else {
- let mut o = Options::default();
- o.env = Rc::new(Box::new(MemEnv::new()));
- }
- }
-
+ let mut o = Options::new_mem_db();
o.log = Some(share(infolog::stderr()));
o
}
diff --git a/tests/unit/enclave/Cargo.toml b/tests/unit/enclave/Cargo.toml
index 3bd06fe..74408c4 100644
--- a/tests/unit/enclave/Cargo.toml
+++ b/tests/unit/enclave/Cargo.toml
@@ -36,6 +36,8 @@ mesalock_sgx = [
"teaclave_scheduler_service_enclave/enclave_unit_test",
"teaclave_worker/mesalock_sgx",
"teaclave_worker/enclave_unit_test",
+ "rusty-leveldb/mesalock_sgx",
+ "rusty-leveldb/enclave_unit_test",
]
cov = ["teaclave_service_enclave_utils/cov"]
@@ -52,7 +54,8 @@ teaclave_execution_service_enclave = { path =
"../../../services/execution/encla
teaclave_management_service_enclave = { path =
"../../../services/management/enclave" }
teaclave_scheduler_service_enclave = { path =
"../../../services/scheduler/enclave" }
-teaclave_worker = { path = "../../../worker" }
+teaclave_worker = { path = "../../../worker" }
+rusty-leveldb = { path = "../../../common/rusty_leveldb_sgx",
default-features = false, optional = true }
teaclave_test_utils = { path = "../../utils" }
teaclave_attestation = { path = "../../../attestation" }
diff --git a/tests/unit/enclave/src/lib.rs b/tests/unit/enclave/src/lib.rs
index c498810..2323139 100644
--- a/tests/unit/enclave/src/lib.rs
+++ b/tests/unit/enclave/src/lib.rs
@@ -21,6 +21,7 @@ extern crate sgx_tstd as std;
use std::prelude::v1::*;
+use rusty_leveldb;
use teaclave_access_control_service_enclave;
use teaclave_authentication_service_enclave;
use teaclave_binder::proto::{
@@ -45,6 +46,7 @@ fn handle_run_test(_: &RunTestInput) ->
TeeServiceResult<RunTestOutput> {
teaclave_authentication_service_enclave::tests::run_tests(),
teaclave_worker::tests::run_tests(),
teaclave_types::tests::run_tests(),
+ rusty_leveldb::tests::run_tests(),
);
assert!(ret);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]