cov: fix Makefile and support llvm-cov-12
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 @@
.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
+#!/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=""
-#${LLVM_COV} gcov $*
-llvm-cov-11 gcov $*
+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} $*