none
Object Model: How to run HCK tests on same target on different computers? RRS feed

  • Question

  • Hi all,

    I have a target "A" on two computers "X" and "Y". I want to distribute tests on these two machines for target A. How do we do it using Object Model? Currently what I have done is

    1. Create a device family using target hardware id

    2. Create a target family using that device family.

    3. Added 2 targets on X and Y to target family.

    4. call test.QueueTest(machinelist) method on each test

    5. Get results from each machine

    The problem with this method is when i try to get results from each machine, i get duplicated results. For exp, if I ran test 1 on X, test2 on Y, ts shows Passed in results from both machine X, Y. It should only have said "Passed" in result list from X, "NotRun" in result list from Y.

    Am I doing something wrong in my logic?

    Thanks,

    Disha

    Monday, January 28, 2013 7:23 PM

All replies

  • Hi Disha,

    Can you tell us what's the value for Test.ScheduleOptions for the tests that you're scheduling?

    By default a test has ScheduleOnAnyTarget which means the test will be scheduled on any one of these targets in the TargetFamily. If a test is distributed, then the test result across targets in the TargetFamily will be the same instance.

    Also, I am not sure I understand how you get results from each machine? Can you elaborate a bit? The recommended way is to retrieve test results from the tests in the TargetFamily.

    Thanks,

    Prakash

    Wednesday, January 30, 2013 9:05 PM
  • I should not have used word "distributed". I want to have a script which tests same target on multiple computers, but runs subset of tests on each computer. If target A has 10 tests, computer 1 should run 5 tests, computer 2 should run 5 tests. I have the sample code that i am working on. Please see below:

    $DATED_DIR= get-date -format "MMddyy_HHmmss"


    $ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dll")
    $DBConnection = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll")
    $Submission = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.submission.dll")
    $FilterEngine = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "Microsoft.Windows.Kits.Hardware.FilterEngine.dll")

    #$ControllerName = "WIN-HCK-QFE5"

    $serverName = "WIN-HCK-QFE5"


    write-Host "Usage: %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -file ListProjects.ps1 <<ControllerName>>"

    # connect to the WIN-HCK-QFE5 server
    if ($serverName -eq $null -OR $serverName -eq "")
    {
        write-host "No Controller name specified"
        return
    }
    else
    {
        write-host connecting to the controller $serverName
    }

    #create Project Manager
    $Manager = New-Object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseprojectManager -args $serverName, DTMJobs

    #Get Root Pool
    $RootPool = $Manager.GetRootMachinePool()
    if ($RootPool -eq $null)
    {
     write-host "No Root Pool found"
     return
    }

    #Create a dated project
    $newProject = $Manager.CreateProject($DATED_DIR)
    if ($newProject -eq $null)
    {
     write-host "No Project Created"
     return
    }

    $projectPoolName = $DATED_DIR +"_Pool"

    $projectMachinePool = $RootPool.CreateChildPool($projectPoolName)

    $poolName = $RootPool.GetChildPools() | ?{$_.Name -eq $projectPoolName}

    write-host "My Pool:" $poolName.Name

    $targetName1 = "X"
    $testMachine1 = $RootPool.DefaultPool.GetMachines() | ?{$_.Name -eq $targetName1}
    $targetName2 = "Y"
    $testMachine2 = $RootPool.DefaultPool.GetMachines() | ?{$_.Name -eq $targetName2}

    #Move the machine from Default machine to pool your Project Pool
    $RootPool.DefaultPool.MoveMachineTo($testMachine1, $projectMachinePool)
    $RootPool.DefaultPool.MoveMachineTo($testMachine2, $projectMachinePool)

    $testmachine1.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, -1)
    $testmachine2.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, -1)


    $osPlatform = $projectMachinePool.GetMachines()[0].OSPlatform

    write-host "$osPlatform.Name"
    $productInstance = $newProject.CreateProductInstance($osPlatform.name, $projectMachinePool, $osPlatform)

    #Adds targets (Device B is target name) from Machines in Project Machine Pool to Product Instance
    function GetTargetsForProductInstance ($machine) {
     $dataList = $machine.gettesttargets([Microsoft.Windows.Kits.Hardware.objectModel.TargetType]::Device)
     foreach ($target in $dataList)
     {
      if($target.Name -eq "Device B") {
       break
      }
     }
     return $target
    }

    #Run susbset of tests from TestList1, TestList2 files on targets
    function RunTestsOnTarget ($target, $ch) {
     write-host "TARGET MACHINE NAME:" $target.Machine.Name
     $tests = $target.gettests()
     switch ($ch)
      {
       1 {
        $testlist = Get-Content C:\Users\Administrator\Documents\HCK_Automation\TestList1.txt
       }
       2 {
        $testlist = Get-Content C:\Users\Administrator\Documents\HCK_Automation\TestList2.txt
       }
      }
     foreach($test in $tests) {
      if($testlist -contains $test.Name) {
       $test.QueueTest()
      }
     }
    }

    foreach ($machineObj in $projectMachinePool.GetMachines()) {
     $targetObj = GetTargetsForProductInstance $machineObj
     if ($targetObj -ne $null) {
      $productInstance.CreateTarget($targetObj)
     }
    }

     

    $i=1
    foreach($obj in $productInstance.Gettargets()) {
     RunTestsOnTarget $obj $i
     $i++
    }

     
    for(;;) {
     if($newProject.Info.status -ne "Running") {
      write-host "Project completed"
      break
     }
    }
    write-host "Script finished"

     

    Friday, February 1, 2013 4:58 AM
  • It would be really heplful if you could reply. I have been working on this for months.
    Friday, February 1, 2013 4:59 AM
  • I have 2 solutions - one using Device Family and the other one is posted above. I think second option is easier to use (without Device family). That's why I posted that. Let me know if my logic is wrong.
    Friday, February 1, 2013 5:02 AM
  • Hi Disha,

    May I ask, why do you want to distribute tests on multiple machines, if they can be run on single machine for the selected target? to save time or other reason? How would you combine the test results from different machines for the same target in a same package?

    Even I work on DTM automation for my company, it might help me too. :)

    Thanks and regards,

    Nilesh

    Friday, February 1, 2013 6:09 AM
  • To save time. My main requirement is to run WHCK tests as part of Build acceptance process and get the results. After every nightly build, we want to schedule tests for same target on multiple machines. I don't know how to combine test results from different machines. In the solution above, I just loop through each test.status in $project.gettests(). Currently, $project.gettests() gives me the incorrect total number of tests. For exp, the target that I am testing has 28 tests but I get 30 tests in the solution above.

    All the 28 tests take around 3 days to complete. I don't know if the solution above is correct. If you have some suggestions, please let me know.

    Friday, February 1, 2013 7:24 AM
  • Did you check whether PI/TargetFamily is same for all tests on respective target machine? what are those additional 2 tests? are they duplicate of some others in the same tests set?
    Tuesday, February 5, 2013 9:02 AM