forked from Samsung/TizenFX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·133 lines (110 loc) · 3.23 KB
/
coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash -e
SCRIPT_DIR=$(dirname $(readlink -f $0))
ROOTDIR=$SCRIPT_DIR
BUILD_CONF=Debug
SLN_NAME=_TizenFX_Cov
SLN_FILE=$ROOTDIR/$SLN_NAME.sln
COV_TOOL_PATH=$ROOTDIR/tools/coverage
COV_REPORT_PATH=$ROOTDIR/Artifacts/coverage
MINICOVER_PATH=$COV_TOOL_PATH/coverage/minicover_linux
TARGET_ASSEMBLY_PATH=/usr/share/dotnet.tizen/framework
TARGET_COV_PATH=/home/owner/share/cov
usage() {
echo "Usage: $0 [command] [module] [exclude-sources]"
echo "Commands:"
echo " instrument|--instrument|-i : Instrument assemblies to record code coverage."
echo " replace |--replace |-c : Replace runtime assemblies with intrumented."
echo " report|--report|-r : Generate report files."
}
check_module() {
if [ -z "$1" ]; then
echo "No module specified." 1>&2
exit 1
fi
local PROJECT_DIR=$ROOTDIR/src/$1
if [ ! -f $PROJECT_DIR/$1.csproj ]; then
echo "No such found $1 module." 1>&2
exit 1
fi
echo $PROJECT_DIR
}
update_coverage_tools() {
echo "## Update Coverage Tools ##"
if [ -d $COV_TOOL_PATH ]; then
pushd $COV_TOOL_PATH > /dev/null
git fetch origin
git reset --hard origin/master
popd > /dev/null
else
git clone https://github.sec.samsung.net/RS8-DotNetTctTools/CSharpCoverageTool $COV_TOOL_PATH
fi
}
public_modules() {
find $ROOTDIR/src -maxdepth 1 \
-type d ! -name "*.Design" \
-not -path $ROOTDIR/src | sort | sed "s:$ROOTDIR/src/::"
}
build() {
PROJECT_DIR=$(check_module $1)
dotnet build -c $BUILD_CONF $PROJECT_DIR/$1.csproj
}
instrument() {
PROJECT_DIR=$(check_module $1)
dotnet $MINICOVER_PATH/dotnet-minicover.dll instrument \
--workdir $ROOTDIR \
--sources "/src/$1/**/*.cs" \
--exclude-sources "$2" \
--assemblies "/src/$1/bin/$BUILD_CONF/*/$1.dll" \
--hits-file $1
}
prepare_replace() {
sdb root on
sdb shell mount -o remount,rw /
sdb shell "rm -f $TARGET_ASSEMBLY_PATH/*.ni.dll"
sdb shell "rm -fr $TARGET_COV_PATH"
sdb shell "mkdir -p $TARGET_COV_PATH"
sdb push $MINICOVER_PATH/MiniCover.HitServices.dll $TARGET_ASSEMBLY_PATH
sdb shell chsmack -a '_' $TARGET_ASSEMBLY_PATH/MiniCover.HitServices.dll
}
replace() {
PROJECT_DIR=$(check_module $1)
sdb push $PROJECT_DIR/bin/$BUILD_CONF/*/$1.dll $TARGET_ASSEMBLY_PATH
sdb shell chsmack -a '_' $TARGET_ASSEMBLY_PATH/$1.dll
}
prepare_report() {
rm -fr $COV_REPORT_PATH
mkdir -p $COV_REPORT_PATH
sdb pull $TARGET_COV_PATH
}
report() {
set +e
PROJECT_DIR=$(check_module $1)
dotnet $MINICOVER_PATH/dotnet-minicover.dll xmlreport \
--threshold 85 --output $1.xml
dotnet $COV_TOOL_PATH/coverage/ReportGenerator_4.8.0/netcoreapp2.0/ReportGenerator.dll \
-reporttypes:lcov -reports:$1.xml -targetdir:$COV_REPORT_PATH/$1
java -jar $COV_TOOL_PATH/coverage/jgenhtml-1.5.jar \
$COV_REPORT_PATH/$1/lcov.info -o $COV_REPORT_PATH/$1 --no-branch-coverage
rm -f $1.xml
rm -f $1*.hits
}
cmd_instrument() {
build $1
instrument $1 $2
}
cmd_replace() {
prepare_replace
replace $1
}
cmd_report() {
prepare_report
report $1
}
update_coverage_tools
cmd=$1; [ $# -gt 0 ] && shift;
case "$cmd" in
instrument|--instrument|-i) cmd_instrument $@ ;;
replace |--replace |-c) cmd_replace $@ ;;
report|--report| -r) cmd_report $@ ;;
*) usage ;;
esac