From 281933fa1c487f29817cc5f05978319b8ffd4ab7 Mon Sep 17 00:00:00 2001 From: Ashwini Khade Date: Wed, 4 Dec 2019 18:01:35 -0800 Subject: [PATCH] Fix C API tests for centos and mac (#2544) * change c++14 to c++11 * add ld lib path for centos * enable csharp tests on macos * fix C API test on MacOS + fix manylinux dotnet install * fix manylinux dotnet install * fix lib link --- .../C_Api_Sample.cpp | 3 ++- .../runtest.sh | 27 ++++++++++++++----- .../nuget/templates/test_macos.yml | 4 ++- .../linux/docker/scripts/install_centos.sh | 12 +++++---- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp index 798dd24257..93aec5d0c9 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -146,7 +147,7 @@ int main(int argc, char* argv[]) { // Get pointer to output tensor float values float* floatarr; CheckStatus(g_ort->GetTensorMutableData(output_tensor, (void**)&floatarr)); - assert(abs(floatarr[0] - 0.000045) < 1e-6); + assert(std::abs(floatarr[0] - 0.000045) < 1e-6); // score the model, and print scores for first 5 classes for (int i = 0; i < 5; i++) diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh index f1c116f5d5..c2288eb82c 100755 --- a/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh +++ b/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests/runtest.sh @@ -6,6 +6,11 @@ LocalNuGetRepo=$1 SourceRoot=$2 BuildDir=$3 export CurrentOnnxRuntimeVersion=$4 +IsMacOS=${5:-false} +PackageName=${PACKAGENAME:-Microsoft.ML.OnnxRuntime} +RunTestCsharp=${RunTestCsharp:-true} +RunTestNative=${RunTestNative:-true} + set -x OldDir=`pwd` @@ -36,13 +41,23 @@ if [ $RunTestNative = "true" ]; then TempDir=_tmp mkdir -p $TempDir && pushd $TempDir unzip ../$PackageName - libs="-L runtimes/linux-x86/native -L runtimes/linux-x64/native -l onnxruntime" - inc="-I build/native/include" - g++ -std=c++14 $SourceRoot/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp $inc $libs -Wunused-result -o sampletest - # Create link to versioned shared object required at runtime - libname=`ldd sampletest | grep onnxruntime | xargs | cut -d" " -f1` - ln -sf runtimes/linux-x64/native/libonnxruntime.so $libname + inc="-I build/native/include" + + if [ $IsMacOS = "true" ]; then + export DYLD_FALLBACK_LIBRARY_PATH=$LocalNuGetRepo/_tmp:${DYLD_FALLBACK_LIBRARY_PATH} + libs="-L runtimes/osx-x64/native -l onnxruntime" + g++ -std=c++11 $SourceRoot/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp $inc $libs -Wunused-result -Wformat=0 -o sampletest + libName=$(otool -L ./sampletest | grep onnxruntime | xargs | cut -d' ' -f1 | cut -d'/' -f2) + ln -sf runtimes/osx-x64/native/libonnxruntime.dylib $libName + else + export LD_LIBRARY_PATH=$LocalNuGetRepo/_tmp:${LD_LIBRARY_PATH} + libs="-L runtimes/linux-x86/native -L runtimes/linux-x64/native -l onnxruntime" + g++ -std=c++11 $SourceRoot/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp $inc $libs -Wunused-result -o sampletest + # Create link to versioned shared object required at runtime + libname=`ldd sampletest | grep onnxruntime | xargs | cut -d" " -f1` + ln -sf runtimes/linux-x64/native/libonnxruntime.so $libname + fi # Copy Sample Model cp $SourceRoot/csharp/testdata/squeezenet.onnx . diff --git a/tools/ci_build/github/azure-pipelines/nuget/templates/test_macos.yml b/tools/ci_build/github/azure-pipelines/nuget/templates/test_macos.yml index f819526649..25695dbfe7 100644 --- a/tools/ci_build/github/azure-pipelines/nuget/templates/test_macos.yml +++ b/tools/ci_build/github/azure-pipelines/nuget/templates/test_macos.yml @@ -1,5 +1,6 @@ parameters: AgentPool : 'Hosted macOS High Sierra' + IsMacOS : 'true' jobs: - job: NuGet_Test_MacOS @@ -38,7 +39,8 @@ jobs: $(Build.BinariesDirectory)/nuget-artifact \ $(Build.SourcesDirectory) \ $(Build.BinariesDirectory) \ - $(NuGetPackageVersionNumber) + $(NuGetPackageVersionNumber) \ + ${{ parameters.IsMacOS }} if [ $? -ne 0 ]; then echo "Failed to run test" diff --git a/tools/ci_build/github/linux/docker/scripts/install_centos.sh b/tools/ci_build/github/linux/docker/scripts/install_centos.sh index 948c55f173..5b779c4cd5 100755 --- a/tools/ci_build/github/linux/docker/scripts/install_centos.sh +++ b/tools/ci_build/github/linux/docker/scripts/install_centos.sh @@ -21,12 +21,14 @@ elif [ "$os_major_version" == "6" ] && [ ! -d "/opt/python/cp35-cp35m" ]; then /usr/bin/python3.6 -m pip install --upgrade pip else yum install -y redhat-lsb-core expat-devel libcurl-devel tar unzip curl zlib-devel make libunwind icu aria2 rsync bzip2 git bzip2-devel - # install dotnet core dependencies - yum install -y lttng-ust openssl-libs krb5-libs libicu libuuid - # install dotnet runtimes - yum install -y https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm - yum install -y dotnet-sdk-2.2 + if [ "$os_major_version" == "7" ]; then + # install dotnet core dependencies + yum install -y lttng-ust openssl-libs krb5-libs libicu libuuid + # install dotnet runtimes + yum install -y https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm + yum install -y dotnet-sdk-2.2 + fi fi