Example #1
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                throw new Exception("Usage: StandaloneBSPValidator <job file> <output dir>");
            }

            var job = XmlTools.LoadObject <TestJob>(args[0]);

            job.BSPPath = job.BSPPath.Replace("$$JOBDIR$$", Path.GetDirectoryName(args[0]));
            if (job.ToolchainPath.StartsWith("["))
            {
                job.ToolchainPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(job.ToolchainPath.Trim('[', ']'));
                if (job.ToolchainPath == null)
                {
                    throw new Exception("Cannot locate toolchain path from registry");
                }
            }

            var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(job.ToolchainPath)));
            var bsp       = LoadedBSP.Load(new BSPEngine.BSPSummary(Path.GetFullPath(Environment.ExpandEnvironmentVariables(job.BSPPath))), toolchain);

            TestBSP(job, bsp, args[1]);
            return;
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args[0] == "vs")
            {
                if (args.Length < 3)
                {
                    throw new Exception("Usage: StandaloneBSPValidator vs <VendorSamples dir> <output dir>");
                }

                if (Directory.GetFiles(args[1], "VendorSamples.xml").Count() == 0)
                {
                    foreach (var dir in Directory.GetDirectories(args[1]))
                    {
                        foreach (var es in Directory.GetFiles(dir, "VendorSamples.xml"))
                        {
                            var expandedSamples = XmlTools.LoadObject <VendorSampleDirectory>(es);
                            expandedSamples.Path = Path.GetFullPath(Path.Combine(dir, "VendorSamples"));
                            var testdir = Path.GetDirectoryName(Path.Combine(dir, "VendorSamples")).Split('\\').Reverse().ToArray()[0];
                            var ts      = TestVendorSamples(expandedSamples, dir, Path.Combine(args[2], testdir));
                        }
                    }
                }
                else
                {
                    var bspDir          = args[1];
                    var expandedSamples = XmlTools.LoadObject <VendorSampleDirectory>(Path.Combine(bspDir, "VendorSamples.xml"));
                    expandedSamples.Path = Path.GetFullPath(Path.Combine(bspDir, "VendorSamples"));
                    var ts = TestVendorSamples(expandedSamples, bspDir, args[2]);
                }
            }
            else
            {
                if (args.Length < 2)
                {
                    throw new Exception("Usage: StandaloneBSPValidator <job file> <output dir>");
                }

                var job = XmlTools.LoadObject <TestJob>(args[0]);
                job.BSPPath = job.BSPPath.Replace("$$JOBDIR$$", Path.GetDirectoryName(args[0]));
                if (job.ToolchainPath.StartsWith("["))
                {
                    job.ToolchainPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(job.ToolchainPath.Trim('[', ']'));
                    if (job.ToolchainPath == null)
                    {
                        throw new Exception("Cannot locate toolchain path from registry");
                    }
                }

                var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(job.ToolchainPath)));
                var bsp       = LoadedBSP.Load(new BSPEngine.BSPSummary(Path.GetFullPath(Environment.ExpandEnvironmentVariables(job.BSPPath))), toolchain);

                TestBSP(job, bsp, args[1]);
            }
            return;
        }
Example #3
0
        protected VendorSampleParser(string testedBSPDirectory, string sampleCatalogName, string subdir = null)
        {
            VendorSampleCatalogName = sampleCatalogName;

            var baseDirectory = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\.."));

            string problemClassifierFile = Path.Combine(baseDirectory, "KnownProblems.xml");

            _KnownProblems = XmlTools.LoadObject <KnownSampleProblemDatabase>(problemClassifierFile);

            BSPDirectory   = Path.GetFullPath(Path.Combine(baseDirectory, testedBSPDirectory));
            CacheDirectory = Path.Combine(baseDirectory, "Cache");
            RulesDirectory = Path.Combine(baseDirectory, "Rules");
            var reportDirectory = Path.Combine(baseDirectory, "Reports");

            if (!string.IsNullOrEmpty(subdir))
            {
                CacheDirectory  = Path.Combine(CacheDirectory, subdir);
                RulesDirectory  = Path.Combine(RulesDirectory, subdir);
                reportDirectory = Path.Combine(reportDirectory, subdir);
            }

            Directory.CreateDirectory(CacheDirectory);
            Directory.CreateDirectory(reportDirectory);

            var toolchainType = XmlTools.LoadObject <BoardSupportPackage>(Path.Combine(BSPDirectory, LoadedBSP.PackageFileName)).GNUTargetID ?? throw new Exception("The BSP does not define GNU target ID.");

            TestDirectory      = _SettingsKey.GetValue("TestDirectory") as string ?? throw new Exception("Registry settings not present. Please apply 'settings.reg'");
            ToolchainDirectory = _SettingsKey.CreateSubKey("ToolchainDirectories").GetValue(toolchainType) as string ?? throw new Exception($"Location for {toolchainType} toolchain is not configured. Please apply 'settings.reg'");

            var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(ToolchainDirectory)));

            BSP = LoadedBSP.Load(new BSPEngine.BSPSummary(Environment.ExpandEnvironmentVariables(Path.GetFullPath(BSPDirectory))), toolchain);

            ReportFile = Path.Combine(reportDirectory, BSP.BSP.PackageVersion.Replace(".", "_") + ".xml");
            if (File.Exists(ReportFile))
            {
                _Report = XmlTools.LoadObject <VendorSampleTestReport>(ReportFile);
            }
            else
            {
                _Report = new VendorSampleTestReport {
                    BSPVersion = BSP.BSP.PackageVersion, BSPID = BSP.BSP.PackageID
                }
            };
        }
