On 08/12/2010 09:08 AM, Yiqiao Pu wrote:
>  On 07/22/2010 06:14 PM, Michael Goldish wrote:
>> This C# program should run on a DTM/WHQL server.  It's used by the
>> whql_submission test to schedule and monitor device submission jobs.
>>
>> Note: the binary is copied to the server at run time, so it doesn't need to 
>> be
>> packaged in winutils.iso.
>>
>> Changes from v1:
>> - Take a job filter regex from the user, and run only the jobs whose names
>>   match the regex.  This is useful for running individual tests instead of
>>   whole submissions which can take many hours to run.
>> - When test execution completes set the client machine's state to Unsafe and
>>   then Reset.
>> - Instead of looking for the requested test device and failing immediately if
>>   it isn't found, allow up to 2 minutes for it to show up.
>> - Add the job ID of each job to the result list printed to stdout.
>>
>> Signed-off-by: Michael Goldish <[email protected]>
>> ---
>>  client/tests/kvm/deps/whql_submission_15.cs  |  289 
>> ++++++++++++++++++++++++++
>>  client/tests/kvm/deps/whql_submission_15.exe |  Bin 0 -> 10240 bytes
>>  2 files changed, 289 insertions(+), 0 deletions(-)
>>  create mode 100644 client/tests/kvm/deps/whql_submission_15.cs
>>  create mode 100644 client/tests/kvm/deps/whql_submission_15.exe
>>
>> diff --git a/client/tests/kvm/deps/whql_submission_15.cs 
>> b/client/tests/kvm/deps/whql_submission_15.cs
>> new file mode 100644
>> index 0000000..bf6e136
>> --- /dev/null
>> +++ b/client/tests/kvm/deps/whql_submission_15.cs
>> @@ -0,0 +1,289 @@
>> +// DTM submission automation program
>> +// Author: Michael Goldish <[email protected]>
>> +// Based on sample code by Microsoft.
>> +
>> +// Note: this program has only been tested with DTM version 1.5.
>> +// It might fail to work with other versions, specifically because it uses
>> +// a few undocumented methods/attributes.
>> +
>> +using System;
>> +using System.Collections.Generic;
>> +using System.Text.RegularExpressions;
>> +using Microsoft.DistributedAutomation.DeviceSelection;
>> +using Microsoft.DistributedAutomation.SqlDataStore;
>> +
>> +namespace automate0
>> +{
>> +    class AutoJob
>> +    {
>> +        static int Main(string[] args)
>> +        {
>> +            if (args.Length != 5)
>> +            {
>> +                Console.WriteLine("Error: incorrect number of command line 
>> arguments");
>> +                Console.WriteLine("Usage: {0} serverName clientName 
>> machinePoolName submissionName timeout",
>> +                    System.Environment.GetCommandLineArgs()[0]);
>> +                return 1;
>> +            }
>> +            string serverName = args[0];
>> +            string clientName = args[1];
>> +            string machinePoolName = args[2];
>> +            string submissionName = args[3];
>> +            double timeout = Convert.ToDouble(args[4]);
>> +
>> +            try
>> +            {
>> +                // Initialize DeviceScript and connect to data store
>> +                Console.WriteLine("Initializing DeviceScript object");
>> +                DeviceScript script = new DeviceScript();
>> +                Console.WriteLine("Connecting to data store");
>> +
>> +                script.ConnectToNamedDataStore(serverName);
>> +
>> +                // Find client machine
>> +                IResourcePool rootPool = script.GetResourcePoolByName("$");
>> +                Console.WriteLine("Looking for client machine '{0}'", 
>> clientName);
>> +                IResource machine = null;
>> +                while (true)
>> +                {
>> +                    try
>> +                    {
>> +                        machine = rootPool.GetResourceByName(clientName);
>> +                    }
>> +                    catch (Exception e)
>> +                    {
>> +                        Console.WriteLine("Warning: " + e.Message);
>> +                    }
>> +                    // Make sure the machine is valid
>> +                    if (machine != null &&
>> +                        machine.OperatingSystem != null &&
>> +                        machine.OperatingSystem.Length > 0 &&
>> +                        machine.ProcessorArchitecture != null &&
>> +                        machine.ProcessorArchitecture.Length > 0 &&
>> +                        machine.GetDevices().Length > 0)
>> +                        break;
>> +                    System.Threading.Thread.Sleep(1000);
>> +                }
>> +                Console.WriteLine("Client machine '{0}' found ({1}, {2})",
>> +                    clientName, machine.OperatingSystem, 
>> machine.ProcessorArchitecture);
>> +
>> +                // Create machine pool and add client machine to it
>> +                // (this must be done because jobs cannot be scheduled for 
>> machines in the
>> +                // default pool)
>> +                try
>> +                {
>> +                    script.CreateResourcePool(machinePoolName, 
>> rootPool.ResourcePoolId);
>> +                }
>> +                catch (Exception e)
>> +                {
>> +                    Console.WriteLine("Warning: " + e.Message);
>> +                }
>> +                IResourcePool newPool = 
>> script.GetResourcePoolByName(machinePoolName);
>> +                Console.WriteLine("Moving the client machine to pool 
>> '{0}'", machinePoolName);
>> +                machine.ChangeResourcePool(newPool);
>> +
>> +                // Reset client machine
>> +                if (machine.Status != "Ready")
>> +                {
>> +                    Console.WriteLine("Changing the client machine's status 
>> to 'Reset'");
>> +                    while (true)
>> +                    {
>> +                        try
>> +                        {
>> +                            machine = 
>> rootPool.GetResourceByName(clientName);
>> +                            machine.ChangeResourceStatus("Unsafe");
>> +                            System.Threading.Thread.Sleep(5000);
>> +                            machine.ChangeResourceStatus("Reset");
>> +                            break;
>> +                        }
>> +                        catch (Exception e)
>> +                        {
>> +                            Console.WriteLine("Warning: " + e.Message);
>> +                        }
>> +                        System.Threading.Thread.Sleep(5000);
>> +                    }
>> +                    Console.WriteLine("Waiting for client machine to be 
>> ready");
>> +                    while (machine.Status != "Ready")
>> +                    {
>> +                        try
>> +                        {
>> +                            machine = 
>> rootPool.GetResourceByName(clientName);
>> +                        }
>> +                        catch (Exception e)
>> +                        {
>> +                            Console.WriteLine("Warning: " + e.Message);
>> +                        }
>> +                        System.Threading.Thread.Sleep(1000);
>> +                    }
>> +                }
>> +                Console.WriteLine("Client machine is ready");
>> +
>> +                // Get requested device regex and look for a matching device
>> +                Console.WriteLine("Device to test: ");
>> +                Regex deviceRegex = new Regex(Console.ReadLine(), 
>> RegexOptions.IgnoreCase);
>> +                Console.WriteLine("Looking for device '{0}'", deviceRegex);
>> +                IDevice device;
>> +                DateTime endTime = DateTime.Now.AddSeconds(120);
>> +                while (DateTime.Now < endTime)
>> +                {
>> +                    machine = rootPool.GetResourceByName(clientName);
>> +                    Console.WriteLine("(Client machine has {0} devices)", 
>> machine.GetDevices().Length);
>> +                    foreach (IDevice d in machine.GetDevices())
>> +                    {
>> +                        if (deviceRegex.IsMatch(d.FriendlyName))
>> +                        {
>> +                            device = d;
>> +                            goto deviceFound;
>> +                        }
>> +                    }
>> +                    System.Threading.Thread.Sleep(5000);
>> +                }
>> +                Console.WriteLine("Error: device '{0}' not found", 
>> deviceRegex);
>> +                return 1;
>> +
>> +            deviceFound:
>> +                Console.WriteLine("Found device '{0}'", 
>> device.FriendlyName);
>> +
>> +                // Get requested jobs regex
>> +                Console.WriteLine("Jobs to run: ");
>> +                Regex jobRegex = new Regex(Console.ReadLine(), 
>> RegexOptions.IgnoreCase);
>> +
>> +                // Create submission
>> +                Object[] existingSubmissions = 
>> script.GetSubmissionByName(submissionName);
>> +                if (existingSubmissions.Length > 0)
>> +                {
>> +                    Console.WriteLine("Submission '{0}' already exists -- 
>> removing it",
>> +                        submissionName);
>> +                    
>> script.DeleteSubmission(((ISubmission)existingSubmissions[0]).Id);
>> +                }
>> +                Console.WriteLine("Creating submission '{0}'", 
>> submissionName);
>> +                ISubmission submission = 
>> script.CreateHardwareSubmission(submissionName,
>> +                    newPool.ResourcePoolId, device.InstanceId);
>> +
> Hi Michael,
> 
> Your program is using CreateHardwareSubmission() to new a submission
> which use for the test of devcies that does not have third part drivers,
> but we want to test some of our own drivers which may use
> CreateDriverSubmission() to new a submission. Do you have any plan to
> extend the program now?
> 
> Best Regards
> Yiqiao Pu

Yes, I do intend to extend the program.  If CreateHardwareSubmission()
isn't enough for all cases, I'll either add the option to use
CreateDriverSubmission() to the existing program or write an additional
little program that uses it.  It will take me a little while though, so
I apologize if you have to wait a bit.  Can you give me an example of a
driver you want to test, and tell me where I can get it (the .inf and
.sys files)?

Thanks,
Michael
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to