Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MonoTests.System.Reflection.Emit.SaveTest.Save test fails in Release configuration with BCL linking on #1186

Closed
grendello opened this issue Jan 11, 2018 · 11 comments
Assignees
Labels
Area: Linker Issues when linking assemblies. bug Component does not function as intended.

Comments

@grendello
Copy link
Contributor

A test from the Mono BCL test suite (MonoTests.System.Reflection.Emit.SaveTest.Save) fails when the tests are built in Release mode with linking set to SdkOnly.
It seems that the linker somehow changes the order of interfaces in emitted code since turning BCL linking off makes the test work again. The test also works fine in Debug configuration (with the linker off)

Steps to Reproduce

  1. Comment out this line
  2. Run make CONFIGURATION=Release run-apk-tests from the top Xamarin.Android dir
  3. Wait patiently
  4. Find the failure in the NUnit tests result file (TestResult-Xamarin.Android.Bcl_Tests.nunit-Release.xml in the top Xamarin.Android directory)

Expected Behavior

The test should run fine with BCL linking on

Actual Behavior

The test fails when executed with BCL linking on

Version Information

Xamarin.Android/master (c4e81655ac22b06806e732e9dd0bc729e8d2c1d7)

Test failure

MESSAGE:
  Expected: <iface1>
  But was:  <System.IComparable>

  +++++++++++++++++++
  STACK TRACE:
  at MonoTests.System.Reflection.Emit.SaveTest.CheckAssembly (System.Reflection.Assembly a) [0x000a0] in <1e30aff9165c427db5bedc42c5906861>:0 
  at MonoTests.System.Reflection.Emit.SaveTest.Save () [0x00b6d] in <1e30aff9165c427db5bedc42c5906861>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <0a3e31ed05774b07957e0b91c5cab789>:0
@grendello grendello added bug Component does not function as intended. Area: Linker Issues when linking assemblies. labels Jan 11, 2018
@radekdoulik
Copy link
Member

This doesn't look like a linker bug, as the assembly is created by the test itself, not by the linker.

@jonpryor
Copy link
Member

@radekdoulik: While that is indeed the case, it's only with a linked BCL that the problem occurs. Running the test with a Debug/unlinked BCL results in the test passing.

We don't understand why or how linking would be involved, but it's the straw we're grasping at.

@radekdoulik
Copy link
Member

Further looking into that, I have put the code from the test to simple android app and it works OK in the Release configuration. The first interface is iface1.

So not sure yet what might be broken here.

@radekdoulik
Copy link
Member

radekdoulik commented Jan 16, 2018

OK, the issue is the test is wrong :-)

In the documentation it is clearly stated, that the interfaces are not returned in any particular order. https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2

@grendello
Copy link
Contributor Author

@radekdoulik yes, it's not documented but @marek-safar stated that the runtime team aim for 100% compatibility with .NET, and the ordering tested for is what .NET does. As @jonpryor said, we're clutching at straws here as the linking was the only real difference between the builds and it is consistently reproducible.

@radekdoulik
Copy link
Member

@grendello not sure I understand you here, when you say that it is not documented . The documentation says

The GetInterfaces method does not return interfaces in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which interfaces are returned, because that order varies.

@radekdoulik
Copy link
Member

@marek-safar Do you have link to our current System.Type::GetInterfaces implementation at hand?

@grendello
Copy link
Contributor Author

@radekdoulik By 'not documented' I meant it isn't stated that the order must be kept. The wording you pasted states that it 'must not' depend on the order, which would make the test invalid, but as @marek-safar stated we want to keep compatibility with .NET as there might be code out there which relies on the particular behavior of .NET (even if it isn't a documented one)

@migueldeicaza
Copy link
Contributor

You might just be getting lucky with some idioms/patterns in .NET, and might change with others, or might change across other implementations. The documentation is right, we should fix the test.

@jonpryor
Copy link
Member

On the implementation side of things, it appears that RuntimeType.GetInterfaces() is implemented as ves_icall_RuntimeType_GetInterfaces() which uses a GHashTable to contain the enumerated interfaces.

I'm going to hazard a guess that GHashTable/g_hash_table_insert() doesn't preserve insertion order, which means the docs are correct and should be followed, because there's no easy way of fixing the implementation, just the tests.

