For running tests after build has succeed you need to add option `-DCMAKE_INSTALL_PREFIX=$PWD/../bin`.
+To enable the Source-based code coverage feature (https://clang.llvm.org/docs/SourceBasedCodeCoverage.html)
+add `-DCLR_CMAKE_ENABLE_CODE_COVERAGE` option.
+
If you have previously downloaded .NET SDK or CoreCLR sources, then you should modify command line and add following options: `-DDOTNET_DIR=/path/to/sdk/dir -DCORECLR_DIR=/path/to/coreclr/sources`
If cmake tries to download .NET SDK or CoreCLR sources and fails -- see bullets 6 and 7 above. You can download required files manually.
You can find detailed instruction how to run tests in `test-suite` directory, see [test-suite/README.md](test-suite/README.md).
Basically you just need to build and install Netcoredbg into `bin` directory (in Netcoredbg source tree) and then change directory to `test-suite` and run script `/run_tests.sh`
+If you wish to get "Source-based code coverage" report, you can add an -c or --coverage option to the command line, i.e.:
+`./run_tests.sh -c [[testname1][testname2]..]`
+Note, for that case your build configuration should be done with `-DCLR_CMAKE_ENABLE_CODE_COVERAGE` option (see above). This feature is currently supported on Unix-like platforms only.
+
### Building and running unit tests
message( WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
endif(NOT UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
- add_compile_options(-fprofile-arcs)
- add_compile_options(-ftest-coverage)
+ add_compile_options(--coverage)
set(CLANG_COVERAGE_LINK_FLAGS "--coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CLANG_COVERAGE_LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CLANG_COVERAGE_LINK_FLAGS}")
local xml_path=$1
local testnames=$2
- echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
- <testsuites>
- <testsuite name=\"Tests\" tests=\"\" failures=\"\" errors=\"\" time=\"\">
- ${testnames}
- </testsuite>
- </testsuites>" > "${xml_path}/test-results.xml"
+ echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+ <testsuites>
+ <testsuite name=\"Tests\" tests=\"$(($test_pass + $test_fail))\" failures=\"$test_fail\" errors=\"0\" time=\"\">
+${testnames} </testsuite>
+ </testsuites>" > "${xml_path}/test-results.xml"
}
ALL_TEST_NAMES=(
generate_report=true
shift
;;
+ -c|--coverage)
+ code_coverage_report=true
+ shift
+ ;;
*)
TEST_NAMES="$TEST_NAMES *"
;;
NETCOREDBG="../bin/netcoredbg"
fi
+if [[ -z $OBJS_DIR ]]; then
+ OBJS_DIR="../build/src/CMakeFiles/netcoredbg.dir/"
+fi
+
if [[ -z $TEST_NAMES ]]; then
TEST_NAMES="${ALL_TEST_NAMES[@]}"
+ # delete all accumulated coverage data
+ find $OBJS_DIR -name '*.gcda' -delete
fi
dotnet build TestRunner || exit $?
if [ "$res" -ne "0" ]; then
test_fail=$(($test_fail + 1))
test_list="$test_list$TEST_NAME ... failed res=$res\n"
- test_xml+="<testcase name=\"$TEST_NAME\"><failure></failure></testcase>"
+ test_xml+=" <testcase name=\"$TEST_NAME\"><failure></failure></testcase>\n"
else
test_pass=$(($test_pass + 1))
test_list="$test_list$TEST_NAME ... passed\n"
- test_xml+="<testcase name=\"$TEST_NAME\"></testcase>"
+ test_xml+=" <testcase name=\"$TEST_NAME\"></testcase>\n"
fi
done
+if [[ $code_coverage_report == true ]]; then
+ lcov --capture --derive-func-data --gcov-tool $PWD/llvm-gcov.sh --directory $OBJS_DIR --output-file coverage.info
+ cd ..
+ lcov --remove test-suite/coverage.info $PWD/'.coreclr/*' $PWD/'build/*' '/usr/*' $PWD/'third_party/*' -o coverage.info
+ genhtml -o ./cov_html coverage.info
+ zip -r coverage.zip cov_html/ coverage.info
+ cd -
+fi
+
if [[ $generate_report == true ]]; then
#Generate xml test file to current directory
generate_xml "${XML_ABS_PATH}" "${test_xml}"
+ zip test.zip test-results.xml
fi
echo ""