Esempio n. 1
0
        public static TestStatistics TestBSP(TestJob job, LoadedBSP bsp, string temporaryDirectory)
        {
            TestStatistics stats = new TestStatistics();

            Directory.CreateDirectory(temporaryDirectory);
            using (var r = new TestResults(Path.Combine(temporaryDirectory, "bsptest.log")))
            {
                LoadedBSP.LoadedMCU[] MCUs;
                if (job.DeviceRegex == null)
                {
                    MCUs = bsp.MCUs.ToArray();
                }
                else
                {
                    var rgFilter = new Regex(job.DeviceRegex);
                    MCUs = bsp.MCUs.Where(mcu => rgFilter.IsMatch(mcu.ExpandedMCU.ID)).ToArray();
                }

                if (job.SkippedDeviceRegex != null)
                {
                    var rg = new Regex(job.SkippedDeviceRegex);
                    MCUs = MCUs.Where(mcu => !rg.IsMatch(mcu.ExpandedMCU.ID)).ToArray();
                }

                var loadedRules   = job.RegisterRenamingRules?.Select(rule => new LoadedRenamingRule(rule))?.ToArray();
                var noValidateReg = job.NonValidatedRegisters;

                foreach (var sample in job.Samples)
                {
                    r.BeginSample(sample.Name);
                    int cnt = 0, failed = 0, succeeded = 0;

                    var effectiveMCUs = MCUs;
                    if (!string.IsNullOrEmpty(sample.DeviceRegex))
                    {
                        Regex rgDevice = new Regex(sample.DeviceRegex);
                        effectiveMCUs = MCUs.Where(mcu => rgDevice.IsMatch(mcu.ExpandedMCU.ID)).ToArray();
                    }

                    foreach (var mcu in effectiveMCUs)
                    {
                        if (string.IsNullOrEmpty(mcu.ExpandedMCU.ID))
                        {
                            throw new Exception("Invalid MCU ID!");
                        }

                        var extraParams = job.DeviceParameterSets?.FirstOrDefault(s => s.DeviceRegexObject?.IsMatch(mcu.ExpandedMCU.ID) == true);

                        string   mcuDir = Path.Combine(temporaryDirectory, mcu.ExpandedMCU.ID);
                        DateTime start  = DateTime.Now;
                        var      result = TestMCU(mcu, mcuDir + sample.TestDirSuffix, sample, extraParams, loadedRules, noValidateReg, job.UndefinedMacros);
                        Console.WriteLine($"[{(DateTime.Now - start).TotalMilliseconds:f0} msec]");
                        if (result == TestResult.Failed)
                        {
                            failed++;
                        }
                        else if (result == TestResult.Succeeded)
                        {
                            succeeded++;
                        }

                        r.LogTestResult(mcu.ExpandedMCU.ID, result);

                        cnt++;
                        Console.WriteLine("{0}: {1}% done ({2}/{3} devices, {4} failed)", sample.Name, (cnt * 100) / effectiveMCUs.Length, cnt, effectiveMCUs.Length, failed);
                    }

                    if ((succeeded + failed) == 0)
                    {
                        throw new Exception("Not a single MCU supports " + sample.Name);
                    }
                    r.EndSample();

                    stats.Passed += succeeded;
                    stats.Failed += failed;
                }
            }
            return(stats);
        }
Esempio n. 2
0
        public static TestStatistics TestBSP(TestJob job, LoadedBSP bsp, string temporaryDirectory)
        {
            TestStatistics stats = new TestStatistics();
            Directory.CreateDirectory(temporaryDirectory);
            using (var r = new TestResults(Path.Combine(temporaryDirectory, "bsptest.log")))
            {
                LoadedBSP.LoadedMCU[] MCUs;
                if (job.DeviceRegex == null)
                    MCUs = bsp.MCUs.ToArray();
                else
                {
                    var rgFilter = new Regex(job.DeviceRegex);
                    MCUs = bsp.MCUs.Where(mcu => rgFilter.IsMatch(mcu.ExpandedMCU.ID)).ToArray();
                }

                if (job.SkippedDeviceRegex != null)
                {
                    var rg = new Regex(job.SkippedDeviceRegex);
                    MCUs = MCUs.Where(mcu => !rg.IsMatch(mcu.ExpandedMCU.ID)).ToArray();
                }

                var loadedRules = job.RegisterRenamingRules?.Select(rule => new LoadedRenamingRule(rule))?.ToArray();
                var noValidateReg = job.NonValidatedRegisters;

                foreach (var sample in job.Samples)
                {
                    r.BeginSample(sample.Name);
                    int cnt = 0, failed = 0, succeeded = 0;
                    foreach (var mcu in MCUs)
                    {
                        if (string.IsNullOrEmpty(mcu.ExpandedMCU.ID))
                            throw new Exception("Invalid MCU ID!");

                        var extraParams = job.DeviceParameterSets?.FirstOrDefault(s => s.DeviceRegexObject?.IsMatch(mcu.ExpandedMCU.ID) == true);

                        string mcuDir = Path.Combine(temporaryDirectory, mcu.ExpandedMCU.ID);
                        DateTime start = DateTime.Now;
                        var result = TestMCU(mcu, mcuDir + sample.TestDirSuffix, sample, extraParams, loadedRules, noValidateReg);
                        Console.WriteLine($"[{(DateTime.Now - start).TotalMilliseconds:f0} msec]");
                        if (result == TestResult.Failed)
                            failed++;
                        else if (result == TestResult.Succeeded)
                            succeeded++;

                        r.LogTestResult(mcu.ExpandedMCU.ID, result);

                        cnt++;
                        Console.WriteLine("{0}: {1}% done ({2}/{3} devices, {4} failed)", sample.Name, (cnt * 100) / MCUs.Length, cnt, MCUs.Length, failed);
                    }

                    if (succeeded == 0)
                        throw new Exception("Not a single MCU supports " + sample.Name);
                    r.EndSample();

                    stats.Passed += succeeded;
                    stats.Failed += failed;
                }
            }
            return stats;
        }
Esempio n. 3
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);
        }