Example #4
0
        public static LoadedBSP LoadBSP(string toolchainID, string bspDir)
        {
            if (string.IsNullOrEmpty(toolchainID))
            {
                toolchainID = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\BSPTools\VendorSampleParsers\ToolchainDirectories").GetValue("arm-eabi");
            }

            if (toolchainID.StartsWith("["))
            {
                toolchainID = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(toolchainID.Trim('[', ']'));
                if (toolchainID == null)
                {
                    throw new Exception("Cannot locate toolchain path from registry");
                }
            }

            var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(toolchainID)));

            return(LoadedBSP.Load(new BSPEngine.BSPSummary(Path.GetFullPath(Environment.ExpandEnvironmentVariables(bspDir))), toolchain));
        }
Example #5
0
        private static void RunTests(MbedBSPGenerator generator)
        {
            var testFiles = new TestInfo[] {
                new TestInfo("test_ledblink.xml", 0, 0),
                new TestInfo("test_usbcd.xml", 0, 0),
                new TestInfo("test_ledblink_rtos.xml", 0, 0),
            };

            foreach (var test in testFiles)
            {
                Console.WriteLine($"Testing {test.Filename}...");
                var job = XmlTools.LoadObject <TestJob>(Path.Combine(generator.dataDir, test.Filename));
                if (job.ToolchainPath.StartsWith("["))
                {
                    job.ToolchainPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(job.ToolchainPath.Trim('[', ']'));
                    if (job.ToolchainPath == null)
                    {
                        throw new Exception("Cannot locate toolchain path from registry");
                    }
                }
                var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(job.ToolchainPath)));
                var lbsp      = LoadedBSP.Load(new BSPEngine.BSPSummary(Environment.ExpandEnvironmentVariables(Path.Combine(generator.outputDir, "mbed"))), toolchain);

                var r = StandaloneBSPValidator.Program.TestBSP(job, lbsp, Path.Combine(generator.outputDir, "TestResults"));
                test.Passed = r.Passed;
                test.Failed = r.Failed;
            }

            foreach (var test in testFiles)
            {
                Console.WriteLine("Results for the test: " + test.Filename);
                Console.WriteLine("Passed: " + test.Passed.ToString());
                Console.WriteLine("Failed: " + test.Failed.ToString());
                Console.WriteLine();
            }
        }
