Пример #1
0
        public void Process(IHardwareDevice outputDevice)
        {
            OutputDevice = outputDevice;

            StartTime = (ulong)PerformanceCounter.ElapsedNanoseconds;

            foreach (ICommand command in Commands)
            {
                if (command.Enabled)
                {
                    bool shouldMeter = command.ShouldMeter();

                    long startTime = 0;

                    if (shouldMeter)
                    {
                        startTime = PerformanceCounter.ElapsedNanoseconds;
                    }

                    command.Process(this);

                    if (shouldMeter)
                    {
                        ulong effectiveElapsedTime = (ulong)(PerformanceCounter.ElapsedNanoseconds - startTime);

                        if (effectiveElapsedTime > command.EstimatedProcessingTime)
                        {
                            Logger.Warning?.Print(LogClass.AudioRenderer, $"Command {command.GetType().Name} took {effectiveElapsedTime}ns (expected {command.EstimatedProcessingTime}ns)");
                        }
                    }
                }
            }

            EndTime = (ulong)PerformanceCounter.ElapsedNanoseconds;
        }
Пример #2
0
        public void Process(CommandList context)
        {
            IHardwareDevice device = context.OutputDevice;

            if (device.GetSampleRate() == Constants.TargetSampleRate)
            {
                int  channelCount = (int)device.GetChannelCount();
                uint bufferCount  = Math.Min(device.GetChannelCount(), InputCount);

                const int sampleCount = Constants.TargetSampleCount;

                short[] outputBuffer = new short[bufferCount * sampleCount];

                for (int i = 0; i < bufferCount; i++)
                {
                    ReadOnlySpan <float> inputBuffer = GetBuffer(InputBufferIndices[i], sampleCount);

                    for (int j = 0; j < sampleCount; j++)
                    {
                        outputBuffer[i + j * channelCount] = PcmHelper.Saturate(inputBuffer[j]);
                    }
                }

                device.AppendBuffer(outputBuffer, InputCount);
            }
            else
            {
                // TODO: support resampling for device only supporting something different
                throw new NotImplementedException();
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InterruptHandler"/> class.
        /// </summary>
        /// <param name="interruptManager">The interrupt manager.</param>
        /// <param name="irq">The irq.</param>
        /// <param name="hardwareDevice">The hardware device.</param>
        public InterruptHandler(InterruptManager interruptManager, byte irq, IHardwareDevice hardwareDevice)
        {
            if (hardwareDevice == null)
                HAL.Abort("hardwareDevice == null");

            this.interruptManager = interruptManager;
            this.irq = irq;
            this.hardwareDevice = hardwareDevice;
        }
Пример #4
0
 /// <summary>
 /// Releases the interrupt handler.
 /// </summary>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public void ReleaseInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
 {
     try {
         spinLock.Enter();
         interruptHandlers[irq].Remove(hardwareDevice);
     }
     finally {
         spinLock.Exit();
     }
 }
Пример #5
0
 /// <summary>
 /// Adds the interrupt handler.
 /// </summary>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public void AddInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
 {
     try {
         spinLock.Enter();
         interruptHandlers[irq].Add(hardwareDevice);
     }
     finally {
         spinLock.Exit();
     }
 }
Пример #6
0
    public Task <ProcessExecutionResult> UninstallDeviceApp(IHardwareDevice device, string appBundleId, CancellationToken cancellationToken = default)
    {
        var args = new MlaunchArguments
        {
            new UninstallAppFromDeviceArgument(appBundleId),
            new DeviceNameArgument(device)
        };

        return(_processManager.ExecuteCommandAsync(args, _mainLog, TimeSpan.FromMinutes(3), cancellationToken: cancellationToken));
    }
Пример #7
0
 /// <summary>
 /// Adds the interrupt handler.
 /// </summary>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public void AddInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
 {
     try {
         spinLock.Enter();
         interruptHandlers[irq].Add(hardwareDevice);
     }
     finally {
         spinLock.Exit();
     }
 }
Пример #8
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        static public void StartDevice(IPCIDevice pciDevice)
        {
            DeviceDriver deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

            // MR 07/21/09: Commenting out, causes mono xbuild to fail on MacOS X
            // PCIDeviceDriverAttribute attribute = deviceDriver.Attribute as PCIDeviceDriverAttribute;

            LinkedList <IIOPortRegion> ioPortRegions = new LinkedList <IIOPortRegion>();
            LinkedList <IMemoryRegion> memoryRegions = new LinkedList <IMemoryRegion>();

            foreach (BaseAddress pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.Add(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.Add(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    IMemory memory = HAL.RequestPhysicalMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.Add(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            HardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InterruptHandler"/> class.
        /// </summary>
        /// <param name="interruptManager">The interrupt manager.</param>
        /// <param name="irq">The irq.</param>
        /// <param name="hardwareDevice">The hardware device.</param>
        public InterruptHandler(InterruptManager interruptManager, byte irq, IHardwareDevice hardwareDevice)
        {
            if (hardwareDevice == null)
            {
                HAL.Abort("hardwareDevice == null");
            }

            this.interruptManager = interruptManager;
            this.irq            = irq;
            this.hardwareDevice = hardwareDevice;
        }
Пример #10
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        static public void StartDevice(DeviceDriver deviceDriver)
        {
            ISADeviceDriverAttribute driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

            if (driverAtttribute.AutoLoad)
            {
                IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;
                //UNUSED:
                //ISADeviceDriverAttribute attribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

                LinkedList <IIOPortRegion> ioPortRegions = new LinkedList <IIOPortRegion>();
                LinkedList <IMemoryRegion> memoryRegions = new LinkedList <IMemoryRegion>();

                ioPortRegions.Add(new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange));

                if (driverAtttribute.AltBasePort != 0x00)
                {
                    ioPortRegions.Add(new IOPortRegion(driverAtttribute.AltBasePort, driverAtttribute.AltPortRange));
                }

                if (driverAtttribute.BaseAddress != 0x00)
                {
                    memoryRegions.Add(new MemoryRegion(driverAtttribute.BaseAddress, driverAtttribute.AddressRange));
                }

                foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes)
                {
                    if (memoryAttribute.MemorySize > 0)
                    {
                        IMemory memory = HAL.RequestPhysicalMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                        memoryRegions.Add(new MemoryRegion(memory.Address, memory.Size));
                    }
                }

                IHardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, driverAtttribute.IRQ, hardwareDevice));

                hardwareDevice.Setup(hardwareResources);

                if (resourceManager.ClaimResources(hardwareResources))
                {
                    hardwareResources.EnableIRQ();
                    if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                    {
                        deviceManager.Add(hardwareDevice);
                    }
                    else
                    {
                        hardwareResources.DisableIRQ();
                        resourceManager.ReleaseResources(hardwareResources);
                    }
                }
            }
        }
Пример #11
0
        protected async Task <string> FindDevice(TestTargetOs target)
        {
            IHardwareDevice?companionDevice = null;
            IHardwareDevice device          = await _hardwareDeviceLoader.FindDevice(target.Platform.ToRunMode(), _mainLog, includeLocked : false, force : false);

            if (target.Platform.IsWatchOSTarget())
            {
                companionDevice = await _hardwareDeviceLoader.FindCompanionDevice(_mainLog, device);
            }

            return(companionDevice?.Name ?? device.Name);
        }
Пример #12
0
        /// <summary>
        /// Adds the interrupt handler.
        /// </summary>
        /// <param name="irq">The irq.</param>
        /// <param name="hardwareDevice">The hardware device.</param>
        public void AddInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
        {
            if (irq >= MaxInterrupts)
                return;

            try
            {
                spinLock.Enter();
                interruptHandlers[irq].AddLast(hardwareDevice);
            }
            finally
            {
                spinLock.Exit();
            }
        }
Пример #13
0
        public IHardwareDevice FindCompanionDevice(ILog log, IHardwareDevice device)
        {
            var companion = ConnectedDevices.Where((v) => v.DeviceIdentifier == device.CompanionIdentifier);

            if (companion.Count() == 0)
            {
                throw new Exception($"Could not find the companion device for '{device.Name}'");
            }

            if (companion.Count() > 1)
            {
                log.WriteLine("Found {0} companion devices for {1}?!?", companion.Count(), device.Name);
            }

            return(companion.First());
        }
Пример #14
0
        /// <summary>
        /// Adds the interrupt handler.
        /// </summary>
        /// <param name="irq">The irq.</param>
        /// <param name="hardwareDevice">The hardware device.</param>
        public void AddInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
        {
            if (irq >= MaxInterrupts)
            {
                return;
            }

            try
            {
                spinLock.Enter();
                interruptHandlers[irq].AddLast(hardwareDevice);
            }
            finally
            {
                spinLock.Exit();
            }
        }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InterruptHandler"/> class.
 /// </summary>
 /// <param name="interruptManager">The interrupt manager.</param>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public InterruptHandler(InterruptManager interruptManager, byte irq, IHardwareDevice hardwareDevice)
 {
     this.interruptManager = interruptManager;
     this.irq = irq;
     this.hardwareDevice = hardwareDevice;
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InterruptHandler"/> class.
 /// </summary>
 /// <param name="interruptManager">The interrupt manager.</param>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public InterruptHandler(InterruptManager interruptManager, byte irq, IHardwareDevice hardwareDevice)
 {
     this.interruptManager = interruptManager;
     this.irq            = irq;
     this.hardwareDevice = hardwareDevice;
 }
Пример #17
0
 public SplitterHardwareDevice(IHardwareDevice baseDevice, IHardwareDevice secondaryDevice)
 {
     _baseDevice      = baseDevice;
     _secondaryDevice = secondaryDevice;
 }
Пример #18
0
        public async Task<(string DeviceName, TestExecutingResult Result, string ResultMessage)> RunApp(
            AppBundleInformation appInformation,
            TestTarget target,
            TimeSpan timeout,
            TimeSpan testLaunchTimeout,
            string? deviceName = null,
            string? companionDeviceName = null,
            bool ensureCleanSimulatorState = false,
            int verbosity = 1,
            XmlResultJargon xmlResultJargon = XmlResultJargon.xUnit,
            CancellationToken cancellationToken = default)
        {
            var args = new MlaunchArguments
            {
                new SetAppArgumentArgument("-connection-mode"),
                new SetAppArgumentArgument("none"), // This will prevent the app from trying to connect to any IDEs
                new SetAppArgumentArgument("-autostart", true),
                new SetEnvVariableArgument(EnviromentVariables.AutoStart, true),
                new SetAppArgumentArgument("-autoexit", true),
                new SetEnvVariableArgument(EnviromentVariables.AutoExit, true),
                new SetAppArgumentArgument("-enablenetwork", true),
                new SetEnvVariableArgument(EnviromentVariables.EnableNetwork, true),

                // On macOS we can't edit the TCC database easily
                // (it requires adding the mac has to be using MDM: https://carlashley.com/2018/09/28/tcc-round-up/)
                // So by default ignore any tests that would pop up permission dialogs in CI.
                new SetEnvVariableArgument(EnviromentVariables.DisableSystemPermissionTests, 1),
            };

            for (int i = -1; i < verbosity; i++)
            {
                args.Add(new VerbosityArgument());
            }

            var isSimulator = target.IsSimulator();

            if (isSimulator)
            {
                args.Add(new SetAppArgumentArgument("-hostname:127.0.0.1", true));
                args.Add(new SetEnvVariableArgument(EnviromentVariables.HostName, "127.0.0.1"));
            }
            else
            {
                var ipAddresses = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.Select(ip => ip.ToString());
                var ips = string.Join(",", ipAddresses);
                args.Add(new SetAppArgumentArgument($"-hostname:{ips}", true));
                args.Add(new SetEnvVariableArgument(EnviromentVariables.HostName, ips));
            }

            var listenerLog = _logs.Create($"test-{target.AsString()}-{_helpers.Timestamp}.log", LogType.TestLog.ToString(), timestamp: true);
            var (transport, listener, listenerTmpFile) = _listenerFactory.Create(target.ToRunMode(),
                log: _mainLog,
                testLog: listenerLog,
                isSimulator: isSimulator,
                autoExit: true,
                xmlOutput: true); // cli always uses xml

            // Initialize has to be called before we try to get Port (internal implementation of the listener says so)
            // TODO: Improve this to not get into a broken state - it was really hard to debug when I moved this lower
            listener.Initialize();

            args.Add(new SetAppArgumentArgument($"-transport:{transport}", true));
            args.Add(new SetEnvVariableArgument(EnviromentVariables.Transport, transport.ToString().ToUpper()));

            if (transport == ListenerTransport.File)
            {
                args.Add(new SetEnvVariableArgument(EnviromentVariables.LogFilePath, listenerTmpFile));
            }

            args.Add(new SetAppArgumentArgument($"-hostport:{listener.Port}", true));
            args.Add(new SetEnvVariableArgument(EnviromentVariables.HostPort, listener.Port));

            if (_listenerFactory.UseTunnel && !isSimulator) // simulators do not support tunnels
            {
                args.Add(new SetEnvVariableArgument(EnviromentVariables.UseTcpTunnel, true));
            }

            if (_useXmlOutput)
            {
                // let the runner now via envars that we want to get a xml output, else the runner will default to plain text
                args.Add (new SetEnvVariableArgument (EnviromentVariables.EnableXmlOutput, true));
                args.Add (new SetEnvVariableArgument (EnviromentVariables.XmlMode, "wrapped"));
                args.Add (new SetEnvVariableArgument (EnviromentVariables.XmlVersion, $"{xmlResultJargon}"));
            }

            listener.StartAsync();

            var crashLogs = new Logs(_logs.Directory);

            if (appInformation.Extension.HasValue)
            {
                switch (appInformation.Extension)
                {
                    case Extension.TodayExtension:
                        args.Add(isSimulator
                            ? (MlaunchArgument)new LaunchSimulatorExtensionArgument(appInformation.LaunchAppPath, appInformation.BundleIdentifier)
                            : new LaunchDeviceExtensionArgument(appInformation.LaunchAppPath, appInformation.BundleIdentifier));
                        break;
                    case Extension.WatchKit2:
                    default:
                        throw new NotImplementedException();
                }
            }
            else
            {
                args.Add(isSimulator
                    ? (MlaunchArgument)new LaunchSimulatorArgument(appInformation.LaunchAppPath)
                    : new LaunchDeviceArgument(appInformation.LaunchAppPath));
            }

            var runMode = target.ToRunMode();
            ICrashSnapshotReporter crashReporter;
            ITestReporter testReporter;

            if (isSimulator)
            {
                crashReporter = _snapshotReporterFactory.Create(_mainLog, crashLogs, isDevice: !isSimulator, deviceName: null!);
                testReporter = _testReporterFactory.Create(_mainLog,
                    _mainLog,
                    _logs,
                    crashReporter,
                    listener,
                    new XmlResultParser(),
                    appInformation,
                    runMode,
                    xmlResultJargon,
                    device: null,
                    timeout,
                    null,
                    (level, message) => _mainLog.WriteLine(message));

                using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(testReporter.CancellationToken, cancellationToken);

                listener.ConnectedTask
                    .TimeoutAfter(testLaunchTimeout)
                    .ContinueWith(testReporter.LaunchCallback)
                    .DoNotAwait();

                await _simulatorLoader.LoadDevices(_logs.Create($"simulator-list-{_helpers.Timestamp}.log", "Simulator list"), false, false);

                var simulators = await _simulatorLoader.FindSimulators(target, _mainLog);
                if (!(simulators?.Any() ?? false))
                {
                    _mainLog.WriteLine("Didn't find any suitable simulators");
                    throw new NoDeviceFoundException();
                }

                var simulator = string.IsNullOrEmpty(deviceName)
                    ? simulators.FirstOrDefault()
                    : simulators.FirstOrDefault(s => string.Equals(s.Name, deviceName, StringComparison.InvariantCultureIgnoreCase));

                if (simulator == null)
                {
                    throw new NoDeviceFoundException();
                }

                deviceName = simulator.Name;

                if (!target.IsWatchOSTarget())
                {
                    var stderrTty = _helpers.GetTerminalName(2);
                    if (!string.IsNullOrEmpty(stderrTty))
                    {
                        args.Add(new SetStderrArgument(stderrTty));
                    }
                    else
                    {
                        var stdoutLog = _logs.CreateFile($"mlaunch-stdout-{_helpers.Timestamp}.log", "Standard output");
                        var stderrLog = _logs.CreateFile($"mlaunch-stderr-{_helpers.Timestamp}.log", "Standard error");
                        args.Add(new SetStdoutArgument(stdoutLog));
                        args.Add(new SetStderrArgument(stderrLog));
                    }
                }

                var systemLogs = new List<ICaptureLog>();
                foreach (var sim in simulators)
                {
                    // Upload the system log
                    _mainLog.WriteLine("System log for the '{1}' simulator is: {0}", sim.SystemLog, sim.Name);
                    bool isCompanion = sim != simulator;

                    var logDescription = isCompanion ? LogType.CompanionSystemLog.ToString() : LogType.SystemLog.ToString();
                    var log = _captureLogFactory.Create(
                        Path.Combine(_logs.Directory, sim.Name + ".log"),
                        sim.SystemLog,
                        true,
                        logDescription);

                    log.StartCapture();
                    _logs.Add(log);
                    systemLogs.Add(log);
                }

                _mainLog.WriteLine("*** Executing {0}/{1} in the simulator ***", appInformation.AppName, target);

                if (ensureCleanSimulatorState)
                {
                    foreach (var sim in simulators)
                    {
                        await sim.PrepareSimulator(_mainLog, appInformation.BundleIdentifier);
                    }
                }

                args.Add(new SimulatorUDIDArgument(simulator.UDID));

                await crashReporter.StartCaptureAsync();

                _mainLog.WriteLine("Starting test run");

                var result = _processManager.ExecuteCommandAsync(args, _mainLog, timeout, cancellationToken: linkedCts.Token);

                await testReporter.CollectSimulatorResult(result);

                // cleanup after us
                if (ensureCleanSimulatorState)
                {
                    await simulator.KillEverything(_mainLog);
                }

                foreach (var log in systemLogs)
                {
                    log.StopCapture();
                }
            }
            else
            {
                args.Add(new DisableMemoryLimitsArgument());

                if (deviceName == null)
                {
                    IHardwareDevice? companionDevice = null;
                    IHardwareDevice device = await _hardwareDeviceLoader.FindDevice(runMode, _mainLog, includeLocked: false, force: false);

                    if (target.IsWatchOSTarget())
                    {
                        companionDevice = await _hardwareDeviceLoader.FindCompanionDevice(_mainLog, device);
                    }

                    deviceName = companionDevice?.Name ?? device.Name;
                }

                if (deviceName == null)
                {
                    throw new NoDeviceFoundException();
                }

                crashReporter = _snapshotReporterFactory.Create(_mainLog, crashLogs, isDevice: !isSimulator, deviceName);
                testReporter = _testReporterFactory.Create(_mainLog,
                    _mainLog,
                    _logs,
                    crashReporter,
                    listener,
                    new XmlResultParser(),
                    appInformation,
                    runMode,
                    xmlResultJargon,
                    deviceName,
                    timeout,
                    null,
                    (level, message) => _mainLog.WriteLine(message));

                using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(testReporter.CancellationToken, cancellationToken);

                listener.ConnectedTask
                    .TimeoutAfter(testLaunchTimeout)
                    .ContinueWith(testReporter.LaunchCallback)
                    .DoNotAwait();

                _mainLog.WriteLine("*** Executing {0}/{1} on device '{2}' ***", appInformation.AppName, target, deviceName);

                if (target.IsWatchOSTarget())
                {
                    args.Add(new AttachNativeDebuggerArgument()); // this prevents the watch from backgrounding the app.
                }
                else
                {
                    args.Add(new WaitForExitArgument());
                }

                args.Add(new DeviceNameArgument(deviceName));

                var deviceSystemLog = _logs.Create($"device-{deviceName}-{_helpers.Timestamp}.log", "Device log");
                var deviceLogCapturer = _deviceLogCapturerFactory.Create(_mainLog, deviceSystemLog, deviceName);
                deviceLogCapturer.StartCapture();

                try
                {
                    await crashReporter.StartCaptureAsync();

                    // create a tunnel to communicate with the device
                    if (transport == ListenerTransport.Tcp && _listenerFactory.UseTunnel && listener is SimpleTcpListener tcpListener)
                    {
                        // create a new tunnel using the listener
                        var tunnel = _listenerFactory.TunnelBore.Create(deviceName, _mainLog);
                        tunnel.Open(deviceName, tcpListener, timeout, _mainLog);
                        // wait until we started the tunnel
                        await tunnel.Started;
                    }

                    _mainLog.WriteLine("Starting test run");

                    // We need to check for MT1111 (which means that mlaunch won't wait for the app to exit).
                    var aggregatedLog = Log.CreateAggregatedLog(testReporter.CallbackLog, _mainLog);
                    Task<ProcessExecutionResult> runTestTask = _processManager.ExecuteCommandAsync(
                        args,
                        aggregatedLog,
                        timeout,
                        cancellationToken: linkedCts.Token);

                    await testReporter.CollectDeviceResult(runTestTask);
                }
                finally
                {
                    deviceLogCapturer.StopCapture();
                    deviceSystemLog.Dispose();

                    // close a tunnel if it was created
                    if (!isSimulator && _listenerFactory.UseTunnel)
                        await _listenerFactory.TunnelBore.Close(deviceName);
                }

                // Upload the system log
                if (File.Exists(deviceSystemLog.FullPath))
                {
                    _mainLog.WriteLine("A capture of the device log is: {0}", deviceSystemLog.FullPath);
                }
            }

            listener.Cancel();
            listener.Dispose();

            // check the final status, copy all the required data
            var (testResult, resultMessage) = await testReporter.ParseResult();

            return (deviceName, testResult, resultMessage);
        }
Пример #19
0
 public void RegisterHardwareDevice(IHardwareDevice dev)
 {
     devices.Add(dev);
     hookupDevice(dev);
     if (dev is IInterruptor)
         ((IInterruptor)dev).Interrupt += new EventHandler(dev_Interrupt);
 }
Пример #20
0
 private void hookupDevice(IHardwareDevice dev)
 {
     foreach (var input in dev.InputDevices)
     {
         state.InputDevices.Add(input.Key, input.Value);
     }
     foreach (var output in dev.OutputDevices)
     {
         state.OutputDevices.Add(output.Key, output.Value);
     }
 }
Пример #21
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IOPortRegion>();
            var memoryRegions = new LinkedList<MemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            foreach (var ioportregion in ioPortRegions)
            {
                Boot.Console.WriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            }

            foreach (var memoryregion in memoryRegions)
            {
                Boot.Console.WriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            }

            //Boot.Console.WriteLine("  Command: 0x" + hardwareDevice...ToString("X"));

            var hardwareResources = new HardwareResources(
                ioPortRegions.ToArray(),
                memoryRegions.ToArray(),
                new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice),
                pciDevice as IPCIDeviceResource
            );

            hardwareDevice.Setup(hardwareResources);

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
            {
                pciDevice.SetDeviceOnline();
            }
        }
 public void AddHardware(IHardwareDevice device)
 {
     devices[arrayLength] = device;
     arrayLength++;
 }
Пример #23
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList <IOPortRegion>();
            var memoryRegions = new LinkedList <MemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            foreach (var ioportregion in ioPortRegions)
            {
                Boot.Console.WriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            }

            foreach (var memoryregion in memoryRegions)
            {
                Boot.Console.WriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            }

            //Boot.Console.WriteLine("  Command: 0x" + hardwareDevice...ToString("X"));

            var hardwareResources = new HardwareResources(
                ioPortRegions.ToArray(),
                memoryRegions.ToArray(),
                new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice),
                pciDevice as IPCIDeviceResource
                );

            hardwareDevice.Setup(hardwareResources);

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
            {
                pciDevice.SetDeviceOnline();
            }
        }
