public void TestAddedNodes01()
        {
            List <string> codes = new List <string>()
            {
                "a = 1;"
            };

            Guid           guid  = System.Guid.NewGuid();
            List <Subtree> added = new List <Subtree>();

            added.Add(CreateSubTreeFromCode(guid, codes[0]));

            var syncData = new GraphSyncData(null, added, null);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(core);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List <string> expectedCode = new List <string>()
            {
                "a = 1;"
            };
            List <AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1   = astList[n];
                AssociativeNode node2   = expectedAstList[n];
                bool            isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
        public void TestInstructionStreamMemory_SimpleWorkflow01()
        {
            List <string> codes = new List <string>()
            {
                "a = 1;",
                "a = 2;"
            };

            Guid guid = System.Guid.NewGuid();

            // First run
            // a = 1
            List <Subtree> added = new List <Subtree>();

            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]));
            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            // Modify
            // a = 2
            List <Subtree> modified = new List <Subtree>();

            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]));
            syncData = new GraphSyncData(null, null, modified);
            liverunner.UpdateGraph(syncData);
            instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();

            Assert.AreEqual(instrStreamStart, instrStreamEnd);
        }
Exemple #3
0
        private bool VerifyGraphSyncData(IEnumerable <NodeModel> nodes)
        {
            GraphSyncData graphSyncdata = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = new HashSet <Guid>(
                nodes.Where(n => n.NeedsForceExecution)
                .Select(n => n.GUID));

            if (reExecuteNodesIds.Any())
            {
                for (int i = 0; i < graphSyncdata.ModifiedSubtrees.Count; ++i)
                {
                    var st = graphSyncdata.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        Subtree newSt = new Subtree(st.AstNodes, st.GUID);
                        newSt.ForceExecution = true;
                        graphSyncdata.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if (graphSyncdata.AddedSubtrees.Any() || graphSyncdata.ModifiedSubtrees.Any() || graphSyncdata.DeletedSubtrees.Any())
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(graphSyncdata);
                }
                return(true);
            }

            return(false);
        }
Exemple #4
0
        /// <summary>
        ///  This is called on the main thread from PreviewGraphSyncData
        ///  to generate the list of node id's that will be executed on the next run
        /// </summary>
        /// <param name="updatedNodes">The updated nodes.</param>
        /// <param name="verboseLogging"></param>
        /// <returns>This method returns the list of all reachable node id's from the given
        /// updated nodes</returns>
        internal List <Guid> PreviewGraphSyncData(IEnumerable <NodeModel> updatedNodes, bool verboseLogging)
        {
            if (updatedNodes == null)
            {
                return(null);
            }

            var tempSyncDataManager = syncDataManager.Clone();
            var activeNodes         = updatedNodes.Where(n => n.State != ElementState.Error);

            if (activeNodes.Any())
            {
                astBuilder.CompileToAstNodes(activeNodes, CompilationContext.PreviewGraph, verboseLogging);
            }

            GraphSyncData graphSyncdata    = syncDataManager.GetSyncData();
            List <Guid>   previewGraphData = this.liveRunnerServices.PreviewGraph(graphSyncdata, verboseLogging);

            syncDataManager = tempSyncDataManager;

            lock (previewGraphQueue)
            {
                previewGraphQueue.Enqueue(previewGraphData);
            }

            return(previewGraphQueue.Dequeue());
        }
Exemple #5
0
        /// <summary>
        /// Call this method to intialize a CompileCustomNodeAsyncTask with an
        /// EngineController and an GraphSyncData that is required to compile the
        /// associated custom node.
        /// </summary>
        /// <param name="initParams">Input parameters required for custom node
        /// graph updates.</param>
        /// <returns>Returns true if GraphSyncData is not empty and that the
        /// CompileCustomNodeAsyncTask should be scheduled for execution. Returns
        /// false otherwise.</returns>
        ///
        internal bool Initialize(CompileCustomNodeParams initParams)
        {
            if (initParams == null)
            {
                throw new ArgumentNullException("initParams");
            }

            engineController = initParams.EngineController;
            graphSyncData    = initParams.SyncData;

            if (engineController == null)
            {
                throw new ArgumentNullException("engineController");
            }
            if (graphSyncData == null)
            {
                throw new ArgumentNullException("graphSyncData");
            }

            var added    = graphSyncData.AddedSubtrees;
            var deleted  = graphSyncData.DeletedSubtrees;
            var modified = graphSyncData.ModifiedSubtrees;

            // Returns true if there is any actual data.
            return((added != null && added.Count > 0) ||
                   (modified != null && modified.Count > 0) ||
                   (deleted != null && deleted.Count > 0));
        }