Example #6
0
        public static TestStatistics TestVendorSamples(VendorSampleDirectory samples, string bspDir, string temporaryDirectory, double testProbability = 1, bool esp32 = false)
        {
            string defaultToolchainID = "SysGCC-arm-eabi-6.2.0";

            flEsp32 = false;

            if (esp32)
            {
                defaultToolchainID = "SysGCC-xtensa-esp32-elf-5.2.0";
                flEsp32            = true;
            }

            var toolchainPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(defaultToolchainID);

            if (toolchainPath == null)
            {
                throw new Exception("Cannot locate toolchain path from registry");
            }

            var toolchain = LoadedToolchain.Load(new ToolchainSource.Other(Environment.ExpandEnvironmentVariables(toolchainPath)));
            var bsp       = LoadedBSP.Load(new BSPEngine.BSPSummary(Environment.ExpandEnvironmentVariables(Path.GetFullPath(bspDir))), toolchain);

            if (flEsp32)
            {
                toolchainPath = toolchainPath.Replace('\\', '/'); //esp32
            }
            TestStatistics stats = new TestStatistics();
            int            cnt = 0, failed = 0, succeeded = 0;

            LoadedBSP.LoadedMCU[] MCUs = bsp.MCUs.ToArray();
            string outputDir           = Path.Combine(temporaryDirectory, "VendorSamples");

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            int    sampleCount = samples.Samples.Length;
            Random rng         = new Random();

            using (var r = new TestResults(Path.Combine(temporaryDirectory, "bsptest.log")))
            {
                r.BeginSample("Vendor Samples");
                foreach (var vs in samples.Samples)
                {
                    LoadedBSP.LoadedMCU mcu;
                    try
                    {
                        var rgFilterID = new Regex(vs.DeviceID.Replace('x', '.'), RegexOptions.IgnoreCase);
                        mcu         = bsp.MCUs.Where(f => rgFilterID.IsMatch(f.ExpandedMCU.ID)).ToArray()?.First();
                        vs.DeviceID = mcu.ExpandedMCU.ID;
                    }
                    catch (Exception ex)
                    {
                        r.ExceptionSample(ex.Message, "mcu " + vs.DeviceID + " not found in bsp");
                        Console.WriteLine("bsp have not mcu:" + vs.DeviceID);
                        continue;
                    }

                    if (testProbability < 1 && rng.NextDouble() > testProbability)
                    {
                        cnt++;
                        continue;
                    }

                    string mcuDir = Path.Combine(temporaryDirectory, "VendorSamples", vs.UserFriendlyName);
                    mcuDir += $"-{mcu.ExpandedMCU.ID}";
                    if (!Directory.Exists(mcuDir))
                    {
                        Directory.CreateDirectory(mcuDir);
                    }
                    DateTime start = DateTime.Now;

                    string[] hwSubstrings = new[]
                    {
                        @"\ARM_CM4F\port.c",
                        @"ARM_CM7\r0p1\port.c",
                        @"CM4_GCC.a",
                    };

                    if (vs.SourceFiles.FirstOrDefault(f => ContainsAnySubstrings(f, hwSubstrings)) != null)
                    {
                        if (vs.Configuration.MCUConfiguration != null)
                        {
                            var dict = PropertyDictionary2.ReadPropertyDictionary(vs.Configuration.MCUConfiguration);
                            dict["com.sysprogs.bspoptions.arm.floatmode"] = "-mfloat-abi=hard";
                            vs.Configuration.MCUConfiguration             = new PropertyDictionary2 {
                                Entries = dict.Select(kv => new PropertyDictionary2.KeyValue {
                                    Key = kv.Key, Value = kv.Value
                                }).ToArray()
                            };
                        }
                        else
                        {
                            vs.Configuration.MCUConfiguration = new PropertyDictionary2
                            {
                                Entries = new PropertyDictionary2.KeyValue[]
                                { new PropertyDictionary2.KeyValue {
                                      Key = "com.sysprogs.bspoptions.arm.floatmode", Value = "-mfloat-abi=hard"
                                  } }
                            };
                        }
                    }

                    vs.SourceFiles = vs.SourceFiles.Where(s => !IsNonGCCFile(vs, s)).ToArray();

                    var result = TestVendorSample(mcu, vs, mcuDir, samples);

                    Console.WriteLine($"[{(DateTime.Now - start).TotalMilliseconds:f0} msec]");

                    if (result == TestResult.Failed)
                    {
                        failed++;
                    }
                    else if (result == TestResult.Succeeded)
                    {
                        succeeded++;
                    }

                    r.LogTestResult(vs.UserFriendlyName, result);
                    cnt++;
                    Console.WriteLine("{0}: {1}% done ({2}/{3} projects, {4} failed)", vs.UserFriendlyName, (cnt * 100) / sampleCount, cnt, sampleCount, failed);
                }
                r.EndSample();
            }

            stats.Passed += succeeded;
            stats.Failed += failed;
            if (samples is ConstructedVendorSampleDirectory)
            {
                (samples as ConstructedVendorSampleDirectory).ToolchainDirectory = toolchainPath;
                (samples as ConstructedVendorSampleDirectory).BSPDirectory       = Path.GetFullPath(bspDir);
            }
            return(stats);
        }
