DoGenerateProjectFromEmbeddedSample() public method

public DoGenerateProjectFromEmbeddedSample ( ConfiguredSample sample, bool plainC, string>.Dictionary bspDict ) : void
sample ConfiguredSample
plainC bool
bspDict string>.Dictionary
return void
Exemplo n.º 1
0
        private static TestResult TestMCU(LoadedBSP.LoadedMCU mcu, string mcuDir, TestedSample sample, DeviceParameterSet extraParameters, LoadedRenamingRule[] renameRules, string[] nonValidateReg, string[] pUndefinedMacros)
        {
            const int RepeatCount = 20;

            for (var i = 0; i < RepeatCount; ++i)
            {
                if (!Directory.Exists(mcuDir))
                {
                    break;
                }
                Console.WriteLine("Deleting " + mcuDir + "...");
                Directory.Delete(mcuDir, true);
                if (i == RepeatCount - 1)
                {
                    throw new Exception("Cannot remove folder!");
                }
                Thread.Sleep(50);
            }
            for (var i = 0; i < RepeatCount; ++i)
            {
                if (Directory.Exists(mcuDir))
                {
                    break;
                }
                Directory.CreateDirectory(mcuDir);
                if (i == RepeatCount - 1)
                {
                    throw new Exception("Cannot create folder!");
                }
                Thread.Sleep(50);
            }

            var configuredMCU = new LoadedBSP.ConfiguredMCU(mcu, GetDefaultPropertyValues(mcu.ExpandedMCU.ConfigurableProperties));

            if (configuredMCU.ExpandedMCU.FLASHSize == 0)
            {
                configuredMCU.Configuration["com.sysprogs.bspoptions.primary_memory"] = "sram";
            }

            var samples = mcu.BSP.GetSamplesForMCU(mcu.ExpandedMCU.ID, false);

            LoadedBSP.LoadedSample sampleObj;
            if (string.IsNullOrEmpty(sample.Name))
            {
                sampleObj = samples[0];
            }
            else
            {
                sampleObj = samples.FirstOrDefault(s => s.Sample.Name == sample.Name);
            }

            if (sampleObj == null)
            {
                if (sample.SkipIfNotFound)
                {
                    Directory.Delete(mcuDir, true);
                    return(TestResult.Skipped);
                }
                else
                {
                    throw new Exception("Cannot find sample: " + sample.Name);
                }
            }

            string[] frameworks = sampleObj.Sample.RequiredFrameworks ?? new string[0];


            //frameworkCfg["com.sysprogs.bspoptions.stm32.freertos.heap"] = "heap_4";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.freertos.portcore"] = "CM0";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.usb.devclass"] = "CDC";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.usb.speed"] = "FS";

            var configuredSample = new ConfiguredSample
            {
                Sample     = sampleObj,
                Parameters = GetDefaultPropertyValues(sampleObj.Sample.ConfigurableProperties),
                Frameworks = (sampleObj.Sample.RequiredFrameworks == null) ? null :
                             sampleObj.Sample.RequiredFrameworks.Select(fwId =>
                {
                    return(configuredMCU.BSP.BSP.Frameworks.First(fwO => fwO.ID == fwId || fwO.ClassID == fwId && fwO.IsCompatibleWithMCU(configuredMCU.ExpandedMCU.ID)));
                }).ToList(),
                FrameworkParameters = new Dictionary <string, string>(),
            };


            ApplyConfiguration(configuredMCU.Configuration, extraParameters?.MCUConfiguration, sample.MCUConfiguration);

            //configuredSample.Parameters["com.sysprogs.examples.ledblink.LEDPORT"] = "GPIOA";
            //configuredSample.Parameters["com.sysprogs.examples.stm32.LEDPORT"] = "GPIOA";
            //configuredSample.Parameters["com.sysprogs.examples.stm32.freertos.heap_size"] = "0";

            var bspDict = configuredMCU.BuildSystemDictionary(SystemDirs);

            bspDict["PROJECTNAME"] = "test";

            if (configuredSample.Frameworks != null)
            {
                foreach (var fw in configuredSample.Frameworks)
                {
                    if (fw.AdditionalSystemVars != null)
                    {
                        foreach (var kv in fw.AdditionalSystemVars)
                        {
                            bspDict[kv.Key] = kv.Value;
                        }
                    }
                    if (fw.ConfigurableProperties != null)
                    {
                        var defaultFwConfig = GetDefaultPropertyValues(fw.ConfigurableProperties);
                        if (defaultFwConfig != null)
                        {
                            foreach (var kv in defaultFwConfig)
                            {
                                configuredSample.FrameworkParameters[kv.Key] = kv.Value;
                            }
                        }
                    }
                }
            }

            if (sampleObj.Sample?.DefaultConfiguration?.Entries != null)
            {
                foreach (var kv in sampleObj.Sample.DefaultConfiguration.Entries)
                {
                    configuredSample.FrameworkParameters[kv.Key] = kv.Value;
                }
            }

            ApplyConfiguration(configuredSample.FrameworkParameters, extraParameters?.FrameworkConfiguration, sample.FrameworkConfiguration);
            ApplyConfiguration(configuredSample.Parameters, extraParameters?.SampleConfiguration, sample.SampleConfiguration);

            var prj = new GeneratedProject(mcuDir, configuredMCU, frameworks)
            {
                DataSections = sample.DataSections
            };

            prj.DoGenerateProjectFromEmbeddedSample(configuredSample, false, bspDict);
            Dictionary <string, bool> frameworkIDs = new Dictionary <string, bool>();

            if (frameworks != null)
            {
                foreach (var fw in frameworks)
                {
                    frameworkIDs[fw] = true;
                }
            }
            if (sample.AdditionalFrameworks != null)
            {
                foreach (var fw in sample.AdditionalFrameworks)
                {
                    frameworkIDs[fw] = true;
                }
            }

            prj.AddBSPFilesToProject(bspDict, configuredSample.FrameworkParameters, frameworkIDs);
            var flags = prj.GetToolFlags(bspDict, configuredSample.FrameworkParameters, frameworkIDs);

            flags.COMMONFLAGS += " -save-temps ";
            Dictionary <string, bool> sourceExtensions = new Dictionary <string, bool>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var ext in sample.SourceFileExtensions.Split(';'))
            {
                sourceExtensions[ext] = true;
            }

            return(BuildAndRunValidationJob(mcu, mcuDir, sample.ValidateRegisters, renameRules, prj, flags, sourceExtensions, nonValidateReg, pUndefinedMacros));
        }
