You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by di...@apache.org on 2020/12/30 00:23:42 UTC

[incubator-teaclave-sgx-sdk] branch fix-sgx-cov updated (4c40f35 -> 0156f09)

This is an automated email from the ASF dual-hosted git repository.

dingyu pushed a change to branch fix-sgx-cov
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git.


    from 4c40f35  Update readme. add gcov version requirement
     new 522fb65  temp fail cannot find final.info
     new 0156f09  cov: fix Makefile and support llvm-cov-12

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 samplecode/sgx-cov/Makefile           |  5 +--
 samplecode/sgx-cov/Readme.md          | 15 +++++++--
 samplecode/sgx-cov/enclave/llvm-gcov  | 57 +++++++++++++++++++++++++++++++++--
 samplecode/sgx-cov/enclave/src/lib.rs |  3 --
 sgx_cov/lib.rs                        | 18 ++++++-----
 5 files changed, 82 insertions(+), 16 deletions(-)


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


[incubator-teaclave-sgx-sdk] 02/02: cov: fix Makefile and support llvm-cov-12

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dingyu pushed a commit to branch fix-sgx-cov
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git

commit 0156f090b1ea282e4ff26a897ebcbd772050fdc7
Author: Yu Ding <di...@gmail.com>
AuthorDate: Tue Dec 29 16:23:11 2020 -0800

    cov: fix Makefile and support llvm-cov-12
---
 samplecode/sgx-cov/Makefile          |   7 +--
 samplecode/sgx-cov/Readme.md         |  15 ++++-
 samplecode/sgx-cov/enclave/llvm-gcov | 113 +++++++++++++++++------------------
 3 files changed, 71 insertions(+), 64 deletions(-)

diff --git a/samplecode/sgx-cov/Makefile b/samplecode/sgx-cov/Makefile
index 8d8e00d..81ee194 100644
--- a/samplecode/sgx-cov/Makefile
+++ b/samplecode/sgx-cov/Makefile
@@ -160,10 +160,9 @@ enclave:
 
 .PHONY: gen_cov_html
 gen_cov_html:
-	#lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
-	#lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
-	lcov --gcov-tool gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
-	lcov --gcov-tool gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
+	lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
+	lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
+	lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --extract all.tag.info `find "$$(cd enclave/src; pwd)" -name "*.rs"` -o final.info
 	genhtml --branch-coverage --demangle-cpp --legend ./final.info -o ./html/ --ignore-errors source
 
 .PHONY: clean
diff --git a/samplecode/sgx-cov/Readme.md b/samplecode/sgx-cov/Readme.md
index be4d101..005af3b 100644
--- a/samplecode/sgx-cov/Readme.md
+++ b/samplecode/sgx-cov/Readme.md
@@ -2,8 +2,19 @@
 
 Prerequisite:
 
-- lcov. Install via `sudo apt-get install lcov`
-- gcov <= 7. Install gcc `sudo apt-get install gcc`. If your platform canot install gcov <=7, you can use another platform to analyze the generated `gcno` and `gcda` files. Ubuntu 18.04 has gcc-7 by default.
+1. `lcov`. Install via `sudo apt-get install lcov`
+
+2. Either of `gcov <= 7`, or `llvm-cov >= 11`
+- `gcov <= 7`. Install gcc `sudo apt-get install gcc`.
+- `llvm-cov >= 11`. You can either install using apt/yum/dnf, or the official LLVM installation script:
+
+```
+wget https://apt.llvm.org/llvm.sh
+chmod +x llvm.sh
+sudo ./llvm.sh 11
+```
+
+If your platform cannot install either of them, you can use another platform to analyze the generated `gcno` and `gcda` files. Ubuntu 18.04 has gcc-7 by default, and can install llvm 11 using the above script.
 
 ## One shot
 