Example #7
0
        static void GenerateBSP(string toolchainDir, string ccsDir)
        {
            string[] keys = null;

            string bspDir = toolchainDir + @"\msp430-bsp";

            Dictionary <string, Dictionary <string, string> > tiMCUs = new Dictionary <string, Dictionary <string, string> >(StringComparer.CurrentCultureIgnoreCase);

            foreach (var line in File.ReadAllLines(@"..\..\msp430.csv"))
            {
                string[] cells = line.Split(';');
                if (keys == null)
                {
                    keys = cells;
                    continue;
                }

                Dictionary <string, string> entry = new Dictionary <string, string>();

                for (int i = 0; i < cells.Length; i++)
                {
                    entry[keys[i]] = cells[i];
                }

                tiMCUs[cells[0]] = entry;
                int idx = cells[0].IndexOf('-');
                if (idx != -1)
                {
                    tiMCUs[cells[0].Substring(0, idx)] = entry;
                }
            }

            Regex rgLen    = new Regex(".*LENGTH = 0x([0-9a-fA-F]{4}).*");
            Regex rgOrigin = new Regex(".*ORIGIN = 0x([0-9a-fA-F]{4}).*");
            Regex rgPeriph = new Regex("__([^ ]+) = (0x[a-fA-F0-9]+);");

            List <string>    families = new List <string>();
            List <MCU>       MCUs     = new List <MCU>();
            List <MCUFamily> famList  = new List <MCUFamily>();

            Directory.CreateDirectory(bspDir);
            Directory.CreateDirectory(bspDir + "\\devices");

            XmlSerializer regSer = new XmlSerializer(typeof(MCUDefinition));

            string[] files = Directory.GetFiles(Path.Combine(toolchainDir, "include"), "*.h");

            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];

                var    proc    = new Process();
                string mcuName = Path.GetFileNameWithoutExtension(file).ToLower();

                proc.StartInfo.FileName               = toolchainDir + @"\bin\msp430-elf-gcc.exe";
                proc.StartInfo.Arguments              = $"-I. -E {mcuName}.h -o - -mmcu={mcuName}";
                proc.StartInfo.WorkingDirectory       = Path.Combine(toolchainDir, "include");
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = true;

                proc.Start();
                List <string> lines = new List <string>();
                for (; ;)
                {
                    var line = proc.StandardOutput.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    lines.Add(line);
                }

                proc.WaitForExit();
                if (proc.ExitCode != 0)
                {
                    continue;
                }

                List <HardwareRegister> regs = new List <HardwareRegister>();

                MCU mcu = new MCU();
                mcu.ID = mcuName;
                mcu.CompilationFlags.COMMONFLAGS = "-mmcu=" + mcuName;

                string ld = Path.ChangeExtension(file, ".ld");
                if (!File.Exists(ld))
                {
                    continue;
                }
                foreach (var line in File.ReadAllLines(ld))
                {
                    if (line.StartsWith("  RAM"))
                    {
                        var m = rgLen.Match(line);
                        mcu.RAMSize = int.Parse(m.Groups[1].ToString(), System.Globalization.NumberStyles.HexNumber);
                        m           = rgOrigin.Match(line);
                        mcu.RAMBase = uint.Parse(m.Groups[1].ToString(), System.Globalization.NumberStyles.HexNumber);
                    }
                    if (line.StartsWith("  ROM"))
                    {
                        var m = rgLen.Match(line);
                        mcu.FLASHSize = int.Parse(m.Groups[1].ToString(), System.Globalization.NumberStyles.HexNumber);
                        m             = rgOrigin.Match(line);
                        mcu.FLASHBase = uint.Parse(m.Groups[1].ToString(), System.Globalization.NumberStyles.HexNumber);
                    }
                }

                if (mcu.RAMSize == 0)
                {
                    throw new Exception("RAM size cannot be 0");
                }


                foreach (var line in lines)
                {
                    Regex rgRegister = new Regex("extern volatile (.*) ([^ ]+) __asm__\\(\"([^\"]+)\"\\)");

                    var m = rgRegister.Match(line);
                    if (!m.Success)
                    {
                        if (line.Contains("extern") && line.Contains("__asm__"))
                        {
                            throw new Exception("Suspicious line");
                        }
                        continue;
                    }

                    string type = m.Groups[1].Value;
                    string name = m.Groups[2].Value;
                    if (name.EndsWith("_H") || name.EndsWith("_L"))
                    {
                        continue;
                    }
                    if (!m.Groups[3].Value.StartsWith("0x"))
                    {
                        throw new Exception("Invalid addr for " + name);
                    }
                    ulong addr = ulong.Parse(m.Groups[3].Value.Substring(2), System.Globalization.NumberStyles.HexNumber);

                    HardwareRegister reg = new HardwareRegister();
                    // TODO: the registers are not all 8 bits
                    // According to some datasheets (not all were checked):
                    // 01FFh to 0100h -> 16 bits
                    // 0FFh to 010h -> 8bits
                    // 0Fh to 00h -> 8-bit SFR (special function register)
                    if (type == "unsigned char")
                    {
                        reg.SizeInBits = 8;
                    }
                    else if (type == "unsigned int")
                    {
                        reg.SizeInBits = 16;
                    }
                    else if (type == "unsigned long int")
                    {
                        reg.SizeInBits = 32;
                    }
                    else
                    {
                        throw new Exception("Unknown type");
                    }

                    reg.Name    = name;
                    reg.Address = m.Groups[3].Value;
                    regs.Add(reg);
                }

                string family = "Other";

                Dictionary <string, string> info;
                if (tiMCUs.TryGetValue(mcu.ID, out info))
                {
                    family = info["Description"];
                }

                int idx = families.IndexOf(family);
                if (idx == -1)
                {
                    idx = families.Count;
                    families.Add(family);
                    famList.Add(new MCUFamily {
                        ID = "fam_" + idx, UserFriendlyName = family, CompilationFlags = null
                    });
                }

                mcu.FamilyID          = "fam_" + idx.ToString();
                mcu.MCUDefinitionFile = "devices\\" + mcu.ID + ".xml";
                mcu.HierarchicalPath  = family;
                MCUs.Add(mcu);


                MCUDefinition desc = new MCUDefinition {
                    MCUName = mcu.ID, RegisterSets = new HardwareRegisterSet[] { new HardwareRegisterSet {
                                                                                     Registers = regs.ToArray()
                                                                                 } }
                };                                                                                                                                                                   //, Specs = specs };
                AdjustHardwareRegisters(ccsDir, mcu.ID, ref desc.RegisterSets);

                using (var fs = File.Create(bspDir + "\\" + mcu.MCUDefinitionFile + ".gz"))
                    using (var gs = new GZipStream(fs, CompressionMode.Compress))
                        regSer.Serialize(gs, desc);


                Console.WriteLine($"Processed {mcuName} ({i}/{files.Length}) [{i * 100 / files.Length}%]");
            }


            //Build the XML file
            BoardSupportPackage bsp = new BoardSupportPackage {
                GNUTargetID = "msp430", PackageID = "com.sysprogs.msp430.core", PackageDescription = "MSP430 MCUs"
            };

            bsp.SupportedMCUs       = MCUs.ToArray();
            bsp.MCUFamilies         = famList.ToArray();
            bsp.DebugMethodPackages = new string[] { "debuggers\\core", "debuggers\\mspdebug" };


            bsp.Examples = new string[] { "Samples\\LEDBlink" };

