[tests] Strict assembly loading of two version of the same assm should work.
authorAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Jun 2017 22:30:50 +0000 (18:30 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Jun 2017 23:07:51 +0000 (19:07 -0400)
In particular, we should be able to use classes/methods that are unique to each
version.  We should not get only one version loaded.

mono/tests/testing_gac/Makefile.am
mono/tests/testing_gac/app-both.cs [new file with mode: 0644]
mono/tests/testing_gac/v1/gactestlib.cs
mono/tests/testing_gac/v2/gactestlib.cs

index a1fa3fe0325f20a69a57849c8092c1991b1b107c..275f8c0153458a8db6f3c8c1d46e9167117bc61c 100644 (file)
@@ -59,6 +59,8 @@ APP_V1_SRC = v1/app.cs v1/app-refl-load.cs
 
 APP_SIGNED_V1_EXE = app-v1.exe app-refl-load-v1.exe
 
+APP_BOTH_EXE = app-both.exe
+
 UNSIGNED_V1_DLL= unsigned_v1/gactestlib.dll
 UNSIGNED_V2_DLL= unsigned_v2/gactestlib.dll
 
@@ -96,8 +98,10 @@ EXTRA_DIST= README $(SIGNING_KEY) $(GACTESTLIB_SRCS)
 .PHONY: runtest compile-tests prereqs
 
 runtest:
+       true
 if !FULL_AOT_TESTS
 if !HYBRID_AOT_TESTS
+       $(MAKE) test-app-both
        $(MAKE) test-signed-v1-app-mp-unsigned-v1
        $(MAKE) test-signed-v1-app-mp-signed-v1
        $(MAKE) test-signed-v1-app-mp-unsigned-v2-signed-v1
@@ -106,7 +110,7 @@ if !HYBRID_AOT_TESTS
 endif
 endif
 
-compile-tests: prereqs $(APP_SIGNED_V1_EXE) $(APP_SIGNED_V1_AOT)
+compile-tests: prereqs $(APP_SIGNED_V1_EXE) $(APP_BOTH_EXE) $(APP_SIGNED_V1_AOT)
 
 prereqs: $(GACTESTLIB_DLLS) $(GACTESTLIB_DLLS_AOT)
        $(MAKE) gacinstall
@@ -127,6 +131,9 @@ $(SIGNED_V2_DLL): $(V2_SRC) $(SIGNING_KEY)
        -mkdir -p $(@D)
        $(MCS) -out:$@ $(SIGN) $< && $(TOOLS_RUNTIME) $(SN) -R $@ $(SIGNING_KEY)
 
+app-both.exe: app-both.cs $(SIGNED_V1_DLL) $(SIGNED_V2_DLL)
+       $(MCS) -target:exe -out:$@ -r:V1=$(SIGNED_V1_DLL) /r:V2=$(SIGNED_V2_DLL) $<
+
 %-v1.exe: v1/%.cs $(SIGNED_V1_DLL)
        $(MCS) -target:exe -out:$@ -r:$(SIGNED_V1_DLL) $<
 
@@ -150,6 +157,10 @@ test-signed-v1-app-mp-unsigned-v2-signed-v1: $(APP_SIGNED_V1_EXE) prereqs
 test-signed-v1-app-mp-signed-v2-signed-v1: $(APP_SIGNED_V1_EXE) prereqs
        $(TOOLS_RUNTIME) $(TEST_RUNNER) $(TEST_RUNNER_ARGS) --testsuite-name "testing_gac_$@" --mono-path "signed_v2$(PLATFORM_PATH_SEPARATOR)signed_v1$(PLATFORM_PATH_SEPARATOR)$(BASE_MONO_PATH)" $(APP_SIGNED_V1_EXE)
 
+# N.B. the path order is important - the test needs to load v1 successfully and then try to load v2 from the v1 directory.
+test-app-both: $(APP_BOTH_EXE) prereqs
+       $(TOOLS_RUNTIME) $(TEST_RUNNER) $(TEST_RUNNER_ARGS) --testsuite-name "testing_gac_$@" --mono-path "signed_v1$(PLATFORM_PATH_SEPARATOR)signed_v2$(PLATFORM_PATH_SEPARATOR)$(BASE_MONO_PATH)" app-both.exe
+
 # MONO_GAC_PREFIX tests
 
 test-signed-v1-app-gac: $(APP_SIGNED_V1_EXE) gacinstall prereqs
diff --git a/mono/tests/testing_gac/app-both.cs b/mono/tests/testing_gac/app-both.cs
new file mode 100644 (file)
index 0000000..ae32d3e
--- /dev/null
@@ -0,0 +1,23 @@
+
+// reference both versions of gactestlib via extern aliases.
+
+// N.B. the order of the aliases is important - the compiler will emit
+// .assembly declarations in the IL file in order, and Mono will try to load the declarations in the same order.
+// The test relies on V1 being loaded first and then V2 being tried from V1's MONO_PATH directory.
+extern alias V1;
+extern alias V2;
+
+using System;
+
+public class AppBoth {
+       public static int Main (string[] args) {
+               // regression test that references two strongly named
+               // assemblies that have the same name but different versions.
+               V1.OnlyInV1.M ();
+               V2.OnlyInV2.M ();
+               if (typeof (V1.X).Assembly.GetName ().Version == typeof (V2.X).Assembly.GetName ().Version)
+                       return 1;
+
+               return 0;
+       }
+}
index 1ced863e6a7feeb9fb56bbe5e95c1a4caed9196b..fad4fbb0c1ce69b64b988eda42e332781fcec157 100644 (file)
@@ -13,3 +13,7 @@ public class X
        }
 
 }
+
+public class OnlyInV1 {
+       public static void M () { }
+}
index 85ae29627cf7b6a07c1df5fae6f56cc0050cbfe1..2cfa666bfcdc3802cf673f9da7183e50c6f6147f 100644 (file)
@@ -13,3 +13,7 @@ public class X
        // {
        // }
 }
+
+public class OnlyInV2 {
+       public static void M () { }
+}