예제 #1
0
        protected T Run <T>(string ns, string type, string method, bool reset, params object[] parameters)
        {
            if (reset)
            {
                // reset the stack
                platform.ResetSimulation(simAdapter);

                //Run<int>("Mosa.Kernel.x86Test", "KernelMemory", "SetMemory", false, new object[] { (uint)0x00900000 });
            }

            // Find the test method to execute
            MosaMethod runtimeMethod = FindMethod(
                ns,
                type,
                method,
                parameters
                );

            Debug.Assert(runtimeMethod != null, runtimeMethod.ToString());

            var symbol = linker.GetSymbol(runtimeMethod.FullName, SectionKind.Text);

            ulong address = (ulong)symbol.VirtualAddress;

            platform.PrepareToExecuteMethod(simAdapter, address, parameters);

            simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + 500000;             // nothing should take this long
            simAdapter.SimCPU.Execute();

            if (simAdapter.SimCPU.Monitor.BreakAtTick == simAdapter.SimCPU.Tick)
            {
                throw new Exception("Aborted. Method did not complete under 500000 ticks. " + simAdapter.SimCPU.Tick.ToString());
            }

            if (runtimeMethod.Signature.ReturnType.IsVoid)
            {
                return(default(T));
            }

            object result = platform.GetResult(simAdapter, runtimeMethod.Signature.ReturnType);

            try
            {
                if (default(T) is ValueType)
                {
                    return((T)result);
                }
                else
                {
                    return(default(T));
                }
            }
            catch (InvalidCastException e)
            {
                Debug.Assert(false, String.Format("Failed to convert result {0} of destination {1} destination type {2}.", result, result.GetType(), typeof(T).ToString()));
                throw e;
            }
        }
예제 #2
0
        protected T Run <T>(string ns, string type, string method, bool reset, params object[] parameters)
        {
            // enforce single thread execution only
            lock (this)
            {
                // If not initialized, do it now
                Initialize();

                // Find the test method to execute
                var runtimeMethod = FindMethod(
                    ns,
                    type,
                    method,
                    parameters
                    );

                Debug.Assert(runtimeMethod != null, runtimeMethod.ToString());

                var symbol = Compiler.Linker.GetSymbol(runtimeMethod.FullName, SectionKind.Text);

                ulong address = symbol.VirtualAddress;

                //Console.Write("Testing: " + ns + "." + type + "." + method);

                if (reset)
                {
                    // reset the stack
                    platform.ResetSimulation(simAdapter);
                }

                platform.PrepareToExecuteMethod(simAdapter, address, parameters);

                simAdapter.SimCPU.Monitor.BreakAtTick = simAdapter.SimCPU.Monitor.BreakAtTick + MaxTicks;                 // nothing should take this long
                simAdapter.SimCPU.Execute();

                if (simAdapter.SimCPU.Monitor.BreakAtTick == simAdapter.SimCPU.Tick)
                {
                    throw new Exception("Aborted. Method did not complete under " + MaxTicks.ToString() + " ticks. " + simAdapter.SimCPU.Tick.ToString());
                }

                if (runtimeMethod.Signature.ReturnType.IsVoid)
                {
                    return(default(T));
                }

                object result = platform.GetResult(simAdapter, runtimeMethod.Signature.ReturnType);

                try
                {
                    //Console.WriteLine(".");
                    if (default(T) is ValueType)
                    {
                        return((T)result);
                    }
                    else
                    {
                        return(default(T));
                    }
                }
                catch (InvalidCastException e)
                {
                    //Console.WriteLine("..." + e.ToString());
                    Debug.Assert(false, String.Format("Failed to convert result {0} of destination {1} destination type {2}.", result, result.GetType(), typeof(T).ToString()));
                    throw e;
                }
            }
        }