Exemplo n.º 1
0
        public void ShouldThrowExceptions()
        {
            // null context
            Assert.Throws <ArgumentNullException>(() => { AnalysisModelProcessor.GetAnalysisModelProcessor(null); });

            Assert.True(File.Exists(this.mgaFile), "Project file does not exist.");
            string ProjectConnStr = "MGA=" + Path.GetFullPath(this.mgaFile);

            MgaProject project = new MgaProject();

            project.OpenEx(ProjectConnStr, "CyPhyML", null);
            try
            {
                var terr = project.BeginTransactionInNewTerr();
                var componentAssembly = project.RootFolder.GetDescendantFCOs(project.CreateFilter()).OfType <MgaModel>().FirstOrDefault(x => x.MetaBase.Name == "ComponentAssembly");

                Assert.True(componentAssembly != null, string.Format("{0} project must contain one component assembly.", Path.GetFullPath(this.mgaFile)));

                // invalid context
                Assert.Throws <AnalysisModelContextNotSupportedException>(() => { AnalysisModelProcessor.GetAnalysisModelProcessor(componentAssembly); });
            }
            finally
            {
                project.AbortTransaction();
                project.Close(true);
            }
        }
Exemplo n.º 2
0
        public void Run()
        {
            if (string.IsNullOrEmpty(this.WorkingDirectory) ||
                Directory.Exists(this.WorkingDirectory) == false)
            {
                // nothing needs to be done.
                return;
            }

            // TODO: exception handling...

            // get manifest file
            string manifestFile = Path.Combine(this.WorkingDirectory, "manifest.sot.json");

            if (File.Exists(manifestFile) == false)
            {
                Trace.TraceError("{0} file does not exist", manifestFile);
                return;
            }

            // this could fail... exception handling!
            sotConfig = Newtonsoft.Json.JsonConvert.DeserializeObject <CyPhySoT.SotConfig>(File.ReadAllText(manifestFile));

            // get mga filename
            string mgaFileName = Path.Combine(this.WorkingDirectory, sotConfig.ProjectFileName);

            if (File.Exists(mgaFileName) == false)
            {
                Trace.TraceError("{0} file does not exist", mgaFileName);
                return;
            }

            this.ProjectConnStr = "MGA=" + mgaFileName;

            Semaphore sem = null;

            if (criticalSection.TryGetValue(this.ProjectConnStr, out sem) == false)
            {
                criticalSection[this.ProjectConnStr] = new Semaphore(1, 1);
            }

            // Load GME model
            this.OpenProject();

            if (sotConfig.MultiJobRun)
            {
                Project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_READ_ONLY);
                try
                {
                    this.TestBenches = GetMultiJobRunTestBenches(CurrentObj, Path.GetDirectoryName(sotConfig.ProjectFileName));
                }
                finally
                {
                    Project.AbortTransaction();
                }
            }
            else
            {
                CyPhySoT.CyPhySoTInterpreter sotInterpreter = new CyPhySoT.CyPhySoTInterpreter();
                this.TestBenches = sotInterpreter.GetTestbenchesFromModel(this.Project, (MgaModel)this.CurrentObj, Path.GetDirectoryName(this.WorkingDirectory));
                Project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
                try
                {
                    // replace tb in TestBenches that corresponds to the MultiJobRun with the tbs from GetMultiJobRunTestBenches
                    foreach (var tb in TestBenches.ToList <CyPhySoT.TestBench>())
                    {
                        var modelProcessor = AnalysisModelProcessor.GetAnalysisModelProcessor((IMgaModel)tb.CurrentObj);
                        if (modelProcessor is MultiJobRunProcessor)
                        {
                            List <CyPhySoT.TestBench> multiTbs = GetMultiJobRunTestBenches(tb.CurrentObj, tb.OutputDirectory);
                            foreach (var upstreamTb in tb.UpstreamTestBenches)
                            {
                                upstreamTb.DownstreamTestBenches.Remove(tb);
                                upstreamTb.DownstreamTestBenches.Add(multiTbs[0]);
                                multiTbs[0].UpstreamTestBenches.Add(upstreamTb);
                            }
                            foreach (var downstreamTb in tb.DownstreamTestBenches)
                            {
                                downstreamTb.UpstreamTestBenches.Remove(tb);
                                downstreamTb.UpstreamTestBenches.Add(multiTbs[multiTbs.Count - 1]);
                                multiTbs[multiTbs.Count - 1].DownstreamTestBenches.Add(downstreamTb);
                            }
                            this.TestBenches.AddRange(multiTbs);
                            this.TestBenches.Remove(tb);
                        }
                    }
                }
                finally
                {
                    Project.AbortTransaction();
                }
            }

            // TODO: update value flow!

            // Test bench/job map
            foreach (var testbench in this.TestBenches)
            {
                JobImpl job = new JobImpl(this.Server);

                this.TestBenchJobMap.Add(testbench, job);
            }

            try
            {
                // propagate the values between test benches
                PropagateValueFlow();
            }
            catch (JobFailure ex)
            {
                // FIXME: add some GUI notification
                string failed_txt = Path.Combine(this.WorkingDirectory, "_FAILED.txt");
                File.WriteAllText(failed_txt, String.Format("SoT {0} failed: {1}", this.sotName, ex.ToString()));
                this.CloseProject();
                return;
            }

            // get all testbenches from sot that can be run without dependency
            foreach (var testbench in this.TestBenches.Where(x => x.UpstreamTestBenches.Count == 0))
            {
                // call interpreters for this test bench and post it to the job manager
                RunTestBenchAndStart(testbench);
            }

            this.CloseProject();
        }