From 29d03ffb08e3cace78e10101cda2257567fa7f49 Mon Sep 17 00:00:00 2001 From: shahasad <43590019+shahasad@users.noreply.github.com> Date: Thu, 27 Dec 2018 15:22:46 -0800 Subject: [PATCH] Add end-to-end test to run on the nuget package (#252) * added end-to-end nuget package test * reset the changes in OnnxRuntime.CSharp.proj * revert the testdata directory path * revert inference tests proj file * added script for running end-to-end tests * fix in the runtest.bat * added error checking in runtest * fixed paths in the test project * added runtest.sh * fix protoc path * updated executable attributes for the runtest scripts * added some log to debug protoc failures * removed the protoc and duplicate test code, reuse unit-test code for end-to-end test * copy always * fix working dir paths in runtest.sh * added a build.py flag to download test data without running the c++ tests * added a script for running the test under docker * added script for docker run of the test --- .../Microsoft.ML.OnnxRuntime.csproj | 6 +-- ...rosoft.ML.OnnxRuntime.EndToEndTests.csproj | 44 +++++++++++++++++++ .../runtest-docker.sh | 29 ++++++++++++ .../runtest.bat | 29 ++++++++++++ .../runtest.sh | 29 ++++++++++++ tools/ci_build/build.py | 4 +- 6 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj create mode 100755 csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest-docker.sh create mode 100755 csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.bat create mode 100755 csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj index ec902c4674..6ab1eba4b6 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj @@ -32,15 +32,15 @@ + + + netcoreapp2.0 + false + $(MSBuildThisFileDirectory)..\.. + AnyCPU + bin\$(Configuration)\ + $(OnnxRuntimeCsharpRoot)\..\build\Windows + $(buildDirectory)\$(Configuration)\external\protobuf\cmake\$(Configuration) + $(OnnxRuntimeCsharpRoot)\..\cmake\external\onnx\onnx + $(buildDirectory)\$(Configuration)\$(Configuration) + + + + + + + + + + + + + + + + + Always + false + + + + Always + false + + + + + + + + + diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest-docker.sh b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest-docker.sh new file mode 100755 index 0000000000..395f2fa60e --- /dev/null +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest-docker.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# build docker image for CPU + +#TODO: Get this working, not tested yet + +SOURCE_ROOT=$1 +NUGET_REPO_DIRNAME=$2 # path relative to BUILD_DIR +IMAGE="ubuntu16.04" +PYTHON_VER=3.5 +OldDir=$(pwd) +cd $SOURCE_ROOT/tools/ci_build/github/linux/docker +docker build -t "onnxruntime-$IMAGE" --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=${PYTHON_VER} -f Dockerfile.ubuntu . + + +docker rm -f "onnxruntime-cpu" || true +docker run -h $HOSTNAME \ + --rm \ + --name "onnxruntime-cpu" \ + --volume "$SOURCE_ROOT:/onnxruntime_src" \ + --volume "$BUILD_DIR:/home/onnxruntimedev" \ + --volume "$HOME/.cache/onnxruntime:/root/.cache/onnxruntime" \ + "onnxruntime-$IMAGE" \ + /bin/bash /onnxruntime_src/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh \ + /home/onnxruntimedev/$NUGET_REPO_DIRNAME /onnxruntime_src & + +cd $OldDir \ No newline at end of file diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.bat b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.bat new file mode 100755 index 0000000000..c72da295d3 --- /dev/null +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.bat @@ -0,0 +1,29 @@ +REM Copyright (c) Microsoft Corporation. All rights reserved. +REM Licensed under the MIT License. + +@echo off +SETLOCAL EnableDelayedExpansion + +set LocalNuGetRepo=%1 +REM WorkingDirectory is Build.SourcesDirectory\csharp +set /p MajorVersionNumber=<..\VERSION_NUMBER +set VersionSuffix= +IF NOT DEFINED IsReleaseBuild ( + FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse --short HEAD`) DO ( + set VersionSuffix=-dev-%%F + ) +) + +set CurrentOnnxRuntimeVersion=%MajorVersionNumber%%VersionSuffix% +@echo %CurrentOnnxRuntimeVersion% +dotnet restore test\Microsoft.ML.OnnxRuntime.EndToEndTests\Microsoft.ML.OnnxRuntime.EndToEndTests.csproj -s %LocalNuGetRepo% --configfile .\Nuget.CSharp.config +if NOT errorlevel 0 ( + @echo "Failed to restore nuget packages for the test project" + Exit 1 +) + +dotnet test test\Microsoft.ML.OnnxRuntime.EndToEndTests\Microsoft.ML.OnnxRuntime.EndToEndTests.csproj --no-restore +if NOT errorlevel 0 ( + @echo "Failed to build or execute the end-to-end test" + Exit 1 +) \ No newline at end of file diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh new file mode 100755 index 0000000000..729da87afc --- /dev/null +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +LocalNuGetRepo=$1 +SourceRoot=$2 + +@echo "Downloading test data" +python build.by --update --download_test_data + +MajorVersion=$(cat $SourceRoot/VERSION_NUMBER) +VersionSuffix= +if [ "$IsReleaseBuild" != "true" ]; then + VersionSuffix = -dev-$(git rev-parse --short HEAD) +fi +export CurrentOnnxRuntimeVersion=$MajorVersion$VersionSuffix +echo "Current NuGet package version is $CurrentOnnxRuntimeVersion" + +dotnet restore $SourceRoot/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj -s $LocalNuGetRepo --configfile $SourceRoot/csharp/Nuget.CSharp.config +if [ $? -ne 0 ] + echo "Failed to restore nuget packages for the test project" + exit 1 +) + +dotnet test $SourceRoot/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/Microsoft.ML.OnnxRuntime.EndToEndTests.csproj --no-restore +if [ $? -ne 0 ] + echo "Failed to build or execute the end-to-end test" + exit 1 +) \ No newline at end of file diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 870c5295e0..7fbbd8447c 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -58,6 +58,8 @@ Use the individual flags to only run the specified stages. parser.add_argument("--enable_onnx_tests", action='store_true', help='''When running the Test phase, run onnx_test_running against available test data directories.''') parser.add_argument("--pb_home", help="Path to protobuf installation") + parser.add_argument("--download_test_data", action="store_true", + help='''Downloads test data without running the tests''') # CUDA related parser.add_argument("--use_cuda", action='store_true', help="Enable CUDA.") parser.add_argument("--cuda_home", help="Path to CUDA home." @@ -237,7 +239,7 @@ def download_test_data(build_dir, src_url, expected_md5, azure_sas_key): def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home, pb_home, configs, cmake_extra_defines, args, cmake_extra_args): has_test_data = False - if args.enable_onnx_tests: + if args.enable_onnx_tests or args.download_test_data: has_test_data = download_test_data(build_dir, test_data_url, test_data_checksum, args.azure_sas_key) #create a shortcut for test models if there is a 'models' folder in build_dir if has_test_data and is_windows():