Пример #24
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.DeviceSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IIOPortRegion>();
            var memoryRegions = new LinkedList<IMemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            var hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                hardwareDevice.Setup(hardwareResources);

                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Пример #25
0
 /// <summary>
 /// Releases the interrupt handler.
 /// </summary>
 /// <param name="irq">The irq.</param>
 /// <param name="hardwareDevice">The hardware device.</param>
 public void ReleaseInterruptHandler(byte irq, IHardwareDevice hardwareDevice)
 {
     try
     {
         spinLock.Enter();
         interruptHandlers[irq].Remove(hardwareDevice);
     }
     finally
     {
         spinLock.Exit();
     }
 }
Пример #26
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.DeviceSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList <IIOPortRegion>();
            var memoryRegions = new LinkedList <IMemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            var hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                hardwareDevice.Setup(hardwareResources);

                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Пример #27
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        public static void StartDevice(ISADeviceDriverAttribute driverAtttribute, IHardwareDevice hardwareDevice)
        {
            int ioRegionCount = 1;
            int memoryRegionCount = 0;

            if (driverAtttribute.AltBasePort != 0x00)
            {
                ioRegionCount++;
            }

            if (driverAtttribute.BaseAddress != 0x00)
                memoryRegionCount++;

            IIOPortRegion[] ioPortRegions = new IIOPortRegion[ioRegionCount];
            IMemoryRegion[] memoryRegions = new IMemoryRegion[memoryRegionCount];

            ioPortRegions[0] = new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange);

            if (driverAtttribute.AltBasePort != 0x00)
            {
                ioPortRegions[1] = new IOPortRegion(driverAtttribute.AltBasePort, driverAtttribute.AltPortRange);
            }

            if (driverAtttribute.BaseAddress != 0x00)
            {
                memoryRegions[0] = new MemoryRegion(driverAtttribute.BaseAddress, driverAtttribute.AddressRange);
            }

            IHardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions, memoryRegions, new InterruptHandler(resourceManager.InterruptManager, driverAtttribute.IRQ, hardwareDevice));

            hardwareDevice.Setup(hardwareResources);

            Mosa.Kernel.x86.Screen.NextLine();
            Mosa.CoolWorld.x86.Boot.BulletPoint();
            Console.Write("Adding device ");
            Boot.InBrackets(hardwareDevice.Name, Colors.White, Colors.LightGreen);
            Console.WriteLine();

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    deviceManager.Add(hardwareDevice);
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }

            }
        }