diff --git a/samplecode/sgx-cov/enclave/llvm-gcov b/samplecode/sgx-cov/enclave/llvm-gcov
index 647cae9..8fd1738 100755
--- a/samplecode/sgx-cov/enclave/llvm-gcov
+++ b/samplecode/sgx-cov/enclave/llvm-gcov
@@ -1,58 +1,55 @@
-#!/bin/sh -e
-##!/usr/bin/env bash
-
-#LLVM_COV=""
-#
-#verlte() {
-#    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
-#}
-#
-#verlt() {
-#    [ "$1" = "$2" ] && return 1 || verlte $1 $2
-#}
-#
-#check_llvm_cov() {
-#    if [ -z `which $1` ];
-#    then
-#        return
-#    else
-#        p=$(which $1)
-#        verinfo=`${p} --version`
-#        first_word=$(echo ${verinfo} | awk "{ print \$1 }")
-#        gcov_ver=$(echo ${verinfo} | awk "{ print \$4 }")
-#        llvm_cov_ver=$(echo ${verinfo} | awk "{ print \$5 }")
-#
-#        if [ "$first_word" = "gcov" ]; then
-#            echo "gcov detected, ver = " ${gcov_ver}
-#            verlt "${gcov_ver}" "8.0.0" && LLVM_COV=$1 || LLVM_COV=""
-#            return
-#        elif [ "$first_word" = "LLVM" ]; then
-#            echo "llvm-cov detected, ver = " ${llvm_cov_ver}
-#            verlte "11.0.0" "${gcov_ver}" && LLVM_COV=$1 || LLVM_COV=""
-#            return
-#        else
-#            echo "neither llvm-cov or gcov ... skipping"
-#            return
-#        fi
-#    fi
-#}
-#
-## search priority
-##for c in "llvm-cov-11" "gcov" "llvm-cov" "gcov-7"
-#for c in "gcov-7"
-#do
-#    check_llvm_cov $c
-#    if [[ ! -z "${LLVM_COV}" ]];
-#    then
-#        break
-#    fi
-#done
-#
-#if [[ -z "${LLVM_COV}" ]];
-#then
-#    echo "You need gcov < 8.0, or llvm-cov >= 11.0 to analyze Rust generated gcno/gcda files!"
-#    exit 1
-#fi
-
-#${LLVM_COV} gcov $*
-llvm-cov-11 gcov $*
+#!/usr/bin/env bash
+
+LLVM_COV=""
+
+verlte() {
+    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
+}
+
+verlt() {
+    [ "$1" = "$2" ] && return 1 || verlte $1 $2
+}
+
+check_llvm_cov() {
+    if [ -z `which $1` ];
+    then
+        return
+    else
+        p=$(which $1)
+        verinfo=`${p} --version`
+        first_word=$(echo ${verinfo} | awk "{ print \$1 }")
+        gcov_ver=$(echo ${verinfo} | awk "{ print \$4 }")
+        llvm_cov_ver=$(echo ${verinfo} | awk "{ print \$5 }")
+
+        if [ "$first_word" = "gcov" ]; then
+            echo "gcov detected, ver = " ${gcov_ver}
+            verlt "${gcov_ver}" "8.0.0" && LLVM_COV=$1 || LLVM_COV=""
+            return
+        elif [ "$first_word" = "LLVM" ]; then
+            echo "llvm-cov detected, ver = " ${llvm_cov_ver}
+            verlte "11.0.0" "${gcov_ver}" && LLVM_COV="$1 gcov" || LLVM_COV=""
+            return
+        else
+            echo "neither llvm-cov or gcov ... skipping"
+            return
+        fi
+    fi
+}
+
+# search priority
+for c in "llvm-cov-11" "gcov-7" "llvm-cov" "gcov"
+do
+    check_llvm_cov $c
+    if [[ ! -z "${LLVM_COV}" ]];
+    then
+        break
+    fi
+done
+
+if [[ -z "${LLVM_COV}" ]];
+then
+    echo "You need gcov < 8.0, or llvm-cov >= 11.0 to analyze Rust generated gcno/gcda files! See Readme.md for more details."
+    exit 1
+fi
+
+${LLVM_COV} $*


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


[incubator-teaclave-sgx-sdk] 01/02: temp fail cannot find final.info

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dingyu pushed a commit to branch fix-sgx-cov
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git

commit 522fb65f363d125d27e32b3e5efed8eff10a22f9
Author: Yu Ding <di...@gmail.com>
AuthorDate: Tue Dec 29 14:51:41 2020 -0800

    temp fail cannot find final.info
---
 samplecode/sgx-cov/Makefile           |  4 ++-
 samplecode/sgx-cov/enclave/llvm-gcov  | 58 ++++++++++++++++++++++++++++++++++-
 samplecode/sgx-cov/enclave/src/lib.rs |  3 --
 sgx_cov/lib.rs                        | 18 ++++++-----
 4 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/samplecode/sgx-cov/Makefile b/samplecode/sgx-cov/Makefile
index e5b9f63..8d8e00d 100644
--- a/samplecode/sgx-cov/Makefile
+++ b/samplecode/sgx-cov/Makefile
@@ -160,8 +160,10 @@ enclave:
 
 .PHONY: gen_cov_html
 gen_cov_html:
+	#lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
+	#lcov --gcov-tool $(PWD)/enclave/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
+	lcov --gcov-tool gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
 	lcov --gcov-tool gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory ${Target_Dir} -o ./all.tag.info
-	lcov --gcov-tool gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --extract all.tag.info `find "$$(cd enclave/src; pwd)" -name "*.rs"` -o final.info
 	genhtml --branch-coverage --demangle-cpp --legend ./final.info -o ./html/ --ignore-errors source
 
 .PHONY: clean
diff --git a/samplecode/sgx-cov/enclave/llvm-gcov b/samplecode/sgx-cov/enclave/llvm-gcov
index d5923e4..647cae9 100755
--- a/samplecode/sgx-cov/enclave/llvm-gcov
+++ b/samplecode/sgx-cov/enclave/llvm-gcov
@@ -1,2 +1,58 @@
 #!/bin/sh -e
