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:43 UTC

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

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