예제 #1
0
        public void TestRoboRioMapsToNativeAssemblySymbols()
        {
            OsType type = NativeLibraryLoader.GetOsType();

            //Only run the roboRIO symbol test on windows.
            if (type != OsType.Windows32 && type != OsType.Windows64)
            {
                Assert.Pass();
            }

            var roboRIOSymbols = GetRequestedNativeSymbols();

            var pathToSolution = FindRootSolutionDirectory();
            var ps             = Path.DirectorySeparatorChar;

            Assert.That(pathToSolution, Is.Not.Null);
            var dirToNetworkTablesLib = $"{pathToSolution}{ps}src{ps}FRC.NetworkTables.Core.DesktopLibraries";

            // Start the child process.
            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.FileName = $"{dirToNetworkTablesLib}\\Libraries\\frcnm.exe";
            Console.WriteLine(p.StartInfo.FileName);
            p.StartInfo.Arguments = $"{dirToNetworkTablesLib}\\Libraries\\Linux\\arm\\libntcore.so";
            p.Start();
            string output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();

            bool found = true;


            string[] nativeSymbols = output.Split('\r');

            foreach (var halSymbol in roboRIOSymbols)
            {
                bool foundSymbol = nativeSymbols.Any(nativeSymbol => nativeSymbol.EndsWith(halSymbol));
                if (!foundSymbol)
                {
                    found = false;
                    Console.WriteLine(halSymbol);
                }
            }

            Assert.That(found);
        }
예제 #2
0
        public void TestNativeIntefaceBlittable()
        {
            OsType type = NativeLibraryLoader.GetOsType();

            //Only run the blittable test on windows. Pathing on linux is being an issue
            if (type != OsType.Windows32 && type != OsType.Windows64)
            {
                Assert.Pass();
            }

            List <string> allowedTypes = new List <string>()
            {
                // Allowed types with arrays are also allowed
                "byte", "sbyte", "short", "ushort", "int", "uint", "long", "ulong", "IntPtr", "UIntPtr", "float", "void", "double",

                // For now force our enum types to be OK
                "NtType",
                //"CTR_Code", "HALAccelerometerRange", "HALAllianceStationID", "AnalogTriggerType", "Mode",

                //Allow delegates to be blittable
                "WarmFunction", "NT_LogFunc", "NT_ConnectionListenerCallback", "NT_EntryListenerCallback", "NT_RPCCallback",

                //Also allow any structs known to be blittable
                "NtStringRead", "DisposableNativeString", "NtConnectionInfo", "NtRpcCallInfo",

                //For now allow bool, since it marshalls easily
                //This will change if the native windows HAL is not 1 byte bools
                "bool",
            };

            List <string> notBlittableMethods = new List <string>();


            var halBaseDelegates = GetDelegates();

            foreach (var halDelegate in halBaseDelegates)
            {
                foreach (var methodSyntax in halDelegate.Methods)
                {
                    List <TypeSyntax> types = new List <TypeSyntax>();

                    if (methodSyntax.AttributeLists.Count != 0)
                    {
                        types.Add(methodSyntax.ReturnType);
                    }
                    else
                    {
                        types.Add(methodSyntax.ReturnType);
                    }

                    List <string> param = new List <string>();

                    StringBuilder builder = new StringBuilder();
                    builder.Append($"\t {methodSyntax.ReturnType} {methodSyntax.Identifier} (");
                    bool first = true;
                    foreach (var parameter in methodSyntax.ParameterList.Parameters)
                    {
                        if (parameter.AttributeLists.Count != 0)
                        {
                            types.Add(parameter.Type);
                        }
                        else
                        {
                            types.Add(parameter.Type);
                        }


                        param.Add(parameter.Type.ToString());
                        if (first)
                        {
                            first = false;
                            builder.Append($"{parameter.Type} {parameter.Identifier}");
                        }
                        else
                        {
                            builder.Append($", {parameter.Type} {parameter.Identifier}");
                        }
                    }
                    builder.Append(")");

                    CheckForBlittable(types, allowedTypes, notBlittableMethods, builder.ToString());
                }
            }

            foreach (string s in notBlittableMethods)
            {
                Console.WriteLine(s);
            }

            if (notBlittableMethods.Count != 0)
            {
                Assert.Fail();
            }
            else
            {
                Assert.Pass();
            }
        }