Exemple #6
0
        public void TestPreviewModify1Node02()
        {
            List <string> codes = new List <string>()
            {
                // guid1
                @"
                    a = 1; 
                ",
                // guid2
                @"
                    x = a; 
                    y = x;
                ",
                // guid3
                @"
                    z = a; 
                ",
                // guid1
                @"
                    a = 10; 
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();
            Guid guid3 = System.Guid.NewGuid();

            // Create and run the graph
            ProtoScript.Runners.LiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();
            List <Subtree> added = new List <Subtree>();

            added.Add(CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(CreateSubTreeFromCode(guid2, codes[1]));
            added.Add(CreateSubTreeFromCode(guid3, codes[2]));
            var syncData = new GraphSyncData(null, added, null);

            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;]
            List <Subtree> modified = new List <Subtree>();

            modified.Add(CreateSubTreeFromCode(guid1, codes[3]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get the preview guids (affected graphs)
            List <Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List <Guid> expectedGuid = new List <Guid> {
                guid2, guid3
            };

            AssertPreview(reachableGuidList, expectedGuid, 2);
        }
Exemple #7
0
        /// <summary>
        /// This method is called by UpdateGraphAsyncTask in the context of
        /// ISchedulerThread to kick start an update through LiveRunner.
        /// </summary>
        /// <param name="graphSyncData">The GraphSyncData that was generated by
        /// a prior call to ComputeSyncData at the time UpdateGraphAsyncTask was
        /// scheduled.</param>
        ///
        public void UpdateGraphImmediate(GraphSyncData graphSyncData)
        {
            // NOTE: We will not attempt to catch any unhandled exception from
            // within the execution. Such exception, if any, will be caught by
            // DynamoScheduler.ProcessTaskInternal.

            liveRunnerServices.UpdateGraph(graphSyncData);
        }
        /// <summary>
        /// Update graph with graph sync data.
        /// </summary>
        /// <param name="graphData"></param>
        /// <param name="verboseLogging"></param>
        internal void UpdateGraph(GraphSyncData graphData, bool verboseLogging)
        {
            if (verboseLogging)
            {
                Log("LRS.UpdateGraph: " + graphData);
            }

            liveRunner.UpdateGraph(graphData);
        }
Exemple #9
0
        /// <summary>
        /// Update graph with graph sync data.
        /// </summary>
        /// <param name="graphData"></param>
        public void UpdateGraph(GraphSyncData graphData)
        {
            if (dynamoModel.DebugSettings.VerboseLogging)
            {
                dynamoModel.Logger.Log("LRS.UpdateGraph: " + graphData);
            }

            liveRunner.UpdateGraph(graphData);
        }
        /// <summary>
        /// Preview graph with graph sync data.
        /// </summary>
        /// <param name="graphData"></param>
        internal List <Guid> PreviewGraph(GraphSyncData graphData, bool verboseLogging)
        {
            if (verboseLogging)
            {
                Log("LRS.PreviewGraph: " + graphData);
            }

            return(liveRunner.PreviewGraph(graphData));
        }
Exemple #11
0
            public void SerialisationDataLoadSave()
            {
                //Test to ensure that the first time the code is executed the wasTraced attribute is marked as false
                //and the secodn time it is marked as true


                string setupCode =
                    @"import(""FFITarget.dll""); 
x = 0; 
mtcA = IncrementerTracedClass.IncrementerTracedClass(x); 
mtcAID = mtcA.ID;
mtcAWasTraced = mtcA.WasCreatedWithTrace(); ";



                // Create 2 CBNs

                List <Subtree> added = new List <Subtree>();


                // Simulate a new new CBN
                Guid guid1 = System.Guid.NewGuid();

                added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, setupCode));

                var syncData = new GraphSyncData(null, added, null);

                astLiveRunner.UpdateGraph(syncData);

                //Get the callsite for the ctor
                var core          = astLiveRunner.RuntimeCore;
                var ctorCallsites = core.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass");

                Assert.IsTrue(ctorCallsites.Count() == 1);
                ProtoCore.CallSite cs = ctorCallsites.First();

                //Request serialisation
                string serialisationData = cs.GetTraceDataToSave();

                //It shouldn't be empty
                Assert.IsTrue(!String.IsNullOrEmpty(serialisationData));


                //Wipe the trace data
                cs.TraceData.Clear();

                //Re-inject the data into the trace cache
                cs.LoadSerializedDataIntoTraceCache(serialisationData);

                ExecuteMoreCode("x = 1;");


                // Verify that a is re-executed
                TestFrameWork.AssertValue("mtcAID", 0, astLiveRunner);
                TestFrameWork.AssertValue("mtcAWasTraced", true, astLiveRunner);
            }
Exemple #12
0
            public void TestGuidStability()
            {
                //Test to ensure that the first time the code is executed the wasTraced attribute is marked as false
                //and the secodn time it is marked as true


                string setupCode =
                    @"import(""FFITarget.dll""); 
x = 0; 
mtcA = IncrementerTracedClass.IncrementerTracedClass(x); 
mtcAID = mtcA.ID;
mtcAWasTraced = mtcA.WasCreatedWithTrace(); ";



                // Create 2 CBNs

                List <Subtree> added = new List <Subtree>();


                // Simulate a new new CBN
                Guid guid1 = System.Guid.NewGuid();

                added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, setupCode));

                var syncData = new GraphSyncData(null, added, null);

                astLiveRunner.UpdateGraph(syncData);

                TestFrameWork.AssertValue("mtcAID", 0, astLiveRunner);
                TestFrameWork.AssertValue("mtcAWasTraced", false, astLiveRunner);


                var core          = astLiveRunner.RuntimeCore;
                var ctorCallsites = core.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass");

                Assert.IsTrue(ctorCallsites.Count() == 1);
                Guid guid = ctorCallsites.First().CallSiteID;



                ExecuteMoreCode("x = 1;");

                // Verify that a is re-executed
                TestFrameWork.AssertValue("mtcAID", 0, astLiveRunner);
                TestFrameWork.AssertValue("mtcAWasTraced", true, astLiveRunner);

                //Verify that the GUID has been adjusted
                var ctorCallsites2 = core.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass");

                Assert.IsTrue(ctorCallsites2.Count() == 1);
                Guid guid2 = ctorCallsites2.First().CallSiteID;

                Assert.AreEqual(guid, guid2);
            }