Exemplo n.º 2
0
        private static TestResult TestMCU(LoadedBSP.LoadedMCU mcu, string mcuDir, TestedSample sample, DeviceParameterSet extraParameters, LoadedRenamingRule[] renameRules, string[] nonValidateReg)
        {
            const int RepeatCount = 20;
            for (var i = 0; i < RepeatCount; ++i)
            {
                if (!Directory.Exists(mcuDir))
                {
                    break;
                }
                Console.WriteLine("Deleting " + mcuDir + "...");
                Directory.Delete(mcuDir, true);
                if (i == RepeatCount - 1)
                {
                    throw new Exception("Cannot remove folder!");
                }
                Thread.Sleep(50);
            }
            for (var i = 0; i < RepeatCount; ++i)
            {
                if (Directory.Exists(mcuDir))
                {
                    break;
                }
                Directory.CreateDirectory(mcuDir);
                if (i == RepeatCount - 1)
                {
                    throw new Exception("Cannot create folder!");
                }
                Thread.Sleep(50);
            }

            var configuredMCU = new LoadedBSP.ConfiguredMCU(mcu, GetDefaultPropertyValues(mcu.ExpandedMCU.ConfigurableProperties));
            if (configuredMCU.ExpandedMCU.FLASHSize == 0)
            {
                configuredMCU.Configuration["com.sysprogs.bspoptions.primary_memory"] = "sram";
            }

            var samples = mcu.BSP.GetSamplesForMCU(mcu.ExpandedMCU.ID, false);
            LoadedBSP.LoadedSample sampleObj;
            if (string.IsNullOrEmpty(sample.Name))
                sampleObj = samples[0];
            else
                sampleObj = samples.FirstOrDefault(s => s.Sample.Name == sample.Name);

            if (sampleObj == null)
            {
                if (sample.SkipIfNotFound)
                {
                    Directory.Delete(mcuDir, true);
                    return TestResult.Skipped;
                }
                else
                    throw new Exception("Cannot find sample: " + sample.Name);
            }

            string[] frameworks = sampleObj.Sample.RequiredFrameworks ?? new string[0];

            //frameworkCfg["com.sysprogs.bspoptions.stm32.freertos.heap"] = "heap_4";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.freertos.portcore"] = "CM0";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.usb.devclass"] = "CDC";
            //frameworkCfg["com.sysprogs.bspoptions.stm32.usb.speed"] = "FS";

            var configuredSample = new ConfiguredSample
            {
                Sample = sampleObj,
                Parameters = GetDefaultPropertyValues(sampleObj.Sample.ConfigurableProperties),
                Frameworks = (sampleObj.Sample.RequiredFrameworks == null) ? null :
                sampleObj.Sample.RequiredFrameworks.Select(fwId =>
                {
                    return configuredMCU.BSP.BSP.Frameworks.First(fwO => fwO.ID == fwId || fwO.ClassID == fwId && fwO.IsCompatibleWithMCU(configuredMCU.ExpandedMCU.ID));
                }).ToList(),
                FrameworkParameters = new Dictionary<string, string>(),
            };

            ApplyConfiguration(configuredMCU.Configuration, extraParameters?.MCUConfiguration, sample.MCUConfiguration);

            //configuredSample.Parameters["com.sysprogs.examples.ledblink.LEDPORT"] = "GPIOA";
            //configuredSample.Parameters["com.sysprogs.examples.stm32.LEDPORT"] = "GPIOA";
            //configuredSample.Parameters["com.sysprogs.examples.stm32.freertos.heap_size"] = "0";

            var bspDict = configuredMCU.BuildSystemDictionary(new BSPManager(), null);
            bspDict["PROJECTNAME"] = "test";

            if (configuredSample.Frameworks != null)
                foreach (var fw in configuredSample.Frameworks)
                {
                    if (fw.AdditionalSystemVars != null)
                        foreach (var kv in fw.AdditionalSystemVars)
                            bspDict[kv.Key] = kv.Value;
                    if (fw.ConfigurableProperties != null)
                    {
                        var defaultFwConfig = GetDefaultPropertyValues(fw.ConfigurableProperties);
                        if (defaultFwConfig != null)
                            foreach (var kv in defaultFwConfig)
                                configuredSample.FrameworkParameters[kv.Key] = kv.Value;
                    }
                }

            if (sampleObj.Sample?.DefaultConfiguration?.Entries != null)
                foreach (var kv in sampleObj.Sample.DefaultConfiguration.Entries)
                    configuredSample.FrameworkParameters[kv.Key] = kv.Value;

            ApplyConfiguration(configuredSample.FrameworkParameters, extraParameters?.FrameworkConfiguration, sample.FrameworkConfiguration);
            ApplyConfiguration(configuredSample.Parameters, extraParameters?.SampleConfiguration, sample.SampleConfiguration);

            var prj = new GeneratedProject(mcuDir, configuredMCU, frameworks);
            prj.DoGenerateProjectFromEmbeddedSample(configuredSample, false, bspDict);
            Dictionary<string, bool> frameworkIDs = new Dictionary<string, bool>();
            if (frameworks != null)
                foreach (var fw in frameworks)
                    frameworkIDs[fw] = true;
            if (sample.AdditionalFrameworks != null)
                foreach (var fw in sample.AdditionalFrameworks)
                    frameworkIDs[fw] = true;

            prj.AddBSPFilesToProject(bspDict, configuredSample.FrameworkParameters, frameworkIDs);
            var flags = prj.GetToolFlags(bspDict, configuredSample.FrameworkParameters, frameworkIDs);

            Dictionary<string, bool> sourceExtensions = new Dictionary<string, bool>(StringComparer.InvariantCultureIgnoreCase);
            foreach (var ext in sample.SourceFileExtensions.Split(';'))
                sourceExtensions[ext] = true;

            return BuildAndRunValidationJob(mcu, mcuDir, sample.ValidateRegisters, renameRules, prj, flags, sourceExtensions, nonValidateReg);
        }
