]> git.lizzy.rs Git - rust.git/commitdiff
LVI test std lib
authorRaoul Strackx <raoul.strackx@fortanix.com>
Thu, 26 Mar 2020 09:51:14 +0000 (10:51 +0100)
committerRaoul Strackx <raoul.strackx@fortanix.com>
Fri, 25 Sep 2020 13:02:14 +0000 (15:02 +0200)
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave.rs [deleted file]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/Cargo.toml [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/src/main.rs [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/print.checks [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh [new file with mode: 0644]

index b17f9a12a29389003a48b94d006500d83262ecb1..6a04d343910357dcf494cca7326f6a997fbef048 100644 (file)
@@ -2,16 +2,22 @@
 
 #only-x86_64-fortanix-unknown-sgx
 
-OBJDUMP="${S}/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-objdump"
-FILECHECK="${S}/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck"
+# For cargo setting
+export RUSTC := $(RUSTC_ORIGINAL)
+export LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
+# We need to be outside of 'src' dir in order to run cargo
+export WORK_DIR := $(TMPDIR)
+export TEST_DIR := $(shell pwd)
 
-all:
-       $(RUSTC) --target ${TARGET} enclave.rs
-
-       #TODO: re-enable check when newly compiled libunwind is used
-       #${OBJDUMP} --disassemble-symbols=unw_getcontext --demangle $(TMPDIR)/enclave > $(TMPDIR)/unw_getcontext.asm
-       #${FILECHECK} --input-file $(TMPDIR)/unw_getcontext.asm unw_getcontext.checks
+## clean up unused env variables which might cause harm.
+unexport RUSTC_LINKER
+unexport RUSTC_BOOTSTRAP
+unexport RUST_BUILD_STAGE
+unexport RUST_TEST_THREADS
+unexport RUST_TEST_TMPDIR
+unexport AR
+unexport CC
+unexport CXX
 
-       #TODO: re-enable check when newly compiled libunwind is used
-       ${OBJDUMP} --disassemble-symbols="libunwind::Registers_x86_64::jumpto()" --demangle $(TMPDIR)/enclave > $(TMPDIR)/jumpto.asm
-       ${FILECHECK} --input-file $(TMPDIR)/jumpto.asm jumpto.checks
+all:
+       bash script.sh
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave.rs b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave.rs
deleted file mode 100644 (file)
index 66c8ead..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-pub fn main() {
-    println!("Hello, World!");
-}
-
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/Cargo.toml b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/Cargo.toml
new file mode 100644 (file)
index 0000000..723cd7c
--- /dev/null
@@ -0,0 +1,9 @@
+[package]
+name = "enclave"
+version = "0.1.0"
+authors = ["Raoul Strackx <raoul.strackx@fortanix.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/src/main.rs b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/src/main.rs
new file mode 100644 (file)
index 0000000..e7a11a9
--- /dev/null
@@ -0,0 +1,3 @@
+fn main() {
+    println!("Hello, world!");
+}
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/print.checks b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/print.checks
new file mode 100644 (file)
index 0000000..0fe8814
--- /dev/null
@@ -0,0 +1,7 @@
+CHECK: print
+CHECK:      lfence
+CHECK:      lfence
+CHECK:      lfence
+CHECK:      popq
+CHECK:      callq 0x{{[[:xdigit:]]*}} <_Unwind_Resume>
+CHECK-NEXT: ud2
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh
new file mode 100644 (file)
index 0000000..98e5284
--- /dev/null
@@ -0,0 +1,42 @@
+set -exuo pipefail
+
+function build {
+    CRATE=enclave
+
+    mkdir -p $WORK_DIR
+    pushd $WORK_DIR
+        rm -rf $CRATE
+        cp -a $TEST_DIR/enclave .
+        pushd $CRATE
+            echo ${WORK_DIR}
+            # HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
+            # These come from the top-level Rust workspace, that this crate is not a
+            # member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
+            env RUSTC_BOOTSTRAP=1  \
+                cargo -v run --target $TARGET
+            env RUSTC_BOOTSTRAP=1  \
+                cargo -v run --target $TARGET --release 
+        popd
+    popd
+}
+
+function check {
+    local func=$1
+    local checks="${TEST_DIR}/$2"
+    local asm=$(mktemp)
+    local objdump="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-objdump"
+    local filecheck="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck"
+    
+    ${objdump} --disassemble-symbols=${func} --demangle ${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave > ${asm}
+    ${filecheck} --input-file ${asm} ${checks}
+}
+
+build
+
+#TODO: re-enable check when newly compiled libunwind is used
+#check unw_getcontext unw_getcontext.checks
+
+#TODO: re-enable check when newly compiled libunwind is used
+#check "libunwind::Registers_x86_64::jumpto()" jumpto.checks
+
+check "std::io::stdio::_print::h87f0c238421c45bc" print.checks