Exemple #13
0
            //Migrate this code into the test framework
            private void ExecuteMoreCode(string newCode)
            {
                Guid           guid2 = System.Guid.NewGuid();
                List <Subtree> added = new List <Subtree>();

                added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, newCode));


                GraphSyncData syncData = new GraphSyncData(null, added, null);

                astLiveRunner.UpdateGraph(syncData);
            }
        /// <summary>
        /// Call this method to intialize a CompileCustomNodeAsyncTask with an
        /// EngineController, nodes from the corresponding CustomNodeWorkspaceModel,
        /// and inputs/outputs of the CustomNodeDefinition.
        /// </summary>
        /// <param name="initParams">Input parameters required for compilation of
        /// the CustomNodeDefinition.</param>
        /// <returns>Returns true if GraphSyncData is generated successfully and
        /// that the CompileCustomNodeAsyncTask should be scheduled for execution.
        /// Returns false otherwise.</returns>
        ///
        internal bool Initialize(CompileCustomNodeParams initParams)
        {
            engineController = initParams.EngineController;

            try
            {
                graphSyncData = engineController.ComputeSyncData(initParams);
                return(graphSyncData != null);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// Call this method to intialize a CompileCustomNodeAsyncTask with an 
        /// EngineController, nodes from the corresponding CustomNodeWorkspaceModel,
        /// and inputs/outputs of the CustomNodeDefinition.
        /// </summary>
        /// <param name="initParams">Input parameters required for compilation of 
        /// the CustomNodeDefinition.</param>
        /// <returns>Returns true if GraphSyncData is generated successfully and 
        /// that the CompileCustomNodeAsyncTask should be scheduled for execution.
        /// Returns false otherwise.</returns>
        /// 
        internal bool Initialize(CompileCustomNodeParams initParams)
        {
            engineController = initParams.EngineController;

            try
            {
                graphSyncData = engineController.ComputeSyncData(initParams);
                return graphSyncData != null;
            }
            catch (Exception)
            {
                return false;
            }
        }
        /// <summary>
        /// This method is called by codes that intent to start a graph update.
        /// This method is called on the main thread where node collection in a
        /// WorkspaceModel can be safely accessed.
        /// </summary>
        /// <param name="controller">Reference to an instance of EngineController
        /// to assist in generating GraphSyncData object for the given set of nodes.
        /// </param>
        /// <param name="workspace">Reference to the WorkspaceModel from which a
        /// set of updated nodes is computed. The EngineController generates the
        /// resulting GraphSyncData from this list of updated nodes.</param>
        /// <returns>Returns true if there is any GraphSyncData, or false otherwise
        /// (in which case there will be no need to schedule UpdateGraphAsyncTask
        /// for execution).</returns>
        ///
        internal bool Initialize(EngineController controller, WorkspaceModel workspace)
        {
            try
            {
                engineController  = controller;
                TargetedWorkspace = workspace;

                modifiedNodes = ComputeModifiedNodes(workspace);
                graphSyncData = engineController.ComputeSyncData(modifiedNodes);
                return(graphSyncData != null);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// This method is called by codes that intent to start a graph update.
        /// This method is called on the main thread where node collection in a 
        /// WorkspaceModel can be safely accessed.
        /// </summary>
        /// <param name="controller">Reference to an instance of EngineController 
        /// to assist in generating GraphSyncData object for the given set of nodes.
        /// </param>
        /// <param name="workspace">Reference to the WorkspaceModel from which a 
        /// set of updated nodes is computed. The EngineController generates the 
        /// resulting GraphSyncData from this list of updated nodes.</param>
        /// <returns>Returns true if there is any GraphSyncData, or false otherwise
        /// (in which case there will be no need to schedule UpdateGraphAsyncTask 
        /// for execution).</returns>
        /// 
        internal bool Initialize(EngineController controller, WorkspaceModel workspace)
        {
            try
            {
                engineController = controller;
                TargetedWorkspace = workspace;

                modifiedNodes = ComputeModifiedNodes(workspace);
                graphSyncData = engineController.ComputeSyncData(modifiedNodes);
                return graphSyncData != null;
            }
            catch (Exception)
            {
                return false;
            }
        }
        /// <summary>
        /// This method is called by code that intends to start a graph update.
        /// This method is called on the main thread where node collection in a
        /// WorkspaceModel can be safely accessed.
        /// </summary>
        /// <param name="controller">Reference to an instance of EngineController
        /// to assist in generating GraphSyncData object for the given set of nodes.
        /// </param>
        /// <param name="workspace">Reference to the WorkspaceModel from which a
        /// set of updated nodes is computed. The EngineController generates the
        /// resulting GraphSyncData from this list of updated nodes.</param>
        /// <returns>Returns true if there is any GraphSyncData, or false otherwise
        /// (in which case there will be no need to schedule UpdateGraphAsyncTask
        /// for execution).</returns>
        ///
        internal bool Initialize(EngineController controller, WorkspaceModel workspace)
        {
            try
            {
                engineController  = controller;
                TargetedWorkspace = workspace;

                ModifiedNodes = ComputeModifiedNodes(workspace);
                graphSyncData = engineController.ComputeSyncData(workspace.Nodes, ModifiedNodes, verboseLogging);
                return(graphSyncData != null);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("UpgradeGraphAsyncTask saw: " + e.ToString());
                return(false);
            }
        }
Exemple #19
0
        public void TestModified02()
        {
            List <string> codes = new List <string>()
            {
                "a = 1; b = 1;",
                "c = 1;"
            };

            // Add nodes a = 1, b = 1
            Guid           guid  = System.Guid.NewGuid();
            List <Subtree> added = new List <Subtree>();

            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]));
            var syncData = new GraphSyncData(null, added, null);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(core, runtimeCore);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Modify contents to c = 1
            List <Subtree> modified = new List <Subtree>();

            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            astList = changeSetState.GetDeltaASTList(syncData);

            // Get expected ASTList
            // The list must be in the order that it is expected
            List <string> expectedCode = new List <string>()
            {
                "b = null; a = null; c = 1;"
            };
            List <AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode);

            // Compare ASTs to be equal
            for (int n = 0; n < astList.Count; ++n)
            {
                AssociativeNode node1   = astList[n];
                AssociativeNode node2   = expectedAstList[n];
                bool            isEqual = node1.Equals(node2);
                Assert.IsTrue(isEqual);
            }
        }