Exemplo n.º 3
0
        public static TestResult TestSingleSample(LoadedBSP.LoadedSample sampleObj,
                                                  LoadedBSP.LoadedMCU mcu,
                                                  string testDirectory,
                                                  TestedSample sample,
                                                  DeviceParameterSet extraParameters,
                                                  RegisterValidationParameters registerValidationParameters,
                                                  BSPValidationFlags validationFlags = BSPValidationFlags.None)
        {
            CreateEmptyDirectoryForTestingMCU(testDirectory);

            var configuredMCU = new LoadedBSP.ConfiguredMCU(mcu, GetDefaultPropertyValues(mcu.ExpandedMCU.ConfigurableProperties));

            if (configuredMCU.ExpandedMCU.FLASHSize == 0)
            {
                configuredMCU.Configuration["com.sysprogs.bspoptions.primary_memory"] = "sram";
            }

            var configuredSample = new ConfiguredSample
            {
                Sample     = sampleObj,
                Parameters = GetDefaultPropertyValues(sampleObj.Sample.ConfigurableProperties),
                Frameworks = (sampleObj.Sample.RequiredFrameworks == null) ? null :
                             sampleObj.Sample.RequiredFrameworks.Select(fwId =>
                {
                    return(configuredMCU.BSP.BSP.Frameworks.First(fwO => fwO.ID == fwId || fwO.ClassID == fwId && fwO.IsCompatibleWithMCU(configuredMCU.ExpandedMCU.ID)));
                }).ToList(),
                FrameworkParameters = new Dictionary <string, string>(),
            };

            ApplyConfiguration(configuredMCU.Configuration, extraParameters?.MCUConfiguration, sample.MCUConfiguration);

            var bspDict = configuredMCU.BuildSystemDictionary(default(SystemDirectories));

            bspDict["PROJECTNAME"] = "test";

            if (configuredSample.Frameworks != null)
            {
                foreach (var fw in configuredSample.Frameworks)
                {
                    if (fw.AdditionalSystemVars != null)
                    {
                        foreach (var kv in fw.AdditionalSystemVars)
                        {
                            bspDict[kv.Key] = kv.Value;
                        }
                    }
                    if (fw.ConfigurableProperties != null)
                    {
                        var defaultFwConfig = GetDefaultPropertyValues(fw.ConfigurableProperties);
                        if (defaultFwConfig != null)
                        {
                            foreach (var kv in defaultFwConfig)
                            {
                                configuredSample.FrameworkParameters[kv.Key] = kv.Value;
                            }
                        }
                    }
                }
            }

            if (sampleObj.Sample?.DefaultConfiguration?.Entries != null)
            {
                foreach (var kv in sampleObj.Sample.DefaultConfiguration.Entries)
                {
                    configuredSample.FrameworkParameters[kv.Key] = kv.Value;
                }
            }

            ApplyConfiguration(configuredSample.FrameworkParameters, extraParameters?.FrameworkConfiguration, sample.FrameworkConfiguration);
            ApplyConfiguration(configuredSample.Parameters, extraParameters?.SampleConfiguration, sample.SampleConfiguration);

            Dictionary <string, bool> frameworkIDs = new Dictionary <string, bool>();

            foreach (var fw in sampleObj.Sample.RequiredFrameworks ?? new string[0])
            {
                frameworkIDs[fw] = true;
            }
            foreach (var fw in sample.AdditionalFrameworks ?? new string[0])
            {
                frameworkIDs[fw] = true;
            }

            var prj = new GeneratedProject(testDirectory, configuredMCU, frameworkIDs.Keys.ToArray())
            {
                DataSections = sample.DataSections
            };

            prj.DoGenerateProjectFromEmbeddedSample(configuredSample, false, bspDict);

            prj.AddBSPFilesToProject(bspDict, configuredSample.FrameworkParameters, frameworkIDs);
            var flags = prj.GetToolFlags(bspDict, configuredSample.FrameworkParameters, frameworkIDs);

            //  if(sampleObj.Sample.LinkerScript!=null)
            //     flags.LinkerScript = sampleObj.Sample.LinkerScript;

            if (!string.IsNullOrEmpty(configuredSample.Sample.Sample.LinkerScript))
            {
                flags.LinkerScript = VariableHelper.ExpandVariables(configuredSample.Sample.Sample.LinkerScript, bspDict, configuredSample.FrameworkParameters);
            }

            if (!string.IsNullOrEmpty(configuredSample.Sample.Sample.CLanguageStandard))
            {
                flags.CFLAGS += $" -std={configuredSample.Sample.Sample.CLanguageStandard}";
            }
            if (!string.IsNullOrEmpty(configuredSample.Sample.Sample.CPPLanguageStandard))
            {
                flags.CXXFLAGS += $" -std={configuredSample.Sample.Sample.CPPLanguageStandard}";
            }

            flags.COMMONFLAGS += " -save-temps ";
            Dictionary <string, bool> sourceExtensions = new Dictionary <string, bool>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var ext in sample.SourceFileExtensions.Split(';'))
            {
                sourceExtensions[ext] = true;
            }

            Console.WriteLine("Building {0}...", Path.GetFileName(testDirectory));
            return(BuildAndRunValidationJob(mcu, testDirectory, prj, flags, sourceExtensions, null, sample.ValidateRegisters ? registerValidationParameters : null, validationFlags));
        }