From f611efcf682a96f42ff4680b962e563b9d043421 Mon Sep 17 00:00:00 2001 From: Ashley Hauck Date: Thu, 14 Dec 2017 11:03:35 -0800 Subject: [PATCH] Add mono as a test runner --- build.sh | 14 ++++++- build/Targets/Tools.props | 1 + build/scripts/build_mono.sh | 16 ++++++++ build/scripts/obtain_mono.sh | 26 ++++++++++++ build/scripts/tests.sh | 41 +++++++++++++++---- netci.groovy | 16 ++++---- .../Symbols/Metadata/MetadataTypeTests.cs | 3 +- .../Symbols/Metadata/PE/LoadingAttributes.cs | 3 +- 8 files changed, 101 insertions(+), 19 deletions(-) create mode 100755 build/scripts/build_mono.sh create mode 100755 build/scripts/obtain_mono.sh diff --git a/build.sh b/build.sh index e827a9d5ccb10..2ad7f2ba8873b 100755 --- a/build.sh +++ b/build.sh @@ -16,6 +16,7 @@ usage() echo " --restore Restore projects required to build" echo " --build Build all projects" echo " --test Run unit tests" + echo " --mono Run unit tests with mono" echo " --build-bootstrap Build the bootstrap compilers" echo " --use-bootstrap Use the built bootstrap compilers when running main build" echo " --bootstrap Implies --build-bootstrap and --use-bootstrap" @@ -30,6 +31,7 @@ build_configuration=Debug restore=false build=false test_=false +use_mono=false build_bootstrap=false use_bootstrap=false stop_vbcscompiler=false @@ -74,6 +76,10 @@ do test_=true shift 1 ;; + --mono) + use_mono=true + shift 1 + ;; --build-bootstrap) build_bootstrap=true shift 1 @@ -149,5 +155,11 @@ fi if [[ "${test_}" == true ]] then - "${root_path}"/build/scripts/tests.sh "${build_configuration}" + if [[ "${use_mono}" == true ]] + then + test_runtime=mono + else + test_runtime=dotnet + fi + "${root_path}"/build/scripts/tests.sh "${build_configuration}" "${test_runtime}" fi diff --git a/build/Targets/Tools.props b/build/Targets/Tools.props index 316367aa054a5..f0a91fd189bf3 100644 --- a/build/Targets/Tools.props +++ b/build/Targets/Tools.props @@ -5,5 +5,6 @@ 2.0.0 2.2.0-preview1-007622 4.3.0 + 5.8.0.88 diff --git a/build/scripts/build_mono.sh b/build/scripts/build_mono.sh new file mode 100755 index 0000000000000..8d4a23f7b4efd --- /dev/null +++ b/build/scripts/build_mono.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +mkdir -p ../../Binaries/mono_build +cd ../../Binaries/mono_build + +sudo apt-get install git autoconf libtool automake build-essential mono-devel gettext cmake + +PREFIX=$PWD/mono +VERSION=5.8.0.88 +curl https://download.mono-project.com/sources/mono/mono-${VERSION}.tar.bz2 | tar xj +pushd mono-$VERSION +./configure --prefix=$PREFIX +make +make install +popd +tar czf mono-${VERSION}.tar.gz mono diff --git a/build/scripts/obtain_mono.sh b/build/scripts/obtain_mono.sh new file mode 100755 index 0000000000000..76c76090ac1fd --- /dev/null +++ b/build/scripts/obtain_mono.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +# Source this script to ensure mono is installed and on the path. + +# This is a function to keep variable assignments out of the parent script (that is sourcing this file) +install_mono () { + # Download and install `mono` locally + local THIS_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "${THIS_DIR}"/build-utils.sh + + local MONO_VERSION="$(get_tool_version mono)" + # the tar file has `mono` as the root directory + local MONO_PATH="${THIS_DIR}"/../../Binaries/Tools + + if [[ ! -x "${MONO_PATH}/mono/bin/mono" ]] + then + echo "Downloading mono ${MONO_VERSION}" + mkdir -p "${MONO_PATH}" + curl -L https://roslyninfra.blob.core.windows.net/jenkins/mono/mono-${MONO_VERSION}.tar.gz | tar xz -C "${MONO_PATH}" + fi + + export PATH="${MONO_PATH}/mono/bin:${PATH}" +} +install_mono diff --git a/build/scripts/tests.sh b/build/scripts/tests.sh index 9dc645094b1d5..1e4e595d6e0ed 100755 --- a/build/scripts/tests.sh +++ b/build/scripts/tests.sh @@ -6,6 +6,7 @@ set -e set -u build_configuration=${1:-Debug} +runtime=${2:-dotnet} this_dir="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${this_dir}"/build-utils.sh @@ -15,9 +16,19 @@ binaries_path="${root_path}"/Binaries unittest_dir="${binaries_path}"/"${build_configuration}"/UnitTests log_dir="${binaries_path}"/"${build_configuration}"/xUnitResults nuget_dir="${HOME}"/.nuget/packages -target_framework=netcoreapp2.0 xunit_console_version="$(get_package_version dotnet-xunit)" -xunit_console="${nuget_dir}"/dotnet-xunit/"${xunit_console_version}"/tools/"${target_framework}"/xunit.console.dll + +if [[ "${runtime}" == "dotnet" ]]; then + target_framework=netcoreapp2.0 + xunit_console="${nuget_dir}"/dotnet-xunit/"${xunit_console_version}"/tools/${target_framework}/xunit.console.dll +elif [[ "${runtime}" == "mono" ]]; then + source ${root_path}/build/scripts/obtain_mono.sh + target_framework=net461 + xunit_console="${nuget_dir}"/dotnet-xunit/"${xunit_console_version}"/tools/net452/xunit.console.exe +else + echo "Unknown runtime: ${runtime}" + exit 1 +fi UNAME="$(uname)" if [ "$UNAME" == "Darwin" ]; then @@ -37,6 +48,7 @@ echo "Using ${xunit_console}" # Discover and run the tests mkdir -p "${log_dir}" +exit_code=0 for test_path in "${unittest_dir}"/*/"${target_framework}" do file_name=( "${test_path}"/*.UnitTests.dll ) @@ -45,17 +57,30 @@ do runtimeconfig_json="${file_name%.*}".runtimeconfig.json # If the user specifies a test on the command line, only run that one - # "${2:-}" => take second arg, empty string if unset - if [[ ("${2:-}" != "") && (! "${file_name}" =~ "${2:-}") ]] + # "${3:-}" => take second arg, empty string if unset + if [[ ("${3:-}" != "") && (! "${file_name}" =~ "${2:-}") ]] then echo "Skipping ${file_name}" continue fi echo Running "${file_name[@]}" - dotnet exec --depsfile "${deps_json}" --runtimeconfig "${runtimeconfig_json}" "${xunit_console}" "${file_name[@]}" -xml "${log_file}" - if [[ $? -ne 0 ]]; then - echo Unit test failed - exit 1 + if [[ "${runtime}" == "dotnet" ]]; then + runner="dotnet exec --depsfile ${deps_json} --runtimeconfig ${runtimeconfig_json}" + elif [[ "${runtime}" == "mono" ]]; then + runner=mono + if [[ "${file_name[@]}" == *'Microsoft.CodeAnalysis.CSharp.Scripting.UnitTests.dll' || "${file_name[@]}" == *'Roslyn.Compilers.CompilerServer.UnitTests.dll' ]] + then + echo "Skipping ${file_name[@]}" + continue + fi + fi + if ${runner} "${xunit_console}" "${file_name[@]}" -xml "${log_file}" + then + echo "Assembly ${file_name[@]} passed" + else + echo "Assembly ${file_name[@]} failed" + exit_code=1 fi done +exit ${exit_code} diff --git a/netci.groovy b/netci.groovy index 4deb5c6fba43f..4918d4f012ba5 100644 --- a/netci.groovy +++ b/netci.groovy @@ -99,11 +99,11 @@ commitPullList.each { isPr -> } } -// Ubuntu 14.04 +// Ubuntu 16.04 commitPullList.each { isPr -> - def jobName = Utilities.getFullJobName(projectName, "ubuntu_14_debug", isPr) + def jobName = Utilities.getFullJobName(projectName, "ubuntu_16_debug", isPr) def myJob = job(jobName) { - description("Ubuntu 14.04 tests") + description("Ubuntu 16.04 tests") steps { shell("./build/scripts/cibuild.sh --debug") } @@ -111,18 +111,18 @@ commitPullList.each { isPr -> def triggerPhraseOnly = false def triggerPhraseExtra = "linux" - Utilities.setMachineAffinity(myJob, 'Ubuntu14.04', 'latest-or-auto') + Utilities.setMachineAffinity(myJob, 'Ubuntu16.04', 'latest-or-auto') Utilities.addXUnitDotNETResults(myJob, '**/xUnitResults/*.xml') addRoslynJob(myJob, jobName, branchName, isPr, triggerPhraseExtra, triggerPhraseOnly) } -// Ubuntu 16.04 +// Ubuntu 16.04 mono commitPullList.each { isPr -> - def jobName = Utilities.getFullJobName(projectName, "ubuntu_16_debug", isPr) + def jobName = Utilities.getFullJobName(projectName, "ubuntu_16_mono_debug", isPr) def myJob = job(jobName) { - description("Ubuntu 16.04 tests") + description("Ubuntu 16.04 mono tests") steps { - shell("./build/scripts/cibuild.sh --debug") + shell("./build/scripts/cibuild.sh --debug --mono") } } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataTypeTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataTypeTests.cs index 82b876e575e7e..6187d1e771478 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataTypeTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataTypeTests.cs @@ -492,7 +492,8 @@ class [mscorlib]System.Collections.Generic.IEnumerator`1, Assert.Equal(stateMachineClass, comp.GetTypeByMetadataName("C+.F>d__0")); // GetTypeByMetadataName works. } - [Fact] + [ConditionalFact(typeof(ClrOnly))] + [WorkItem(23761, "https://github.com/dotnet/roslyn/issues/23761")] // reason for skipping mono public void EmptyNamespaceNames() { var ilSource = diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs index 948272034db49..1b328dd1b5a65 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs @@ -1316,8 +1316,9 @@ public void M1(decimal d1 = -7) }); } - [Fact] + [ConditionalFact(typeof(ClrOnly))] [WorkItem(530209, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530209")] + [WorkItem(23760, "https://github.com/dotnet/roslyn/issues/23760")] // reason for skipping Mono public void Bug530209_DecimalConstant_FromIL() { var ilSource = @"