Esempio n. 1
0
 public NullAppInstall(string InName, TargetDeviceNull InDevice, string InCommandLine)
 {
     Name        = InName;
     Device      = InDevice;
     CommandLine = InCommandLine;
 }
Esempio n. 2
0
        /// <summary>
        /// Installs and launches all of our roles and returns an UnrealSessonInstance that represents the aggregate
        /// of all of these processes. Will perform retries if errors with devices are encountered so this is a "best
        /// attempt" at running with the devices provided
        /// </summary>
        /// <returns></returns>
        public UnrealSessionInstance LaunchSession()
        {
            SessionInstance = null;

            // tries to find devices and launch our session. Will loop until we succeed, we run out of devices/retries, or
            // something fatal occurs..
            while (SessionInstance == null && Globals.CancelSignalled == false)
            {
                int Retries   = 5;
                int RetryWait = 120;

                IEnumerable <UnrealSessionRole> RolesNeedingDevices = SessionRoles.Where(R => R.IsNullRole() == false);

                while (ReservedDevices.Count() < RolesNeedingDevices.Count())
                {
                    // get devices
                    TryReserveDevices();

                    if (Globals.CancelSignalled)
                    {
                        break;
                    }

                    // if we failed to get enough devices, show a message and wait
                    if (ReservedDevices.Count() != SessionRoles.Count())
                    {
                        if (Retries == 0)
                        {
                            throw new AutomationException("Unable to acquire all devices for test.");
                        }
                        Log.Info("\nUnable to find enough device(s). Waiting {0} secs (retries left={1})\n", RetryWait, --Retries);
                        Thread.Sleep(RetryWait * 1000);
                    }
                }

                if (Globals.CancelSignalled)
                {
                    return(null);
                }

                Dictionary <IAppInstall, UnrealSessionRole> InstallsToRoles = new Dictionary <IAppInstall, UnrealSessionRole>();

                // create a copy of our list
                IEnumerable <ITargetDevice> DevicesToInstallOn = ReservedDevices.ToArray();

                bool InstallSuccess = true;


#if !__MonoCS__
                // count how many desktop clients
                IEnumerable <UnrealSessionRole> DesktopClients = SessionRoles.Where(R => R.Platform == BuildHostPlatform.Current.Platform).Where(R => R.RoleType.IsClient());

                if (DesktopClients.Count() > 1)
                {
                    int NumClientRows = (int)Math.Ceiling(DesktopClients.Count() / 2.0);

                    var ScreenRect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;

                    double Ratio = 16.0 / 9.0;

                    // pick width
                    int DesiredWidth = ScreenRect.Width / 2;

                    // height at 16:9 aspect
                    int DesiredHeight = (int)(DesiredWidth / Ratio);

                    // constrain width if the screen can't have that many rows
                    if (DesiredHeight * NumClientRows > ScreenRect.Height)
                    {
                        DesiredHeight = ScreenRect.Height / NumClientRows;
                        DesiredWidth  = (int)(DesiredHeight * Ratio);
                    }

                    // now set all these params and disable the regular params that pick windowed stuff
                    for (int i = 0; i < DesktopClients.Count(); i++)
                    {
                        UnrealSessionRole Role = DesktopClients.ElementAt(i);
                        int Row    = i / 2;
                        int Column = i - (Row * 2);

                        // this is hacky, but not sure if a better way to do it right now without changing interfaces in a TBD way
                        UnrealTestConfiguration ConfigOptions = Role.Options as UnrealTestConfiguration;

                        if (ConfigOptions != null)
                        {
                            ConfigOptions.IgnoreDefaultResolutionAndWindowMode = true;
                        }

                        Role.CommandLine += string.Format(" -WinX={0} -WinY={1} -ResX={2} -ResY={3} -windowed",
                                                          Column * DesiredWidth, Row * DesiredHeight, DesiredWidth, DesiredHeight);
                    }
                }
#endif

                // sort by constraints, so that we pick constrained devices first
                List <UnrealSessionRole> SortedRoles = SessionRoles.OrderBy(R => R.Constraint.IsIdentity() ? 1 : 0).ToList();

                // first install all roles on these devices
                foreach (var Role in SortedRoles)
                {
                    ITargetDevice Device = null;

                    if (Role.IsNullRole() == false)
                    {
                        Device = DevicesToInstallOn.Where(D => D.IsConnected && D.Platform == Role.Platform &&
                                                          (Role.Constraint.IsIdentity() || DevicePool.Instance.GetConstraint(D) == Role.Constraint)).First();

                        DevicesToInstallOn = DevicesToInstallOn.Where(D => D != Device);
                    }
                    else
                    {
                        Device = new TargetDeviceNull(string.Format("Null{0}", Role.RoleType));
                    }

                    var OtherRoles = SortedRoles.Where(R => R != Role);

                    // create a config from the build source (this also applies the role options)
                    UnrealAppConfig AppConfig = BuildSource.CreateConfiguration(Role, OtherRoles);

                    // todo - should this be elsewhere?
                    AppConfig.Sandbox = Sandbox;

                    IAppInstall Install = null;

                    try
                    {
                        Install = Device.InstallApplication(AppConfig);
                    }
                    catch (System.Exception Ex)
                    {
                        // Warn, ignore the device, and do not continue
                        Log.Info("Failed to install app onto device {0} for role {1}. {2}. Will retry with new device", Device, Role, Ex);
                        MarkProblemDevice(Device);
                        InstallSuccess = false;
                        break;
                    }

                    if (Globals.CancelSignalled)
                    {
                        break;
                    }

                    // Device has app installed, give role a chance to configure device
                    Role.ConfigureDevice?.Invoke(Device);

                    InstallsToRoles[Install] = Role;
                }

                if (InstallSuccess == false)
                {
                    // release all devices
                    ReleaseDevices();
                }


                if (InstallSuccess && Globals.CancelSignalled == false)
                {
                    List <UnrealSessionInstance.RoleInstance> RunningRoles = new List <UnrealSessionInstance.RoleInstance>();

                    // Now try to run all installs on their devices
                    foreach (var InstallRoleKV in InstallsToRoles)
                    {
                        IAppInstall CurrentInstall = InstallRoleKV.Key;

                        bool Success = false;

                        try
                        {
                            IAppInstance Instance = CurrentInstall.Run();

                            if (Instance != null || Globals.CancelSignalled)
                            {
                                RunningRoles.Add(new UnrealSessionInstance.RoleInstance(InstallRoleKV.Value, Instance));
                            }

                            Success = true;
                        }
                        catch (DeviceException Ex)
                        {
                            // shutdown all
                            Log.Warning("Device {0} threw an exception during launch. \nException={1}", CurrentInstall.Device, Ex.Message);
                            Success = false;
                        }

                        if (Success == false)
                        {
                            Log.Warning("Failed to start build on {0}. Marking as problem device and retrying with new set", CurrentInstall.Device);

                            // terminate anything that's running
                            foreach (UnrealSessionInstance.RoleInstance RunningRole in RunningRoles)
                            {
                                Log.Info("Shutting down {0}", RunningRole.AppInstance.Device);
                                RunningRole.AppInstance.Kill();
                                RunningRole.AppInstance.Device.Disconnect();
                            }

                            // mark that device as a problem
                            MarkProblemDevice(CurrentInstall.Device);

                            // release all devices
                            ReleaseDevices();

                            break;                             // do not continue loop
                        }
                    }

                    if (RunningRoles.Count() == SessionRoles.Count())
                    {
                        SessionInstance = new UnrealSessionInstance(RunningRoles.ToArray());
                    }
                }
            }

            return(SessionInstance);
        }
