Beispiel #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;
                    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;
        }