#if BSP_ADDITIONAL_GCC_FLAGS
            bsp.AdditionalGCCFlags = new PropertyList
            {
                PropertyGroups = new PropertyGroup[] { new PropertyGroup {
                                                           Name       = "MSP430 Options",
                                                           Properties = new PropertyEntry[] {
                                                               new PropertyEntry.Boolean {
                                                                   Name          = "Disable watchdog on startup",
                                                                   Description   = "Link the crt0 modules that disable the watchdog on startup",
                                                                   UniqueID      = "com.sysprogs.msp430.mdisable-watchdog",
                                                                   ValueForTrue  = "-mdisable-watchdog",
                                                                   ValueForFalse = "",
                                                               },
                                                               new PropertyEntry.Boolean {
                                                                   Name          = "Enable libcalls for shifts",
                                                                   Description   = "Use library routines for non-constant shifts",
                                                                   UniqueID      = "com.sysprogs.msp430.menable-libcall-shift",
                                                                   ValueForTrue  = "-menable-libcall-shift",
                                                                   ValueForFalse = "",
                                                               },
                                                               new PropertyEntry.Boolean {
                                                                   Name          = "Inline hardware multiplication",
                                                                   Description   = "Issue inline multiplication code for 32-bit integers",
                                                                   UniqueID      = "com.sysprogs.msp430.minline-hwmul",
                                                                   ValueForTrue  = "-minline-hwmul",
                                                                   ValueForFalse = "",
                                                               },
                                                               new PropertyEntry.Enumerated {
                                                                   Name           = "Interrupt vector count",
                                                                   Description    = "Specify number of interrupt vectors on chip:",
                                                                   UniqueID       = "com.sysprogs.msp430.mivcnt",
                                                                   GNUPrefix      = "-mivcnt=",
                                                                   SuggestionList = new PropertyEntry.Enumerated.Suggestion[]
                                                                   {
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "", UserFriendlyName = "(default)"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "16"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "32"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "64"
                                                                       },
                                                                   },
                                                                   AllowFreeEntry = true,
                                                               },
                                                               new PropertyEntry.Enumerated {
                                                                   Name           = "Hardware multiplier",
                                                                   Description    = "Define available hardware multiplier",
                                                                   UniqueID       = "com.sysprogs.msp430.mmpy",
                                                                   GNUPrefix      = "-mmpy=",
                                                                   SuggestionList = new PropertyEntry.Enumerated.Suggestion[]
                                                                   {
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "", UserFriendlyName = "(default)"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "16"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "16se"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "32"
                                                                       },
                                                                       new PropertyEntry.Enumerated.Suggestion {
                                                                           InternalValue = "32dw"
                                                                       },
                                                                   }
                                                               },
                                                               new PropertyEntry.Boolean {
                                                                   Name          = "No hardware multiplication in ISRs",
                                                                   Description   = "Assume interrupt routine does not do hardware multiplication",
                                                                   UniqueID      = "com.sysprogs.msp430.noint-hwmul",
                                                                   ValueForTrue  = "-noint-hwmul",
                                                                   ValueForFalse = "",
                                                               },
                                                               new PropertyEntry.Boolean {
                                                                   Name          = "Prologue space optimization",
                                                                   Description   = "Use subroutine call for function prologue/epilogue when possible",
                                                                   UniqueID      = "com.sysprogs.msp430.msave-prologue",
                                                                   ValueForTrue  = "-msave-prologue",
                                                                   ValueForFalse = "",
                                                               },
                                                           }
                                                       } }
            };
