Skip to content

Commit

Permalink
Add mono as a test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
khyperia committed Dec 14, 2017
1 parent 9866191 commit f611efc
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 19 deletions.
14 changes: 13 additions & 1 deletion build.sh
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -74,6 +76,10 @@ do
test_=true
shift 1
;;
--mono)
use_mono=true
shift 1
;;
--build-bootstrap)
build_bootstrap=true
shift 1
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions build/Targets/Tools.props
Expand Up @@ -5,5 +5,6 @@
<dotnetRuntimeVersion>2.0.0</dotnetRuntimeVersion>
<dotnetSdkVersion>2.2.0-preview1-007622</dotnetSdkVersion>
<nugetExeVersion>4.3.0</nugetExeVersion>
<monoVersion>5.8.0.88</monoVersion>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions 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
26 changes: 26 additions & 0 deletions 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
41 changes: 33 additions & 8 deletions build/scripts/tests.sh
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 )
Expand All @@ -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}
16 changes: 8 additions & 8 deletions netci.groovy
Expand Up @@ -99,30 +99,30 @@ 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")
}
}

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")
}
}

Expand Down
Expand Up @@ -492,7 +492,8 @@ class [mscorlib]System.Collections.Generic.IEnumerator`1<object>,
Assert.Equal(stateMachineClass, comp.GetTypeByMetadataName("C+<I<System.Int32>.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 =
Expand Down
Expand Up @@ -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 = @"
Expand Down

0 comments on commit f611efc

Please sign in to comment.