Esempio n. 3
0
        /// <summary>
        /// Installs and launches all of our roles and returns an UnrealSessonInstance that represents the aggregate
        /// of all of these processes. Will perform retries if errors with devices are encountered so this is a "best
        /// attempt" at running with the devices provided
        /// </summary>
        /// <returns></returns>
        public UnrealSessionInstance LaunchSession()
        {
            SessionInstance = null;

            // tries to find devices and launch our session. Will loop until we succeed, we run out of devices/retries, or
            // something fatal occurs..
            while (SessionInstance == null && Globals.CancelSignalled == false)
            {
                int Retries   = 5;
                int RetryWait = 120;

                IEnumerable <UnrealSessionRole> RolesNeedingDevices = SessionRoles.Where(R => R.IsNullRole() == false);

                while (ReservedDevices.Count() < RolesNeedingDevices.Count())
                {
                    // get devices
                    TryReserveDevices();

                    if (Globals.CancelSignalled)
                    {
                        break;
                    }

                    // if we failed to get enough devices, show a message and wait
                    if (ReservedDevices.Count() != SessionRoles.Count())
                    {
                        if (Retries == 0)
                        {
                            throw new AutomationException("Unable to acquire all devices for test.");
                        }
                        Log.Info("\nUnable to find enough device(s). Waiting {0} secs (retries left={1})\n", RetryWait, --Retries);
                        Thread.Sleep(RetryWait * 1000);
                    }
                }

                if (Globals.CancelSignalled)
                {
                    return(null);
                }

                Dictionary <IAppInstall, UnrealSessionRole> InstallsToRoles = new Dictionary <IAppInstall, UnrealSessionRole>();

                // create a copy of our list
                IEnumerable <ITargetDevice> DevicesToInstallOn = ReservedDevices.ToArray();

                bool InstallSuccess = true;

                // sort by constraints, so that we pick constrained devices first
                List <UnrealSessionRole> SortedRoles = SessionRoles.OrderBy(R => R.Constraint.IsIdentity() ? 1 : 0).ToList();

                // first install all roles on these devices
                foreach (var Role in SortedRoles)
                {
                    ITargetDevice Device = null;

                    if (Role.IsNullRole() == false)
                    {
                        Device = DevicesToInstallOn.Where(D => D.IsConnected && D.Platform == Role.Platform &&
                                                          (Role.Constraint.IsIdentity() || DevicePool.Instance.GetConstraint(D) == Role.Constraint)).First();

                        DevicesToInstallOn = DevicesToInstallOn.Where(D => D != Device);
                    }
                    else
                    {
                        Device = new TargetDeviceNull(string.Format("Null{0}", Role.RoleType));
                    }

                    // create a config from the build source (this also applies the role options)
                    UnrealAppConfig AppConfig = BuildSource.CreateConfiguration(Role);

                    // todo - should this be elsewhere?
                    AppConfig.Sandbox = Sandbox;

                    IAppInstall Install = null;

                    try
                    {
                        Install = Device.InstallApplication(AppConfig);
                    }
                    catch (System.Exception Ex)
                    {
                        // Warn, ignore the device, and do not continue
                        Log.Info("Failed to install app onto device {0} for role {1}. {2}. Will retry with new device", Device, Role, Ex);
                        MarkProblemDevice(Device);
                        InstallSuccess = false;
                        break;
                    }


                    if (Globals.CancelSignalled)
                    {
                        break;
                    }

                    InstallsToRoles[Install] = Role;
                }

                if (InstallSuccess == false)
                {
                    // release all devices
                    ReleaseDevices();
                }


                if (InstallSuccess && Globals.CancelSignalled == false)
                {
                    List <UnrealSessionInstance.RoleInstance> RunningRoles = new List <UnrealSessionInstance.RoleInstance>();

                    // Now try to run all installs on their devices
                    foreach (var InstallRoleKV in InstallsToRoles)
                    {
                        IAppInstall CurrentInstall = InstallRoleKV.Key;

                        bool Success = false;

                        try
                        {
                            IAppInstance Instance = CurrentInstall.Run();

                            if (Instance != null || Globals.CancelSignalled)
                            {
                                RunningRoles.Add(new UnrealSessionInstance.RoleInstance(InstallRoleKV.Value, Instance));
                            }

                            Success = true;
                        }
                        catch (DeviceException Ex)
                        {
                            // shutdown all
                            Log.Warning("Device {0} threw an exception during launch. \nException={1}", CurrentInstall.Device, Ex.Message);
                            Success = false;
                        }

                        if (Success == false)
                        {
                            Log.Warning("Failed to start build on {0}. Marking as problem device and retrying with new set", CurrentInstall.Device);

                            // terminate anything that's running
                            foreach (UnrealSessionInstance.RoleInstance RunningRole in RunningRoles)
                            {
                                Log.Info("Shutting down {0}", RunningRole.AppInstance.Device);
                                RunningRole.AppInstance.Kill();
                                RunningRole.AppInstance.Device.Disconnect();
                            }

                            // mark that device as a problem
                            MarkProblemDevice(CurrentInstall.Device);

                            // release all devices
                            ReleaseDevices();

                            break;                             // do not continue loop
                        }
                    }

                    if (RunningRoles.Count() == SessionRoles.Count())
                    {
                        SessionInstance = new UnrealSessionInstance(RunningRoles.ToArray());
                    }
                }
            }

            return(SessionInstance);
        }