Exemple #20
0
        /// <summary>
        /// This method is called by code that intends to start a graph update.
        /// This method is called on the main thread where node collection in a
        /// WorkspaceModel can be safely accessed.
        /// </summary>
        /// <param name="controller">Reference to an instance of EngineController
        /// to assist in generating GraphSyncData object for the given set of nodes.
        /// </param>
        /// <param name="workspace">Reference to the WorkspaceModel from which a
        /// set of updated nodes is computed. The EngineController generates the
        /// resulting GraphSyncData from this list of updated nodes.</param>
        /// <returns>Returns true if there is any GraphSyncData, or false otherwise
        /// (in which case there will be no need to schedule UpdateGraphAsyncTask
        /// for execution).</returns>
        ///
        internal bool Initialize(EngineController controller, WorkspaceModel workspace)
        {
            try
            {
                engineController  = controller;
                TargetedWorkspace = workspace;

                ModifiedNodes = ComputeModifiedNodes(workspace);
                graphSyncData = engineController.ComputeSyncData(workspace.Nodes, ModifiedNodes, verboseLogging);
                if (graphSyncData == null)
                {
                    return(false);
                }

                if (engineController.ProfilingSession != null)
                {
                    engineController.ProfilingSession.UnregisterDeletedNodes(workspace.Nodes);
                }

                // We clear dirty flags before executing the task. If we clear
                // flags after the execution of task, for example in
                // AsyncTask.Completed or in HandleTaskCompletionCore(), as both
                // are executed in the other thread, although some nodes are
                // modified and we request graph execution, but just before
                // computing sync data, the task completion handler jumps in
                // and clear dirty flags. Now graph sync data will be null and
                // graph is in wrong state.
                foreach (var nodeGuid in graphSyncData.NodeIDs)
                {
                    var node = workspace.Nodes.FirstOrDefault(n => n.GUID.Equals(nodeGuid));
                    if (node != null)
                    {
                        node.ClearDirtyFlag();
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("UpgradeGraphAsyncTask saw: " + e.ToString());
                return(false);
            }
        }
Exemple #21
0
        public void TestPeriodicUpdate01()
        {
            int    rhs  = 0;
            string code = String.Format("a = {0};", rhs.ToString());

            Guid guid = System.Guid.NewGuid();

            // First run
            // a = 1
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, code);

            st.IsInput = true;
            added.Add(st);
            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 0);

            List <Subtree> modified = null;

            const int maxUpdate = 100;

            for (int n = 1; n <= maxUpdate; ++n)
            {
                // Modify a
                code       = String.Format("a = {0};", n.ToString());
                modified   = new List <Subtree>();
                st         = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, code);
                st.IsInput = true;
                modified.Add(st);
                syncData = new GraphSyncData(null, null, modified);
                liverunner.UpdateGraph(syncData);

                instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();
                Assert.AreEqual(instrStreamStart, instrStreamEnd);
            }

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 100);
        }