#endif

            XmlSerializer ser = new XmlSerializer(typeof(BoardSupportPackage), PropertyEntry.EntryTypes);
            using (var fs = File.Create(bspDir + "\\BSP.xml"))
                ser.Serialize(fs, bsp);

            //mcuSelector1.Reset();
            var lBsp = LoadedBSP.Load(new BSPSummary(bspDir), null);
            //mcuSelector1.AddBSP(lBsp);
            //embeddedDebugSettingsControl1.Reset();
            //embeddedDebugSettingsControl1.AddDebugMethods(lBsp.KnownDebugMethods);
        }
Example #8
0
        public static TestStatistics TestVendorSamples(VendorSampleDirectory samples, string bspDir, string temporaryDirectory, double testProbability = 1)
        {
            const string defaultToolchainID = "SysGCC-arm-eabi-5.3.0";
            var          toolchainPath      = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(defaultToolchainID);

            if (toolchainPath == null)
            {
                throw new Exception("Cannot locate toolchain path from registry");
            }

            var toolchain = LoadedToolchain.Load(Environment.ExpandEnvironmentVariables(toolchainPath), new ToolchainRelocationManager());
            var bsp       = LoadedBSP.Load(new BSPManager.BSPSummary(Environment.ExpandEnvironmentVariables(Path.GetFullPath(bspDir))), toolchain);

            TestStatistics stats = new TestStatistics();
            int            cnt = 0, failed = 0, succeeded = 0;

            LoadedBSP.LoadedMCU[] MCUs = bsp.MCUs.ToArray();
            string outputDir           = Path.Combine(temporaryDirectory, "VendorSamples");

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            int    sampleCount = samples.Samples.Length;
            Random rng         = new Random();

            using (var r = new TestResults(Path.Combine(temporaryDirectory, "bsptest.log")))
            {
                foreach (var vs in samples.Samples)
                {
                    LoadedBSP.LoadedMCU mcu;

                    try
                    {
                        var rgFilterID = new Regex(vs.DeviceID.Replace('x', '.'), RegexOptions.IgnoreCase);
                        mcu         = bsp.MCUs.Where(f => rgFilterID.IsMatch(f.ExpandedMCU.ID)).ToArray()?.First();
                        vs.DeviceID = mcu.ExpandedMCU.ID;
                    }
                    catch (Exception ex)
                    {
                        r.ExceptionSample(ex.Message, "mcu " + vs.DeviceID + " not found in bsp");
                        Console.WriteLine("bsp have not mcu:" + vs.DeviceID);
                        continue;
                    }

                    if (testProbability < 1 && rng.NextDouble() > testProbability)
                    {
                        cnt++;
                        continue;
                    }

                    bool   aflSoftFPU = true;
                    string mcuDir     = Path.Combine(temporaryDirectory, "VendorSamples", vs.UserFriendlyName);
                    if (!Directory.Exists(mcuDir))
                    {
                        Directory.CreateDirectory(mcuDir);
                    }
                    if (vs.UserFriendlyName.ToUpper().Contains("RTOS"))
                    {
                        aflSoftFPU = false;
                    }
                    DateTime start  = DateTime.Now;
                    var      result = TestVendorSample(mcu, vs, mcuDir, aflSoftFPU, samples);

                    Console.WriteLine($"[{(DateTime.Now - start).TotalMilliseconds:f0} msec]");

                    if (result == TestResult.Failed)
                    {
                        failed++;
                    }
                    else if (result == TestResult.Succeeded)
                    {
                        succeeded++;
                    }

                    r.LogTestResult(vs.UserFriendlyName, result);
                    cnt++;
                    Console.WriteLine("{0}: {1}% done ({2}/{3} projects, {4} failed)", vs.UserFriendlyName, (cnt * 100) / sampleCount, cnt, sampleCount, failed);
                }
            }

            stats.Passed += succeeded;
            stats.Failed += failed;
            if (samples is ConstructedVendorSampleDirectory)
            {
                (samples as ConstructedVendorSampleDirectory).ToolchainDirectory = toolchainPath;
                (samples as ConstructedVendorSampleDirectory).BSPDirectory       = Path.GetFullPath(bspDir);
            }
            return(stats);
        }
