-
Notifications
You must be signed in to change notification settings - Fork 5
/
netkvm.ps1
executable file
·295 lines (247 loc) · 9.46 KB
/
netkvm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
##/***************************************
## Copyright (c) All rights reserved
##
## File: Library_WHQL_ENV_Parsing.ps1
##
## Authors (s)
##
## Mike Cao <[email protected]>
##
## This file is used to run netkvm related test cases automately
##
## This work is licensed under the terms of the GNU GPL,Version 2.
##
##****************************************/
function local:GetScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
. (Join-Path (GetScriptDirectory) "Library_HCK_MachinePoolAPI.ps1" )
. (Join-Path (GetScriptDirectory) "Library_WHQL_ENV_Parsing.ps1" )
$ObjectModel1 = LoadObjectModel "microsoft.windows.Kits.Hardware.objectmodel.dll"
$ObjectModel2 = LoadObjectModel "microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll"
function GetServerPlatformName($Manager)
{
$ServerPlatforms = New-Object System.Collections.ArrayList
$Manager.GetPlatforms() | foreach {
if (!($_.Code.Contains("IA64") -or $_.Code.Contains("ARM")) -and $_.Code.Contains("Server") )
{
$ServerPlatforms.Add($_.Code)
}
}
return $ServerPlatforms
}
function GetPlatformName($Manager)
{
$DesktopPlatforms = New-Object System.Collections.ArrayList
$Manager.GetPlatforms() | foreach {
if (!($_.Code.Contains("IA64") -or $_.Code.Contains("ARM") -or $_.Code.Contains("Server")) )
{
$DesktopPlatforms.Add($_.Code)
}
}
return $DesktopPlatforms
}
function CreateTestMachinePoolGroup ($RootPool ,$ProjectName)
{
$TestPoolGroupFlag = 0
GetChildMachinePools $RootPool| foreach {
if ($_.Name -eq $projectName)
{
Write-Host $_.Path
$TestPoolGroup = $_
$TestPoolGroupFlag = 1
} #end of if
} #end of GetChildPools() foreach
if ($TestPoolGroupFlag -eq "0")
{
$TestPoolGroup = CreateChildMachinePool $RootPool $ProjectName
} #end of load or create TestMachinePoolGroup
else
{
Write-Host $TestPoolGroup.Name is exists .no need to re-create one
}
return $TestPoolGroup
}
function CreateTestPool($TestPoolGroup ,$GuestNameSignature)
{
$TestMachinePoolFlag = 0
$TestPoolGroup.GetChildPools() | foreach {
if($_.Name -eq $GuestNameSignature) #if the pool exists ,move the previous guests to sub-pool
{
$TestPool = $_
$TestMachinePoolFlag = 1
}
} # end if GetChildPools()
if ($TestMachinePoolFlag -eq "0")
{
$TestPool= CreateChildMachinePool $TestPoolGroup $GuestNameSignature
}
return $TestPool
}
function CreateProject($Manager , $ProjectName)
{
$projectFlag = 0
$Manager.GetProjectNames() | foreach {
if ($_ -eq $ProjectName)
{
$Project = $Manager.GetProject($ProjectName)
$ProjectFlag = 1
} #end of if
} # end of GetProjectNames()
if ($ProjectFlag -eq "0")
{
$Project = $Manager.CreateProject($ProjectName)
} #end of if
return $Project
}
function CreateDeviceFamily($Manager, $Driver ,$HardwareIds)
{
$DeviceFamilyFlag = 0
$Manager.GetDeviceFamilies() | foreach {
Write-Host $_.name
if ($_.name -eq $Driver)
{
$DeviceFamily = $_
$DeviceFamilyFlag = 1
} #end of if
} #end of GetDeviceFamilies foreach
if ($DeviceFamilyFlag -eq "0")
{
$DeviceFamily = $Manager.CreateDeviceFamily($Driver, $HardwareIds)
} #end of if
return $DeviceFamily
}
function ManualAddFeatures( $Manager ,$OSPlatformCode)
{
$Manager.GetFeatures() | foreach {
Write-Host $OSPlatformCode
if ($OSPlatformCode.Contains("SERVER") -and $_.FullName -eq ("Device.Network.LAN.RSS"))
{
$Features = $_
}
if ($Platforms -contains $SUT_OSPlatform -and $_.FullName -eq ("Device.Network.LAN.PM"))
{
$Features = $_
}
}
return $Features
}
#Need to investigate again!!!
function MoveMachineToTestPool( $DefaultPool ,$GuestNameSignature ,$TestPool ,$Role ,$Driver)
{
#Write-Host "why i am not execute????"
#"How many machines in the machine pool {0}" -f $DefaultPool.GetMachines().Count
if ($Driver -eq "netkvm")
{
#Write-host SUT signratue is $GuestNameSignature
#Write-host Roles is {0} $Role
$DefaultPool.GetMachines() | foreach {
if ($_.Name.Contains($GuestNameSignature) -AND ($_.Name.SubString(12,1) -eq $Role) )
{
$Machine = $_
Write-Host the machine is moved
$aa=$DefaultPool.MoveMachineTo($_, $TestPool)
# no idea why after adding this line ,this function will return object type
#$Machine.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, 1)
#sleep 5
}
}
}
else
{
$DefaultPool.GetMachines() | foreach {
if ($_.Name.Contains($GuestNameSignature))
{
$Machine = $_
$DefaultPool.MoveMachineTo($Machine, $TestPool)
# no idea why after adding this line ,this function will return object type
#$Machine.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, 1)
#sleep 5
}
}
}
#Write-Host My machine ,what is your type $Machine.GetType()
return $Machine
}
function CheckStatus()
{
Write-Host now the VM is running now ,let us checking running status ..
}
function RunWHQLJobs
{
GetXMLValues
switch($Driver)
{
{$Driver -eq "viostor"}{Write-host "viostor";[string[]]$HardwareIds = "PCI\VEN_1AF4&DEV_1001&SUBSYS_00021AF4";$GuestNameSignature = $Driver_Version+"BLK"+$OSPlatform;break}
{$Driver -eq "netkvm"} {Write-host "netkvm"; [string[]]$HardwareIds = "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4";$GuestNameSignature = $Driver_Version+"NIC"+$OSPlatform;break}
{$Driver -eq "vioscsi"}{Write-host "vioscsi";[string[]]$HardwareIds = "PCI\VEN_1AF4&DEV_1004&SUBSYS_00081AF4";$GuestNameSignature = $Driver_Version+"SCS"+$OSPlatform;break}
{$Driver -eq "vioser"} {Write-host "vioser";[string[]]$HardwareIds = "PCI\VEN_1AF4&DEV_1003&SUBSYS_00031AF4";$GuestNameSignature = $Driver_Version+"SRL"+$OSPlatform;break}
{$Driver -eq "balloon"}{Write-host "balloon";[string[]]$HardwareIds = "PCI\VEN_1AF4&DEV_1002&SUBSYS_00051AF4";$GuestNameSignature = $Driver_Version+"BLN"+$OSPlatform;break}
default {Write-host Invalid driver name ,pls check your configuration file ,whether Driver_Name part is viostor netkvm vioscsi vioser balloon;return}
} # end of switch
GetKitValues
Write-Host GuestNameSignature is $GuestNameSignature
#Remove ARM and IA64 platform hosts
#load or create a project
$Project = CreateProject $Manager $GuestNameSignature # let's try to use GuestNameSignature instead of $Manager $ProjectName
#load or create TestMachinePoolGroup
$TestPoolGroup = CreateTestMachinePoolGroup $RootPool $ProjectName
#Load or create a DeviceFamily
$DeviceFamily = CreateDeviceFamily $Manager $Driver $HardwareIds
#create TestPool
$TestPool = CreateTestPool $TestPoolGroup $GuestNameSignature
"there are {0} machines in the default pool" -f $DefaultPool.GetMachines().Count
#Move the Machines to the TestingPool
#$SUT = New-Object Microsoft.Windows.Kits.Hardware.ObjectModel.WttMachine
$SUT = MoveMachineToTestPool $DefaultPool $GuestNameSignature $TestPool "C" $Driver
Write-Host SUT do you have a machinetype $SUT.GetType()
$MachineName = $SUT.Name
Write-Host SUT machine name is $MachineName
$SUT.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, 1)
sleep 20
$ProductInstance = $Project.CreateProductInstance($MachineName, $TestPool, $SUT.OSPlatform)
$TargetFamily = $ProductInstance.CreateTargetFamily($DeviceFamily)
"Targetdata count is {0}" -f $ProductInstance.FindTargetFromDeviceFamily($DeviceFamily).Count
#find all the devices in this machine pool that are in this device family
$ProductInstance.FindTargetFromDeviceFamily($DeviceFamily) | foreach {
#attempting to add target $_.Name on machine $_.Machine.Name to TargetFamily"
# and add those to the target family
# check this first, to make sure that this can be added to the target family
#"TargetData name is {0}" -f $_.Name
#"TargetData machine is {0}" -f $_.Machine.Name
if ($TargetFamily.IsValidTarget($_) -And $_.Machine.Name -eq $MachineName)
{
Write-host we want to add features $SUT.OSPlatform.Code
$Target = $TargetFamily.CreateTarget($_)
}
} #end of foreach
#Move Slave Host for netkvm
if($Driver -eq "netkvm")
{
$Features = ManualAddFeatures $Manager $SUT.OSPlatform.Code
$Target.AddFeature($Features)
$SlaveMachine = MoveMachineToTestPool $DefaultPool $GuestNameSignature $TestPool "S"
$SlaveMachine.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, 1)
sleep 20
}
"mike cao want {0} " -f $TestPool.GetMachines().Count
$Target.GetTests()| foreach{
"Test name :{0}" -f $_.Name
$MachineRole = $_.GetMachineRole() #return machineset
if ($MachineRole -eq "" -OR $MachineRole -eq $null)
{
$_.QueueTest()
"job run"
}
else
{
$MachineRole.Roles[1].AddMachine($SlaveMachine)
$_.QueueTest($MachineRole)
"slave job run "
} #end of else
} # end of TestPool.GetTests
checkStatus
}
. RunWHQLJobs