Exemple #22
0
        public void TestInstructionStreamMemory_FunctionRedefinition01()
        {
            List <string> codes = new List <string>()
            {
                "def f() {return = 1;}",
                "a = f();",
                "def f() {return = 2;}"
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();

            // First run
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[0]);

            added.Add(st);

            st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[1]);
            added.Add(st);

            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 1);

            // Modify function
            List <Subtree> modified = new List <Subtree>();

            st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[2]);
            modified.Add(st);
            syncData = new GraphSyncData(null, null, modified);
            liverunner.UpdateGraph(syncData);
            instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 2);

            Assert.AreEqual(instrStreamStart, instrStreamEnd);
        }
Exemple #23
0
            public void EnsureSerialisationDataNonNull()
            {
                //Test to ensure that the first time the code is executed the wasTraced attribute is marked as false
                //and the secodn time it is marked as true


                string setupCode =
                    @"import(""FFITarget.dll""); 
x = 0; 
mtcA = IncrementerTracedClass.IncrementerTracedClass(x); 
mtcAID = mtcA.ID;
mtcAWasTraced = mtcA.WasCreatedWithTrace(); ";



                // Create 2 CBNs

                List <Subtree> added = new List <Subtree>();


                // Simulate a new new CBN
                Guid guid1 = System.Guid.NewGuid();

                added.Add(CreateSubTreeFromCode(guid1, setupCode));

                var syncData = new GraphSyncData(null, added, null);

                astLiveRunner.UpdateGraph(syncData);

                //Get the callsite for the ctor
                var core          = astLiveRunner.Core;
                var ctorCallsites = core.DSExecutable.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass");

                Assert.IsTrue(ctorCallsites.Count() == 1);
                ProtoCore.CallSite cs = ctorCallsites.First();

                //Request serialisation
                string serialisationData = cs.GetTraceDataToSave();

                //It shouldn't be empty
                Assert.IsTrue(!String.IsNullOrEmpty(serialisationData));
            }
