public static void Main(string[] args)
        {
            int machinePoolSize = 64;

            MachinePool machinePool = new MachinePool(machinePoolSize);

            Console.Write("Random free machine IDs while setting them busy: ");

            while (machinePool.FreeCount() > 0)
            {
                int freeMachineId = machinePool.GetRandomFree();
                Console.Write(freeMachineId + " ");
                machinePool.SetBusy(freeMachineId);
            }

            Console.WriteLine();

            Console.Write("Random free machine IDs while setting machines free in order: ");

            for (int machineId = 0; machineId < machinePoolSize; machineId++)
            {
                machinePool.SetFree(machineId);
                Console.Write(machinePool.GetRandomFree() + " ");
            }

            Console.WriteLine();
        }
Example #2
0
        //create pool
        public static MachinePool CreatePool(ProjectManager manager, string TestPoolName)
        {
            MachinePool testPool = null;

            try
            {
                MachinePool rootPool = manager.GetRootMachinePool();
                //create test pool
                Log("Creating test pool");
                testPool = manager.GetRootMachinePool().GetChildPools().Where(x => x.Name == TestPoolName).FirstOrDefault();
                if (testPool == null)
                {
                    Log("Pool:- " + TestPoolName + " not found, creating");
                    testPool = manager.GetRootMachinePool().CreateChildPool(TestPoolName);
                    Log("Created " + TestPoolName);
                }
                else
                {
                    Log("Test pool " + testPool.Name + " already found");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}", e.ToString());
            }
            return(testPool);
        }
Example #3
0
        //list tests
        public static IList <Test> GetTestsSystemLevel(Machine TargetName, MachinePool testPool, Project project)
        {
            IList <Test> Test_List = new List <Test> {
            };

            try
            {
                OSPlatform      platform = testPool.GetMachines().First().OSPlatform;
                ProductInstance pi       = project.CreateProductInstance(project.Name, testPool, platform);
                TargetData      data     = pi.FindTargetFromSystem(TargetName);
                if (data == null)
                {
                    Log("Error! No target data found in system " + TargetName.Name);
                    Console.ReadLine();
                    return(Test_List);
                }
                pi.CreateTarget(data);
                IList <Test> tests = project.GetTests();
                if (tests.Count == 0)
                {
                    Log("Warning! Test list count is 0");
                    Console.ReadLine();
                    return(Test_List);
                }
                Test_List = tests;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception :- {0}", e.ToString());
            }
            return(Test_List);
        }
Example #4
0
        //add target machine to test pool
        public static Machine LookForMachine(ProjectManager manager, string TargetName, MachinePool testpool)
        {
            Machine TargetMachine = null;

            try
            {
                bool bFoundInDefault = false;
                bool bFoundInTest    = false;

                MachinePool RootPool = manager.GetRootMachinePool();
                //check if machine is in default pool or test pool
                foreach (Machine m in testpool.GetMachines())
                {
                    if (m.Name == TargetName)
                    {
                        bFoundInTest  = true;
                        TargetMachine = m;
                    }
                }
                foreach (Machine m in RootPool.DefaultPool.GetMachines())
                {
                    if (m.Name == TargetName)
                    {
                        bFoundInDefault = true;
                        TargetMachine   = m;
                    }
                }
                if (bFoundInTest == true)
                {
                    Log("Machine already in test pool!");
                    return(TargetMachine);
                }
                Log("Checking for machine " + TargetName + " in default pool");
                if (bFoundInDefault == true)
                {
                    Log("Machine " + TargetName + " is in default pool");
                    Log("Moving to test pool");
                    RootPool.DefaultPool.MoveMachineTo(TargetMachine, testpool);
                    Log("Moved machine " + TargetMachine.Name + " from default to test pool");
                    return(TargetMachine);
                }
                if (bFoundInDefault == false)
                {
                    Log("Warning!!! Machine " + TargetName + " not found in default pool too");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception:-{0}", e.ToString());
            }
            return(TargetMachine);
        }
Example #5
0
        //MAIN
        static void Main(string[] args)
        {
            try
            {
                string controllerName = "HLK-RS3";
                string projectName = null, TargetName = null, TestPoolName = null;
                if (args.Length != 3)   //syntax
                {
                    Console.WriteLine("Invalid arguments:-\nSyntax:-\nHLKAutomation.exe TargetName projectName TestPoolName");
                    return;
                }
                TargetName   = args[0];
                projectName  = args[1];
                TestPoolName = args[2];
                string     sExePath      = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string     playlistpath  = Path.Combine(sExePath, "playlist.xml");
                List <int> PassFailCount = new List <int> {
                };
                List <string> Results    = new List <string> {
                };
                if (File.Exists(Path.Combine(sExePath, sLogFile)))     //delete log file if exist
                {
                    File.Delete(Path.Combine(sExePath, sLogFile));
                }
                ProjectManager manager       = ConnectToController(controllerName);                 //connect to controller
                Project        project       = CreateProject(manager, projectName);                 //create project if not exist
                MachinePool    testpool      = CreatePool(manager, TestPoolName);                   //create test pool
                Machine        TargetMachine = LookForMachine(manager, TargetName, testpool);       //check if test machine is there in test pool or not, if in default, move to test pool
                if (TargetMachine != null)                                                          //if system is valid
                {
                    PrepareTargetMachine(TargetMachine);                                            //now make it ready
                    IList <Test> test_list = GetTestsDeviceLevel(TargetMachine, testpool, project); //get list of tests
                    Console.WriteLine("{0} tests found", test_list.Count.ToString());
                    test_list = LoadPlaylist(project, playlistpath);                                //load playlist
                    Results   = RunTests(project, test_list, 2);                                    //run filtered tests
                    Console.ReadLine();
                }

                else
                {
                    Console.WriteLine("Error! Machine is N/A");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in main:- {0}", e.ToString());
            }
        }
Example #6
0
        //list tests
        public static IList <Test> GetTestsDeviceLevel(Machine TargetName, MachinePool testPool, Project project)
        {
            IList <Test> Test_List = new List <Test> {
            };

            try
            {
                OSPlatform      platform = testPool.GetMachines().First().OSPlatform;
                ProductInstance pi       = project.CreateProductInstance(project.Name, testPool, platform);
                //Device Level
                ReadOnlyCollection <TargetData> devices = testPool.GetMachines().First().GetTestTargets();
                TargetData device_tpm = null;
                //Find TPM device
                foreach (TargetData device in devices)
                {
                    if (device.Name.Contains("Trusted Platform Module 2.0"))
                    {
                        Console.WriteLine(device.Name);
                        device_tpm = device;
                    }
                }
                pi.CreateTarget(device_tpm);
                IList <Test> tests_tpm = project.GetTests();
                if (tests_tpm.Count == 0)
                {
                    Log("Warning! Device Level Test list count is 0");
                    Console.ReadLine();
                    return(tests_tpm);
                }
                Test_List = tests_tpm;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception :- {0}", e.ToString());
            }
            return(Test_List);
        }