@marek-safar
Copy link
Contributor

I'm ok with the test fix but we have bug reports like https://bugzilla.xamarin.com/show_bug.cgi?id=31020 and similar so you could actually end up fixing this issue in XA for real

radekdoulik added a commit to radekdoulik/mono that referenced this issue Jan 17, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
marek-safar pushed a commit to mono/mono that referenced this issue Jan 17, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
radekdoulik added a commit to radekdoulik/mono that referenced this issue Jan 17, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
radekdoulik added a commit to radekdoulik/mono that referenced this issue Jan 17, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
marek-safar pushed a commit to mono/mono that referenced this issue Jan 18, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
marek-safar pushed a commit to mono/mono that referenced this issue Jan 18, 2018
Updated the System.Reflection.Emit/SaveTest to not depend on order of
interfaces returned from the System.Type::GetInterfaces method, as the
order is not guaranted. As described in the [documentation][0].

Also see github [issue][1] for more information and reasoning.

[0]: https://msdn.microsoft.com/en-us/library/system.type.getinterfaces(v=vs.110).aspx#Anchor_2
[1]: dotnet/android#1186
radekdoulik added a commit to radekdoulik/xamarin-android that referenced this issue Jan 18, 2018
And enable the SaveTest again for Release configuration.
jonpryor pushed a commit to jonpryor/xamarin-android that referenced this issue Mar 29, 2021
…cations. (dotnet#5708)

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288717
Context: xamarin/monodroid@83de4b4

Changes: xamarin/monodroid@b2a750a...4163ee9

  * xamarin/monodroid@4163ee947: [Xamarin.Android.Build.Tasks] Support FastDev for System Apps (dotnet#1177) (dotnet#1186)
  * xamarin/monodroid@947c6ef72: Bump to xamarin/xamarin-android/d16-9@877f5727 (dotnet#1183)

The new fast deployment system (xamarin/monodroid@767f6471) broke
fast deployment for system-installed applications.

This is fixed in xamarin/monodroid@4163ee94.

Adds unit tests to stop this kind of regression in the future.

In order to install a `system` application we need a few things:

 1. The emulator MUST be started with the `-system-writable` argument

 2. The `.apk` needs to be signed with a platform keystore, found at:
    https://github.com/aosp-mirror/platform_build/tree/master/target/product/security

 3. `AndroidManifest.xml` must set
    [`/manifest/@android:sharedUserId`][0] to `android.uid.system`:

        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            android:sharedUserId="android.uid.system"
            …>
        </manifest>

See also:

  * https://medium.com/xrpractices/android-system-apps-development-d73bedfb8def

[0]: https://developer.android.com/guide/topics/manifest/manifest-element#uid
jonpryor pushed a commit that referenced this issue Mar 30, 2021
…cations. (#5708)

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288717
Context: xamarin/monodroid@83de4b4

Changes: xamarin/monodroid@b2a750a...4163ee9

  * xamarin/monodroid@4163ee947: [Xamarin.Android.Build.Tasks] Support FastDev for System Apps (#1177) (#1186)
  * xamarin/monodroid@947c6ef72: Bump to xamarin/xamarin-android/d16-9@877f5727 (#1183)

The new fast deployment system (xamarin/monodroid@767f6471) broke
fast deployment for system-installed applications.

This is fixed in xamarin/monodroid@4163ee94.

Adds unit tests to stop this kind of regression in the future.

In order to install a `system` application we need a few things:

 1. The emulator MUST be started with the `-system-writable` argument

 2. The `.apk` needs to be signed with a platform keystore, found at:
    https://github.com/aosp-mirror/platform_build/tree/master/target/product/security

 3. `AndroidManifest.xml` must set
    [`/manifest/@android:sharedUserId`][0] to `android.uid.system`:

        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            android:sharedUserId="android.uid.system"
            …>
        </manifest>

See also:

  * https://medium.com/xrpractices/android-system-apps-development-d73bedfb8def

[0]: https://developer.android.com/guide/topics/manifest/manifest-element#uid
@ghost ghost locked as resolved and limited conversation to collaborators Jun 9, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Area: Linker Issues when linking assemblies. bug Component does not function as intended.
Projects
None yet
Development

No branches or pull requests

5 participants