Cannot build Core FX tests on Linux
I encountered the following error while building FX tests:
$ ./build-managed.sh -release -SkipTests -- /maxcpucount:4 /p:BinPlaceNETCoreAppPackage=true
...
Microsoft.XmlSerializer.Generator.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/Microsoft.XmlSerializer.Generator.Tests/netcoreapp/Microsoft.XmlSerializer.Generator.Tests.dll
System.Collections.Immutable.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Collections.Immutable.Tests/netcoreapp/System.Collections.Immutable.Tests.dll
System.Collections.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Collections.Tests/netcoreapp/System.Collections.Tests.dll
System.Composition.Convention.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Composition.Convention.Tests/netcoreapp/System.Composition.Convention.Tests.dll
System.ComponentModel.Annotations.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.ComponentModel.Annotations.Tests/netcoreapp/System.ComponentModel.Annotations.Tests.dll
System.ComponentModel.TypeConverter.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.ComponentModel.TypeConverter.Tests/netcoreapp/System.ComponentModel.TypeConverter.Tests.dll
System.Diagnostics.Debug.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Diagnostics.Debug.Tests/netcoreapp/System.Diagnostics.Debug.Tests.dll
System.Diagnostics.Tracing.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Diagnostics.Tracing.Tests/netcoreapp/System.Diagnostics.Tracing.Tests.dll
System.Drawing.Primitives.Tests -> /var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/AnyOS.AnyCPU.Release/System.Drawing.Primitives.Tests/netcoreapp/System.Drawing.Primitives.Tests.dll
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'System.Native': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at Interop.Sys.Dup(SafeFileHandle oldfd)
at Microsoft.Win32.SafeHandles.SafeFileHandleHelper.Open(Func`1 fdFunc)
at System.ConsolePal.OpenStandardError()
at System.Console.<>c.<get_Error>b__27_0()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Object& syncLock, Func`1 valueFactory)
at Microsoft.XmlSerializer.Generator.Sgen.WriteError(Exception e)
at Microsoft.XmlSerializer.Generator.Sgen.Run(String[] args)
at Microsoft.XmlSerializer.Generator.Sgen.Main(String[] args)
Aborted (core dumped)
/var/jenkins/workspace/FX/FX_Managed_Release/repo/code/src/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj(57,5): error MSB3073: The command "/var/jenkins/workspace/FX/FX_Managed_Release/repo/code/bin/testhost/netcoreapp-Linux-Release-x64/dotnet
...
Is there any requirement to build this test on Linux? I couldn't understand why it failed to find System.Native.
~IMO, it seems that -SkipTests argument is not working.
Maybe Microsoft.XmlSerializer.Generator.Tests is the first running test in linux.~
It's my misreading. Forget this comment.
In Linux cross build environment for ARM, I faced this same problem after resolving dotnet/runtime#23548.
@huanwu ?
@hqueue All tests pass on CI. How can I repro this issue? @shmao
The above issue is not from ARM cross build, I just ran x64 managed build inside Ubuntu 14.04 docker container with the following command:
$ ./build-managed.sh -release -SkipTests -- /maxcpucount:4 /p:BinPlaceNETCoreAppPackage=true
...
$ ./build-managed.sh -release -BuildTests -SkipTests -- /maxcpucount:4 /p:ArchiveTests=true
...
The error comes from the second stage.
I was able to repro the issue on my ubuntu machine. This seems like a issue with the CLI tools for the tests. In my experiments, the following command worked,
/home/wcfcore/dd/corefx/bin/testhost/netcoreapp-Linux-Debug-x64/dotnet /home/wcfcore/dd/corefx/bin/AnyOS.AnyCPU.Release/Microsoft.XmlSerializer.Generator.Tests/netcoreapp/dotnet-Microsoft.XmlSerializer.Generator.dll /home/wcfcore/dd/corefx/bin/AnyOS.AnyCPU.Release/Microsoft.XmlSerializer.Generator.Tests/netcoreapp/Microsoft.XmlSerializer.Generator.Tests.dll /force /quiet
The following command failed,
/home/wcfcore/dd/corefx/bin/testhost/netcoreapp-Linux-Release-x64/dotnet /home/wcfcore/dd/corefx/bin/AnyOS.AnyCPU.Release/Microsoft.XmlSerializer.Generator.Tests/netcoreapp/dotnet-Microsoft.XmlSerializer.Generator.dll /home/wcfcore/dd/corefx/bin/AnyOS.AnyCPU.Release/Microsoft.XmlSerializer.Generator.Tests/netcoreapp/Microsoft.XmlSerializer.Generator.Tests.dll /force /quiet
The only difference between the above two commands was that the first one use the dotnet tool from Debug testhost while the second one use the one from Release folder.
The Debug CLI tool's \shared folder included System.Native.so, the Release one did not. I guessed that caused the issue.
@ericstj Is this as expected?
@ericstj @mellinoe can you please take a look at my comments above? Should the CLI tool used by Release build also include System.Native.so?
Have you completed a full Release build of the product before running the second command? The bin/testhost directory is populated during the build of the product, so if you haven't done a complete build (e.g. by running build.sh -release), then it will be missing things.
@mellinoe thanks for the tips. You are right. After I ran build.sh -release the command succeeded.
Is build.sh -release always supposed to be run before using /build-managed.sh -release -SkipTests, even for cross build? If that's the case, we may close the issue.
I'm not sure about cross-build, to be honest. But if we are executing things out of that testhost directory, then we will need to have done a full build before-hand; build-managed.sh is not enough by itself.
Then again, if this is a cross-build, then trying to execute things out of that directory doesn't really make a lot of sense, because the binaries will be for a different machine, not the local one.
@weshaggard Thoughts?
cc @ericstj
I wouldn't expect the building of the tests to ever try to execute this command why is it running during the build? If that is the case then we should also make it honor the skiptests property to disable it from running.
As was discussed here: https://github.com/dotnet/corefx/pull/23758#issuecomment-328220067, the sgen tool is meant to run on the framework that was just built so I made changes to the project to enable that. https://github.com/ericstj/corefx/blob/43e9165afdacfa79ff1ffc87759da34ecf6ab3b9/src/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj#L11-L22
Previously that tool was only ever running on the LKG version (tools version) of netcoreapp so it wasn't even testing the tool on the latest framework.
If you don't want to execute that command as part of the build then you could have the test run the command (as well as CSC of the resultant generated source) at test time, but that will require a bit of work refactoring the test cases.
I already discussed the cross-targeting scenario here: https://github.com/dotnet/corefx/pull/24030#issuecomment-329926208. Rather than skipping you should just use the tool-runtime. You won't get coverage of running the sgen tool on the latest bits, but that's better than no coverage at all on that architecture.
Thanks for the information, @ericstj . My comments on dotnet/corefx#23758 is still valid. We want the SGen tool to run on the just-built bits. And I believe the fix you made to enable SGen's test project to use the test CLI was the right fix.
The issue here is that the \testhost folder populated by build-managed.sh does not have some components required by dotnet.exe, e.g. System.Native.so, which is built by build-native.sh and was not available when build-managed.sh assembled the testhost folder. The workaround for the issue is to run build-native.sh first before cross compiling for managed corefx, i.e.
$ ./build-native.sh -release
$ ./build-managed.sh -release -SkipTests -- /maxcpucount:4 /p:BinPlaceNETCoreAppPackage=true
$ ./build-managed.sh -release -BuildTests -SkipTests -- /maxcpucount:4 /p:ArchiveTests=true
@parjong would the workaround above work for you?
@shmao Thanks you! That workaround works for me.
Thanks for the confirmation, @parjong .
I'm closing the issue.