Exemple #24
0
        public void TestInstructionStreamMemory_SimpleWorkflow01()
        {
            List <string> codes = new List <string>()
            {
                "a = 1;",
                "a = 2;"
            };

            Guid guid = System.Guid.NewGuid();

            // First run
            // a = 1
            List <Subtree> added = new List <Subtree>();
            Subtree        st    = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]);

            st.IsInput = true;
            added.Add(st);
            var syncData = new GraphSyncData(null, added, null);

            liverunner.UpdateGraph(syncData);
            instrStreamStart = runtimeDiagnostics.GetExecutableInstructionCount();

            ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 1);

            // Modify
            // a = 2
            List <Subtree> modified = new List <Subtree>();

            st         = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]);
            st.IsInput = true;
            modified.Add(st);
            syncData = new GraphSyncData(null, null, modified);
            liverunner.UpdateGraph(syncData);
            instrStreamEnd = runtimeDiagnostics.GetExecutableInstructionCount();

            mirror = liverunner.InspectNodeValue("a");
            Assert.IsTrue((Int64)mirror.GetData().Data == 2);

            Assert.AreEqual(instrStreamStart, instrStreamEnd);
        }
Exemple #25
0
        private bool VerifyGraphSyncData(IEnumerable <NodeModel> nodes)
        {
            GraphSyncData data = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = new HashSet <Guid>(
                nodes.Where(n => n.ForceReExecuteOfNode)
                .Select(n => n.GUID));

            if (reExecuteNodesIds.Any() && data.ModifiedSubtrees != null)
            {
                for (int i = 0; i < data.ModifiedSubtrees.Count; ++i)
                {
                    var st = data.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        var newSt = new Subtree(st.AstNodes, st.GUID)
                        {
                            ForceExecution = true
                        };
                        data.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if ((data.AddedSubtrees != null && data.AddedSubtrees.Count > 0) ||
                (data.ModifiedSubtrees != null && data.ModifiedSubtrees.Count > 0) ||
                (data.DeletedSubtrees != null && data.DeletedSubtrees.Count > 0))
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(data);
                }
                return(true);
            }

            return(false);
        }
Exemple #26
0
        private bool VerifyGraphSyncData()
        {
            GraphSyncData data = syncDataManager.GetSyncData();

            syncDataManager.ResetStates();

            var reExecuteNodesIds = dynamoModel.HomeSpace.Nodes
                                    .Where(n => n.ForceReExecuteOfNode)
                                    .Select(n => n.GUID);

            if (reExecuteNodesIds.Any() && data.ModifiedSubtrees != null)
            {
                for (int i = 0; i < data.ModifiedSubtrees.Count; ++i)
                {
                    var st = data.ModifiedSubtrees[i];
                    if (reExecuteNodesIds.Contains(st.GUID))
                    {
                        Subtree newSt = new Subtree(st.AstNodes, st.GUID);
                        newSt.ForceExecution     = true;
                        data.ModifiedSubtrees[i] = newSt;
                    }
                }
            }

            if ((data.AddedSubtrees != null && data.AddedSubtrees.Count > 0) ||
                (data.ModifiedSubtrees != null && data.ModifiedSubtrees.Count > 0) ||
                (data.DeletedSubtrees != null && data.DeletedSubtrees.Count > 0))
            {
                lock (graphSyncDataQueue)
                {
                    graphSyncDataQueue.Enqueue(data);
                }
                return(true);
            }

            return(false);
        }
