Ejemplo n.º 1
0
        /*internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, StreamReader log,
            bool watchNestedMode = false)
        {
            //bool check = true;
            
            // search for the line and LHS string in the log file
            // verify that the LHS identifier name equals 'symbolName'
            // pass the LHS string to GetWatchValue() and inspect it
            // verify the watch values with the log output
            string line = null;
            while ((line = log.ReadLine()) != null)
            {
                // Get line no.
                Match m = Regex.Match(line, @"At line, (\d+)");
                if (m.Success)
                {
                    int lineNo = int.Parse(m.Groups[1].Value);
                    if (lineNo == lineAtPrevBreak)
                    {
                        // Get lhs string
                        // m = Regex.Match(line, @"(\d+), (\w+)");
                        m = Regex.Match(line, @"(\d+), (.*)([^\s]+)");
                        if (m.Success)
                        {
                            string lhsString = m.Groups[2].Value;

                            // Get lhs symbol name
                            m = Regex.Match(lhsString, @"(\w+)");
                            if (m.Success)
                            {
                                string lhsName = m.Groups[1].Value;
                                if (lhsName.Equals(symbolName))
                                {
                                    ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core);
                                    ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(lhsString);
                                    Obj obj = mirror.GetWatchValue();

                                    if (!watchNestedMode)
                                    {
                                        // Cheat by peeking into heap etc. to dump output string
                                        // match string with log output to verify
                                        string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true);
                                        line = log.ReadLine();

                                        m = Regex.Match(line, @"Info: (.*)");
                                        if (m.Success)
                                        {
                                            string output = m.Groups[1].Value;
                                            if (!output.Equals(result))
                                            {
                                                Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", lhsString));
                                                return;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // TODO: Implement this - pratapa
                                        // if obj is a class pointer, handle separately
                                        // if obj is an array pointer, handle separately
                                        // if obj is a literal, verify watch value with log output directly
                                        GetStringValue(obj, mirror);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }*/

        internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, RuntimeCore runtimeCore,
            Dictionary<int, List<string>> map, bool watchNestedMode = false, int ci = Constants.kInvalidIndex, string defectID = "")
        {
            //bool check = true;

            // search for the line and LHS string in the map
            // verify that the LHS identifier name equals 'symbolName'
            // pass the LHS string to GetWatchValue() and inspect it
            // verify the watch values with the log output
            if (!map.ContainsKey(lineAtPrevBreak))
                return;

            List<string> expressions = map[lineAtPrevBreak];
            foreach(string exp in expressions)
            {
                // Get line no.
                // Get lhs symbol name
                string lhsName = null;
                int index = exp.IndexOf('.');
                if (index != -1)
                {
                    string[] parts = exp.Split('.');
                    lhsName = parts[parts.Length - 1];
                }
                else
                {
                    Match m = Regex.Match(exp, @"(\w+)");
                    if (m.Success)
                    {
                        lhsName = m.Groups[1].Value;
                    }
                }                            
                if (lhsName.Equals(symbolName))
                {
                    ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, runtimeCore);
                    ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(exp);
                    Obj obj = mirror.GetWatchValue();
                    
                    if (!watchNestedMode)
                    {
                        // Cheat by peeking into heap etc. to dump output string
                        // match string with map output to verify
                        string result = mirror.GetStringValue(obj.DsasmValue, runtimeCore.RuntimeMemory.Heap, 0, true);

                        Expression expr = new Expression(lineAtPrevBreak, exp, ci);
                        if (!InjectionExecutive.ExpressionMap.ContainsKey(expr))
                            return;

                        List<string> values = InjectionExecutive.ExpressionMap[expr];
                        
                        if (!values.Contains(result))
                        {
                            Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\nTracked by Defect: {1}", exp, defectID));
                            return;
                        }                        
                    }
                    else
                    {
                        // TODO: Implement this! - pratapa
                        // if obj is a class pointer, handle separately
                        // if obj is an array pointer, handle separately
                        // if obj is a literal, verify watch value with log output directly
                        GetStringValue(obj, mirror);
                    }
                    //break;
                }
            }
        }
Ejemplo n.º 2
0
        internal void Print(StackValue sv, int lineNo, string symbolName, int ci = Constants.kInvalidIndex)
        {
            //TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created
            ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(this, RuntimeCore);
            string result = mirror.GetStringValue(sv, RuntimeCore.RuntimeMemory.Heap, 0, true);

            TextOutputStream tStream = RuntimeCore.RuntimeStatus.MessageHandler as TextOutputStream;
            if (tStream != null)
            {
                Dictionary<int, List<string>> map = tStream.Map;

                //foreach(var kv in tStream.Map)

                if (!map.ContainsKey(lineNo))
                    return;

                List<string> expressions = map[lineNo];

                foreach (var exp in expressions)
                {
                    // Get lhs symbol name
                    string lhsName = null;
                    int index = exp.IndexOf('.');
                    if (index != -1)
                    {
                        string[] parts = exp.Split('.');
                        lhsName = parts[parts.Length - 1];
                    }
                    else
                    {
                        Match m = Regex.Match(exp, @"(\w+)");
                        if (m.Success)
                        {
                            lhsName = m.Groups[1].Value;
                        }
                    }

                    if (lhsName.Equals(symbolName))
                    {
                        // Add to map
                        Expression expStruct = new Expression(lineNo, exp, ci);

                        if (ExpressionMap.ContainsKey(expStruct))
                        {
                            List<string> values = ExpressionMap[expStruct];
                            values.Add(result);
                        }
                        else
                        {
                            List<string> values = new List<string>();
                            values.Add(result);

                            ExpressionMap.Add(expStruct, values);
                        }
                    }
                }
            }
        }