Example #9
0
        static void Main(string[] args)
        {
            string outputDir = Path.GetFullPath(@"..\..\Output");
            string dataDir   = Path.GetFullPath(@"..\..\data");

            Directory.CreateDirectory(outputDir);
            string mbedRoot = Path.Combine(outputDir, "mbed");

            List <KeyValuePair <Regex, string> > nameRules = new List <KeyValuePair <Regex, string> >();

            foreach (var line in File.ReadAllLines(Path.Combine(dataDir, "DeviceNameRules.txt")))
            {
                int idx = line.IndexOf('=');
                nameRules.Add(new KeyValuePair <Regex, string>(new Regex(line.Substring(0, idx).Trim()), line.Substring(idx + 1).Trim()));
            }

            bool regenerate = true;

            if (regenerate)
            {
                string gitExe    = (Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\BSPGenerators")?.GetValue("git") as string) ?? "git.exe";
                string pythonExe = (Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\BSPGenerators")?.GetValue("python") as string) ?? "python.exe";

                Process proc;
                if (Directory.Exists(mbedRoot))
                {
                    // Prevent pull fail due to modified files
                    proc = Process.Start(new ProcessStartInfo(gitExe, "reset --hard")
                    {
                        WorkingDirectory = mbedRoot, UseShellExecute = false
                    });
                    proc.WaitForExit();
                    if (proc.ExitCode != 0)
                    {
                        throw new Exception("Git reset command exited with code " + proc.ExitCode);
                    }
                    proc = Process.Start(new ProcessStartInfo(gitExe, "pull origin fix_5.2")
                    {
                        WorkingDirectory = mbedRoot, UseShellExecute = false
                    });
                }
                else
                {
                    proc = Process.Start(new ProcessStartInfo(gitExe, "clone https://github.com/oter/mbed-os.git -b fix_5.2 mbed")
                    {
                        WorkingDirectory = outputDir, UseShellExecute = false
                    });
                }
                proc.WaitForExit();
                if (proc.ExitCode != 0)
                {
                    throw new Exception("Git exited with code " + proc.ExitCode);
                }

                string sampleDir = Path.Combine(mbedRoot, "samples");
                if (Directory.Exists(sampleDir))
                {
                    Directory.Delete(sampleDir, true);
                }
                PathTools.CopyDirectoryRecursive(Path.Combine(dataDir, "samples"), sampleDir);

                ProcessStartInfo bspGenInfo = new ProcessStartInfo(pythonExe, Path.Combine(dataDir, "visualgdb_bsp.py") + " --alltargets");
                bspGenInfo.UseShellExecute = false;
                bspGenInfo.EnvironmentVariables["PYTHONPATH"] = mbedRoot;
                proc = Process.Start(bspGenInfo);
                proc.WaitForExit();

                if (proc.ExitCode != 0)
                {
                    throw new Exception("BSP generator exited with code " + proc.ExitCode);
                }
            }

            File.Copy(Path.Combine(dataDir, "stubs.cpp"), Path.Combine(mbedRoot, "stubs.cpp"), true);
            Dictionary <string, string> mcuDefs = new Dictionary <string, string>();
            var linkedBSPs = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\VisualGDB\EmbeddedBSPs\arm-eabi", "*.bsplink").Select(f => File.ReadAllText(f));

            foreach (var dir in Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\VisualGDB\EmbeddedBSPs\arm-eabi").Concat(linkedBSPs))
            {
                var anotherBSP = XmlTools.LoadObject <BoardSupportPackage>(Path.Combine(dir, "bsp.xml"));
                foreach (var mcu in anotherBSP.SupportedMCUs)
                {
                    if (mcu.MCUDefinitionFile != null)
                    {
                        mcuDefs[mcu.ID] = Path.Combine(dir, mcu.MCUDefinitionFile);
                    }
                }
            }

            string bspFile = Path.Combine(mbedRoot, "BSP.xml");
            var    bsp     = XmlTools.LoadObject <BoardSupportPackage>(bspFile);
            var    defDir  = Directory.CreateDirectory(Path.Combine(mbedRoot, "DeviceDefinitions"));

            foreach (var mcu in bsp.SupportedMCUs)
            {
                foreach (var rule in nameRules)
                {
                    var m = rule.Key.Match(mcu.ID);
                    if (m.Success)
                    {
                        string devRegex = rule.Value;
                        for (int i = 1; i < m.Groups.Count; i++)
                        {
                            devRegex = devRegex.Replace(@"\" + i, m.Groups[i].Value);
                        }

                        Regex  devRegexObj = new Regex(devRegex);
                        string definition  = null;
                        foreach (var dev in mcuDefs)
                        {
                            if (devRegexObj.IsMatch(dev.Key))
                            {
                                definition = dev.Value;
                            }
                        }

                        if (definition == null)
                        {
                            Console.WriteLine("Warning: cannot find device register definition for " + devRegex);
                        }
                        else
                        {
                            mcu.MCUDefinitionFile = "DeviceDefinitions/" + Path.GetFileName(definition);
                            File.Copy(definition + ".gz", Path.Combine(mbedRoot, mcu.MCUDefinitionFile + ".gz"), true);
                        }
                        break;
                    }
                }
            }
            ProduceBSPArchive(mbedRoot, bsp);

            var  testfFiles   = new TestInfo[] { new TestInfo("test_usbcd.xml", 0, 0), new TestInfo("test_ledblink_rtos.xml", 0, 0), new TestInfo("test_ledblink.xml", 0, 0), };
            bool performTests = true;

            if (performTests)
            {
                foreach (var test in testfFiles)
                {
                    Console.WriteLine("Testing BSP...");
                    var job = XmlTools.LoadObject <TestJob>(Path.Combine(dataDir, test.Filename));
                    if (job.ToolchainPath.StartsWith("["))
                    {
                        job.ToolchainPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue(job.ToolchainPath.Trim('[', ']'));
                        if (job.ToolchainPath == null)
                        {
                            throw new Exception("Cannot locate toolchain path from registry");
                        }
                    }
                    var toolchain = LoadedToolchain.Load(Environment.ExpandEnvironmentVariables(job.ToolchainPath), new ToolchainRelocationManager());
                    var lbsp      = LoadedBSP.Load(new BSPManager.BSPSummary(Environment.ExpandEnvironmentVariables(Path.Combine(outputDir, "mbed"))), toolchain);
                    var r         = StandaloneBSPValidator.Program.TestBSP(job, lbsp, Path.Combine(outputDir, "TestResults"));
                    test.Passed = r.Passed;
                    test.Failed = r.Failed;
                }

                foreach (var test in testfFiles)
                {
                    Console.WriteLine("Results for the test: " + test.Filename);
                    Console.WriteLine("Passed: " + test.Passed.ToString());
                    Console.WriteLine("Failed: " + test.Failed.ToString());
                    Console.WriteLine();
                }
            }
        }