Exemple #27
0
 /// <summary>
 /// Update graph with graph sync data.
 /// </summary>
 /// <param name="graphData"></param>
 public void UpdateGraph(GraphSyncData graphData)
 {
     liveRunner.UpdateGraph(graphData);
 }
Exemple #28
0
        public void TestPreviewModify2Nodes02()
        {
            List <string> codes = new List <string>()
            {
                @"
                    a = 1;
                ",

                @"
                    b = 2;
                ",

                @"
                    x = a;
                ",

                @"
                    y = b;
                ",

                @"
                    z = b;
                ",

                @"
                    a = 10;
                ",
                @"
                    b = 20;
                ",
            };

            Guid guid1 = System.Guid.NewGuid();
            Guid guid2 = System.Guid.NewGuid();
            Guid guid3 = System.Guid.NewGuid();
            Guid guid4 = System.Guid.NewGuid();
            Guid guid5 = System.Guid.NewGuid();

            // Create and run the graph
            List <Subtree> added = new List <Subtree>();

            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[0]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[1]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid3, codes[2]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid4, codes[3]));
            added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid5, codes[4]));
            var syncData = new GraphSyncData(null, added, null);

            liveRunner.UpdateGraph(syncData);


            // Modify [a = 1;] to [a = 10;]
            // Modify [b = 2;] to [b = 20;]
            List <Subtree> modified = new List <Subtree>();

            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[5]));
            modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[6]));
            syncData = new GraphSyncData(null, null, modified);

            // Get astlist from ChangeSetComputer
            ChangeSetComputer      changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core, liveRunner.RuntimeCore);
            List <AssociativeNode> astList        = changeSetState.GetDeltaASTList(syncData);

            // Get the the preview guids (affected graphs)
            List <Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList);

            // Check if the the affected guids are in the list
            List <Guid> expectedGuid = new List <Guid> {
                guid1, guid2, guid3, guid4, guid5
            };

            AssertPreview(reachableGuidList, expectedGuid);
        }
Exemple #29
0
            public void LoadSave_R2R_2()
            {
                string setupCode =
                    @"import(""FFITarget.dll""); 
x = 0..2; 
mtcA = IncrementerTracedClass.IncrementerTracedClass(x); 
mtcAID = mtcA.ID;
mtcAWasTraced = mtcA.WasCreatedWithTrace(); ";


                // Create 2 CBNs

                List <Subtree> added = new List <Subtree>();


                // Simulate a new new CBN
                Guid guid1 = System.Guid.NewGuid();

                added.Add(CreateSubTreeFromCode(guid1, setupCode));

                var syncData = new GraphSyncData(null, added, null);

                astLiveRunner.UpdateGraph(syncData);

                TestFrameWork.AssertValue("mtcAID", new List <int>()
                {
                    0,
                    1,
                    2
                }, astLiveRunner);

                TestFrameWork.AssertValue("mtcAWasTraced", new List <bool>()
                {
                    false,
                    false,
                    false
                }, astLiveRunner);

                //Get the callsite for the ctor
                var core          = astLiveRunner.Core;
                var ctorCallsites = core.DSExecutable.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass");

                Assert.IsTrue(ctorCallsites.Count() == 1);
                ProtoCore.CallSite cs = ctorCallsites.First();

                //Request serialisation
                string serialisationData = cs.GetTraceDataToSave();

                //It shouldn't be empty
                Assert.IsTrue(!String.IsNullOrEmpty(serialisationData));


                //Wipe the trace data
                cs.TraceData.Clear();

                //Re-inject the data into the trace cache
                cs.LoadSerializedDataIntoTraceCache(serialisationData);


                // Simulate a new new CBN
                Guid guid2 = System.Guid.NewGuid();

                added = new List <Subtree>();
                added.Add(CreateSubTreeFromCode(guid2, "x = 1..2;"));


                syncData = new GraphSyncData(null, added, null);
                astLiveRunner.UpdateGraph(syncData);

                // Verify that a is re-executed
                TestFrameWork.AssertValue("mtcAID", new List <int>()
                {
                    0,
                    1
                }, astLiveRunner);
                TestFrameWork.AssertValue("mtcAWasTraced", new List <bool>()
                {
                    true,
                    true
                }, astLiveRunner);
            }