Example #1
0
        public void InitializeDeps_LoadsExpectedDependencies()
        {
            string        depsPath            = Path.Combine(Directory.GetCurrentDirectory(), "Description", "DotNet", "TestFiles", "DepsFiles");
            List <string> currentRidFallbacks = DependencyHelper.GetRuntimeFallbacks();

            (IDictionary <string, RuntimeAsset[]> depsAssemblies, IDictionary <string, RuntimeAsset[]> nativeLibraries) =
                FunctionAssemblyLoadContext.InitializeDeps(depsPath, currentRidFallbacks);

            string testRid = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win" : "unix";

            // Ensure runtime specific dependencies are resolved, with appropriate RID
            FunctionAssemblyLoadContext.TryGetDepsAsset(depsAssemblies, "System.private.servicemodel", currentRidFallbacks, out string assemblyPath);
            Assert.Equal($"runtimes/{testRid}/lib/netstandard2.0/System.Private.ServiceModel.dll", assemblyPath);

            FunctionAssemblyLoadContext.TryGetDepsAsset(depsAssemblies, "System.text.encoding.codepages", currentRidFallbacks, out assemblyPath);
            Assert.Equal($"runtimes/{testRid}/lib/netstandard1.3/System.Text.Encoding.CodePages.dll", assemblyPath);

            // Ensure flattened dependency has expected path
            FunctionAssemblyLoadContext.TryGetDepsAsset(depsAssemblies, "Microsoft.Azure.WebJobs.Host.Storage", currentRidFallbacks, out assemblyPath);
            Assert.Equal($"Microsoft.Azure.WebJobs.Host.Storage.dll", assemblyPath);

            // Ensure native libraries are resolved, with appropriate RID and path
            string nativeRid;
            string nativePrefix;
            string nativeExtension;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                nativeRid       = "win-";
                nativePrefix    = string.Empty;
                nativeExtension = "dll";
            }
            else
            {
                nativePrefix = "lib";
                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    nativeRid       = "osx-";
                    nativeExtension = "dylib";
                }
                else
                {
                    nativeRid       = "linux-";
                    nativeExtension = "so";
                }
            }

            nativeRid += Environment.Is64BitProcess ? "x64" : "x86";

            string nativeAssetFileName = $"{nativePrefix}CpuMathNative.{nativeExtension}";

            FunctionAssemblyLoadContext.TryGetDepsAsset(nativeLibraries, nativeAssetFileName, currentRidFallbacks, out string assetPath);
            Assert.Contains($"runtimes/{nativeRid}/nativeassets/netstandard2.0/{nativeAssetFileName}", assetPath);
        }
Example #2
0
        public void InitializeDeps_WithRidSpecificNativeAssets_LoadsExpectedDependencies(string rid, string expectedNativeRid, string prefix, string suffix, bool expectMatch)
        {
            string depsPath = Path.Combine(Directory.GetCurrentDirectory(), "Description", "DotNet", "TestFiles", "DepsFiles", "RidNativeDeps");

            List <string> ridFallback = DependencyHelper.GetRuntimeFallbacks(rid);

            (_, IDictionary <string, RuntimeAsset[]> nativeLibraries) =
                FunctionAssemblyLoadContext.InitializeDeps(depsPath, ridFallback);

            string nativeAssetFileName = $"{prefix}Cosmos.CRTCompat.{suffix}";

            FunctionAssemblyLoadContext.TryGetDepsAsset(nativeLibraries, nativeAssetFileName, ridFallback, out string assetPath);

            string expectedMatch = expectMatch
                ? $"runtimes/{expectedNativeRid}/native/{nativeAssetFileName}"
                : null;

            Assert.Equal(expectedMatch, assetPath);
        }
Example #3
0
        public void GetRuntimeFallbacks_WithUnkonwnRid_DefaultsToPlatformRid(string rid)
        {
            List <string> rids = DependencyHelper.GetRuntimeFallbacks(rid);

            // Ensure the "unknown" RID is still in the list
            Assert.Equal(rid, rids.First());

            // Ensure our fallback list matches our default RID fallback
            var defaultRidFallback = DependencyHelper.GetDefaultRuntimeFallbacks(DotNetConstants.DefaultWindowsRID);
            var defaultRidGraph    = new List <string> {
                defaultRidFallback.Runtime
            };

            defaultRidGraph.AddRange(defaultRidFallback.Fallbacks);

            bool match = defaultRidGraph
                         .Zip(rids.Skip(1), (s1, s2) => string.Equals(s1, s2, StringComparison.Ordinal))
                         .All(r => r);

            Assert.True(match, $"Mismatched fallbacks for unknown RID");
        }