-llvm-cov gcov $*
+##!/usr/bin/env bash
+
+#LLVM_COV=""
+#
+#verlte() {
+#    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
+#}
+#
+#verlt() {
+#    [ "$1" = "$2" ] && return 1 || verlte $1 $2
+#}
+#
+#check_llvm_cov() {
+#    if [ -z `which $1` ];
+#    then
+#        return
+#    else
+#        p=$(which $1)
+#        verinfo=`${p} --version`
+#        first_word=$(echo ${verinfo} | awk "{ print \$1 }")
+#        gcov_ver=$(echo ${verinfo} | awk "{ print \$4 }")
+#        llvm_cov_ver=$(echo ${verinfo} | awk "{ print \$5 }")
+#
+#        if [ "$first_word" = "gcov" ]; then
+#            echo "gcov detected, ver = " ${gcov_ver}
+#            verlt "${gcov_ver}" "8.0.0" && LLVM_COV=$1 || LLVM_COV=""
+#            return
+#        elif [ "$first_word" = "LLVM" ]; then
+#            echo "llvm-cov detected, ver = " ${llvm_cov_ver}
+#            verlte "11.0.0" "${gcov_ver}" && LLVM_COV=$1 || LLVM_COV=""
+#            return
+#        else
+#            echo "neither llvm-cov or gcov ... skipping"
+#            return
+#        fi
+#    fi
+#}
+#
+## search priority
+##for c in "llvm-cov-11" "gcov" "llvm-cov" "gcov-7"
+#for c in "gcov-7"
+#do
+#    check_llvm_cov $c
+#    if [[ ! -z "${LLVM_COV}" ]];
+#    then
+#        break
+#    fi
+#done
+#
+#if [[ -z "${LLVM_COV}" ]];
+#then
+#    echo "You need gcov < 8.0, or llvm-cov >= 11.0 to analyze Rust generated gcno/gcda files!"
+#    exit 1
+#fi
+
+#${LLVM_COV} gcov $*
+llvm-cov-11 gcov $*
diff --git a/samplecode/sgx-cov/enclave/src/lib.rs b/samplecode/sgx-cov/enclave/src/lib.rs
index 5af1431..420a505 100644
--- a/samplecode/sgx-cov/enclave/src/lib.rs
+++ b/samplecode/sgx-cov/enclave/src/lib.rs
@@ -99,8 +99,5 @@ pub extern "C" fn say_something(some_string: *const u8, some_len: usize) -> sgx_
     // Ocall to normal world for output
     println!("{}", &hello_string);
 
-    #[cfg(feature = "cov")]
-    sgx_cov::cov_writeout();
-
     sgx_status_t::SGX_SUCCESS
 }
diff --git a/sgx_cov/lib.rs b/sgx_cov/lib.rs
index 5a21b51..fdf19f3 100644
--- a/sgx_cov/lib.rs
+++ b/sgx_cov/lib.rs
@@ -52,7 +52,7 @@ const GCOV_TAG_OBJECT_SUMMARY: u32 = 0xa100_0000;
 const GCOV_TAG_PROGRAM_SUMMARY: u32 = 0xa300_0000;
 
 lazy_static! {
-    static ref GCDA_FILE: SgxMutex<(c_int, c_int)> = SgxMutex::new((-1, -1));
+    static ref GCDA_FILE: SgxMutex<(c_int, u32)> = SgxMutex::new((-1, u32::MAX));
     static ref WROUT_FNS: SgxMutex<Vec<extern "C" fn()>> = SgxMutex::new(Vec::new());
     static ref RND: SgxMutex<u32> = SgxMutex::new(0);
 }
@@ -188,21 +188,25 @@ pub extern "C" fn llvm_gcda_start_file(orig_filename: *const c_char, version: u3
                 Err(_) => File::create(&new_gcda_name)?,
             };
 
+            println!("opened file {}", new_gcda_name);
+
             let c3: u8 = ((version >> 24) & 0x000000FF) as u8;
             let c2: u8 = ((version >> 16) & 0x000000FF) as u8;
             let c1: u8 = ((version >> 8) & 0x000000FF) as u8;
-            let parsed_gcov_version: i32 = if c3 >= 'A' as u8 {
-                ((c3 - 'A' as u8) as i32) * 100
-                    + ((c2 - '0' as u8) as i32) * 10
-                    + (c1 - '0' as u8) as i32
+            let parsed_gcov_version: u32 = if c3 >= 'A' as u8 {
+                ((c3 - 'A' as u8) as u32) * 100
+                    + ((c2 - '0' as u8) as u32) * 10
+                    + (c1 - '0' as u8) as u32
             } else {
-                ((c3 - '0' as u8) as i32) * 10 + (c1 - '0' as u8) as i32
+                ((c3 - '0' as u8) as u32) * 10 + (c1 - '0' as u8) as u32
             };
+            println!("parsed_gcov_version = {}", parsed_gcov_version);
+            println!("parsed_gcov_version = {:?}", &parsed_gcov_version.to_le_bytes());
 
             tup.1 = parsed_gcov_version;
 
             file.write_all(&GCOV_DATA_MAGIC.to_le_bytes()).unwrap();
-            file.write_all(&parsed_gcov_version.to_le_bytes()).unwrap();
+            file.write_all(&version.to_le_bytes()).unwrap();
             file.write_all(&checksum.to_le_bytes()).unwrap();
 
             tup.0 = file.into_raw_fd();


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