Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

988 lines
29 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: autoboottest.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is an example of a perl script in the NT postbuild
  7. # environment.
  8. #
  9. # Version: <1.00> (<mm/dd/yyyy>) : (<your alias>) <Purpose>
  10. # <1.01> (<mm/dd/yyyy>) : (<your alias>) <Purpose>
  11. #---------------------------------------------------------------------
  12. # Set Package
  13. # <Set your package name of your perl module>
  14. package autoboottest;
  15. # Set the script name
  16. # <Set your script name>
  17. $ENV{script_name} = 'autoboottest.pl';
  18. # Set version
  19. # <Set the version of your script>
  20. $VERSION = '1.00';
  21. # Set required perl version
  22. # <Set the version of perl that your script requires>
  23. require 5.003;
  24. # Use section
  25. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  26. use lib $ENV{RAZZLETOOLPATH};
  27. use GetParams;
  28. use LocalEnvEx;
  29. use GetIniSetting;
  30. use cksku;
  31. use Logmsg;
  32. use strict;
  33. no strict 'vars';
  34. # <Add any perl modules that you will be using for this script>
  35. # Require section
  36. require Exporter;
  37. # <Add any perl pl files that you will be using>
  38. # Global variable section
  39. # <Add any global variables here using my to preserve namespace>
  40. $selectedsku = undef;
  41. (@BuildArchs, @BuildTypes, @JoinDomain) = ();
  42. ($FirstBuildMachine, @ReleaseServers, $ReleaseServers, $ReleaseRemote, $BootTestMachines,
  43. $BuildNumber, $AutoRaise)=();
  44. ($BuildBranch, $BuildArchs, $BuildTypes)=(
  45. $ENV{_BuildBranch}, $ENV{_BuildArch}, $ENV{_BuildType}
  46. );
  47. # Assumption: BootTestDrive defined in Boot Test Machine remote.
  48. # Please reference BootTestDriveVarName in bootinit.cmd
  49. ($BootTestDriveVar, $PostBootTest, $UnAttend, $OpShellFolder) = (
  50. "BootTestDrive", "PostBootTest", "unattend.txt", "OpShellFolder.pl"
  51. );
  52. sub Main {
  53. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  54. # Begin Main code section
  55. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  56. # Return when you want to exit on error
  57. # <Implement your code here>
  58. my (%skus)=();
  59. my (@BootTestMachines, $BuildName, $sku, $PostBootTestFile ) = ();
  60. # BUGBUG - need to remove if we turn on outside main
  61. # if not defined MAIN_BUILD_LAB_MACHINE goto End
  62. return if (!exists $ENV{MAIN_BUILD_LAB_MACHINE});
  63. &initial;
  64. # for $BuildBranch, we can not change branch, because currently template limitation
  65. # for $lang. we can not change language, because currently template limitation
  66. # Initial GetIniSetting
  67. unless ( &GetIniSetting::CheckIniFile ) {
  68. errmsg( "Failed to find ini file ..." );
  69. return;
  70. }
  71. # for @BuildArchs, now is only execute one time, because template limitation
  72. for $BuildArch (@BuildArchs) {
  73. $ENV{_BuildArch} = $BuildArch;
  74. %skus = &cksku::GetSkus($lang, $BuildArch);
  75. # for @BuildTypes, now is only execute one time, because template limitation
  76. for $BuildType (@BuildTypes) {
  77. $ENV{_BuildType} = $BuildType;
  78. # Get Build Name
  79. $BuildName = &GetLatestBuildName;
  80. next if (!defined $BuildName);
  81. $BuildNumber = (split(/\./, $BuildName))[0];
  82. # Get build share
  83. $BuildShare = &GetBuildShare($BuildName);
  84. # Get Release Server
  85. @ReleaseServers = &GetReleaseServers;
  86. $ReleaseRemote = &GetReleaseRemote;
  87. # Get BuildMachine
  88. $FirstBuildMachine = &GetFirstBuildMachine($BuildBranch, $BuildArch, $BuildType);
  89. # Get Account
  90. @JoinDomain = split(/\s+/, &GetAccount);
  91. # Get AutoRaise
  92. $AutoRaise = &GetAutoRaise($BuildArch, $BuildType);
  93. for $sku (reverse(keys %skus)) {
  94. next if (defined ($selectedsku)
  95. && $sku ne $selectedsku);
  96. # Get Boot Test Machines
  97. @BootTestMachines = &GetBootTestMachine( $BuildArch, $BuildType, $sku );
  98. $BootTestMachines = join(" ", map({$_ . "1"} @BootTestMachines));
  99. for $BootTestMachine (@BootTestMachines) {
  100. # Show the boot test machine we working on
  101. logmsg("Start to install build on $BootTestMachine....");
  102. # Write PostBootTestScript
  103. $PostBootTestFile = "$ENV{temp}\\${PostBootTest}_${BootTestMachine}.cmd";
  104. &WritePostBootTestScript($PostBootTestFile, $BootTestMachines, $FirstBuildMachine, $BuildArch, $BuildType, $BuildName, @ReleaseServers );
  105. &StartBootTest($BuildArch, $BuildShare, $sku, $PostBootTestFile, $BootTestMachine);
  106. }
  107. }
  108. }
  109. }
  110. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  111. # End Main code section
  112. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  113. }
  114. # <Implement your subs here>
  115. sub initial {
  116. @BuildArchs = splitcolon( $BuildArchs ); # x86 or amd64 or ia64
  117. @BuildTypes = splitcolon( $BuildTypes ); # fre or chk
  118. system("$ENV{RAZZLETOOLPATH}\\setbuildstatus.cmd -s:boot");
  119. }
  120. sub StartBootTest {
  121. my ($BuildArch, $BuildShare, $sku, $PostBootTestFile, $BootTestMachine) = @_;
  122. my $BootCmd;
  123. # For some reason there is no environment variable for i386
  124. my $TargetArch = ($BuildArch eq "x86")?"i386":$BuildArch;
  125. my $UnattendFile = "$ENV{tmp}\\$UnAttend";
  126. my $OpShellFolderFile = "$ENV{RazzleToolPath}\\postbuildscripts\\$OpShellFolder";
  127. # Compose Boot Command
  128. $BootCmd = &ComposeBootCmd($TargetArch, $BuildShare, $sku);
  129. # Make the Unattend file
  130. &WriteUnattendFile($UnattendFile, $BootTestMachine, $BuildBranch);
  131. errmsg "Unable to create answer file." if (!-e $UnattendFile);
  132. # Issue Commands
  133. &IssueBootTestCommands($BuildArch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd);
  134. }
  135. #
  136. # ComposeBootCmd($TargetArch, $BuildShare, $sku)
  137. #
  138. # purpose: Generate the boot command. Such as "winnt32 ....", so we can call issue command
  139. #
  140. sub ComposeBootCmd {
  141. my ($TargetArch, $BuildShare, $sku) = @_;
  142. my $BinSource = "$BuildShare\\$sku\\$TargetArch";
  143. my $UnattendFile = "/Unattend:\%$BootTestDriveVar\%\\tools\\$UnAttend";
  144. my $CmdOpt;
  145. # if ($AutoRaise) {
  146. # $CmdOpt = "/cmd:\"\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe " .
  147. # "\%$BootTestDriveVar\%\\tools\\OpShellFolder.wsf " .
  148. # "/op:CopyFileTo /path:Startup /file:\%$BootTestDriveVar\%\\tools\\PostBootTest.cmd\"";
  149. # }
  150. # Set the boot command to issue
  151. # Have to remove winnt32 when testing on MP machines
  152. return "$BinSource\\winnt32.exe /#bvt:nosymbols /tempdrive:\%$BootTestDriveVar\% $UnattendFile $CmdOpt";
  153. }
  154. #
  155. # WriteUnattendFile($UnattendFile, $BootTestMachine, $Branch)
  156. #
  157. # purpose: Generate Unattend File
  158. #
  159. sub WriteUnattendFile {
  160. my($UnattendFile, $BootTestMachine, $Branch) = @_;
  161. my $Administrators = ($lang =~ /ger/i) ?
  162. "Administratoren" :
  163. "Administrators";
  164. my $password = "PASSWORD";
  165. open(F, ">$UnattendFile");
  166. print F <<UnattendFile;
  167. [data]
  168. Unattendedinstall=yes
  169. msdosinitiated="0"
  170. [Unattended]
  171. UnattendMode = fullUnattended
  172. OemSkipEula = yes
  173. TargetPath=test
  174. Filesystem=LeaveAlone
  175. NtUpgrade=no
  176. ConfirmHardware = No
  177. Repartition = No
  178. [branding]
  179. brandieusingunattended = yes
  180. [Proxy]
  181. Proxy_Enable = 1
  182. Use_Same_Proxy = 1
  183. HTTP_Proxy_Server = http://itgproxy:80
  184. Secure_Proxy_Server = http://itgproxy:80
  185. [GuiUnattended]
  186. AutoLogon =Yes
  187. AutoLogonCount = 1
  188. TimeZone=04
  189. AdminPassword=*
  190. oemskipregional =1
  191. oemskipwelcome = 1
  192. [UserData]
  193. FullName="$Branch"
  194. OrgName="Microsoft"
  195. ComputerName="${BootTestMachine}1"
  196. ProductID="\$\{P_roductID\}"
  197. [LicenseFilePrintData]
  198. AutoMode = "PerServer"
  199. AutoUsers = "50"
  200. [Display]
  201. BitsPerPel=0x10
  202. XResolution=0x400
  203. YResolution=0x300
  204. VRefresh=0x3C
  205. Flags=0x0
  206. AutoConfirm=0x1
  207. [RegionalSettings]
  208. LanguageGroup = 1, 7, 8, 9, 10, 11, 12, 13
  209. [Networking]
  210. InstallDefaultComponents=Yes
  211. [Identification]
  212. JoinDomain=$JoinDomain[0]
  213. DomainAdmin=\${BT_U}
  214. DomainAdminPassword=\${BT_P}
  215. CreateComputerAccountInDomain = Yes
  216. [SetupData]
  217. OsLoadOptionsVar="/fastdetect /debug /baudrate=115200"
  218. [GuiRunOnce]
  219. ;command0: Create the SAFE reboot shortcut
  220. command0="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\addlink.wsf -x:'\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\bootsafe.wsf' -i:13"
  221. UnattendFile
  222. print F <<O1631 if ($AutoRaise);
  223. ; command7: copy the postboottest.cmd to Administrator's Startup special folder
  224. command7="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\OpShellFolder.wsf /op:CopyFileTo /path:Startup /file:\%SYSTEMDRIVE\%\\TOOLS\\PostBootTest.cmd"
  225. ; one may store tools on other drive than \%SYSTEMDRIVE\%:
  226. ; command7="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \${${BootTestDriveVar}}\\TOOLS\\OpShellFolder.wsf /op:CopyFileTo /path:Startup /file:\${${BootTestDriveVar}}\\TOOLS\\PostBootTest.cmd"
  227. O1631
  228. print F <<BVT if $lang and $lang ne "usa";
  229. ;[GuiRunOnce]
  230. ; command1: Create the BVT shortcut
  231. command1="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\addlink.wsf -x:\%SYSTEMDRIVE\%\\TOOLS\\bvtm.cmd -l:'BVT Test.lnk'"
  232. ; command2: Add the winbld to ADMINISTRATORS
  233. command2="\%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\add2grp.wsf /u:'winbld' /d /g:$Administrators"
  234. ; command3: Clean the unattend* files
  235. ; command3="\%SYSTEMROOT\%\\SYSTEM32\\cmd.exe /c del /q \%SYSTEMDRIVE\%\\TOOLS\\unattend.*"
  236. ;
  237. ; command4: add the REGISTRY entries for automatic logon of the winbld
  238. ; command5: reboot the machine. use traditional way.
  239. ; command6: Do the cleanup and indirect cleanup.Not yet implemented.
  240. BVT
  241. close(F);
  242. }
  243. #
  244. # IssueBootTestCommands($buildarch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd)
  245. #
  246. # purpose: According the paramters and issue below commands to Boot Test machine
  247. # Phase 1: Format the Boot test drive
  248. # Phase 2: Prepare reference files (such as unattend.txt, opshellfolder.pl, postboottest.cmd)
  249. # Phase 3: Process Boot file (boot.ini or boot.nvr or nvram.sav)
  250. # Phase 4: Run winnt32
  251. #
  252. sub IssueBootTestCommands {
  253. # ------------ Data definition
  254. my ($buildarch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd) = @_;
  255. my $cmd;
  256. # Set the tools copy command
  257. my $SourceToolDir="\\\\$ENV{ComputerName}\\$ENV{RazzleToolPath}\\$buildarch";
  258. my $SourcePerlDir="\\\\$ENV{ComputerName}\\$ENV{RazzleToolPath}\\perl";
  259. my $SourcesScrDir="\\\\$ENV{ComputerName}\\$ENV{RazzleToolPath}\\POSTBUILDSCRIPTS";
  260. my $TargetToolDir="\^\%$BootTestDriveVar\^\%\\tools";
  261. # Construct the UNC
  262. $UnattendFile = "\\\\$ENV{ComputerName}\\$UnattendFile";
  263. $PostBootTestFile = "\\\\$ENV{ComputerName}\\$PostBootTestFile";
  264. $OpShellFolderFile = "\\\\$ENV{ComputerName}\\$OpShellFolderFile";
  265. # replace <drv>: with <drv>$
  266. $UnattendFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  267. $SourceToolDir =~ s/\\(\w)\:\\/\\$1\$\\/;
  268. $SourcePerlDir =~ s/\\(\w)\:\\/\\$1\$\\/;
  269. $SourcesScrDir =~ s/\\(\w)\:\\/\\$1\$\\/;
  270. $PostBootTestFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  271. $OpShellFolderFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  272. # Phase 1: Format the Boot test drive (details see below the 'code' part)
  273. #
  274. # Phase 2: Prepare reference files (such as unattend.txt, opshellfolder.pl, postboottest.cmd)
  275. my @Phase2 = &FormStrToArray( <<Phase2);
  276. if not exist $TargetToolDir md $TargetToolDir
  277. start /w /min cmd /c copy /y $PostBootTestFile $TargetToolDir\\${PostBootTest}.cmd.temp
  278. start /w /min cmd /c copy /y $UnattendFile $TargetToolDir\\${UnAttend}.temp
  279. start /min cmd /c copy /y $OpShellFolderFile $TargetToolDir\\$OpShellFolder
  280. start /min cmd /c copy /y $SourceToolDir\\remote.exe $TargetToolDir
  281. start /min cmd /c copy /y $SourceToolDir\\autologon.exe $TargetToolDir
  282. start /min cmd /c copy /y $SourceToolDir\\sleep.exe $TargetToolDir
  283. start /min cmd /c copy /y $SourcesScrDir\\addlink.wsf $TargetToolDir
  284. start /min cmd /c copy /y $SourcesScrDir\\add2grp.wsf $TargetToolDir
  285. start /min cmd /c copy /y $SourcesScrDir\\fixlogon.wsf $TargetToolDir
  286. start /min cmd /c copy /y $SourcesScrDir\\bootsafe.wsf $TargetToolDir
  287. start /min cmd /c copy /y $SourcesScrDir\\parsesys.wsf $TargetToolDir
  288. start /min cmd /c copy /y $SourcesScrDir\\opshellfolder.wsf $TargetToolDir
  289. start /min cmd /c copy /y $SourcesScrDir\\bvtm.cmd $TargetToolDir\\bvtm.cmd.temp
  290. start /min cmd /c xcopy /fdice $SourcePerlDir $TargetToolDir\\perl
  291. \^\^\%windir\^\^\%\\SYSTEM32\\cscript.exe $TargetToolDir\\parsesys.wsf /path:$TargetToolDir /in:"${PostBootTest}.cmd.temp" /out:"${PostBootTest}.cmd"
  292. \^\^\%windir\^\^\%\\SYSTEM32\\cscript.exe $TargetToolDir\\parsesys.wsf /path:$TargetToolDir /in:"${UnAttend}.temp" /out:"$UnAttend"
  293. \^\^\%windir\^\^\%\\SYSTEM32\\cscript.exe $TargetToolDir\\parsesys.wsf /path:$TargetToolDir /in:"bvtm.cmd.temp" /out:"bvtm.cmd"
  294. Phase2
  295. # Phase 3: Process Boot file (boot.ini or boot.nvr)
  296. my @Phase3;
  297. my $BootFile;
  298. $BootFile="boot.ini" if (lc$buildarch eq "x86");
  299. $BootFile="boot.ini" if (lc$buildarch eq "amd64");
  300. $BootFile="boot.nvr" if (lc$buildarch eq "ia64");
  301. # Phase 3a: Save off the boot file for intel machines
  302. @Phase3 = &FormStrToArray( <<Phase3a);
  303. if exist c:\\${BootFile} attrib -s -r -h c:\\${BootFile}
  304. if exist c:\\${BootFile}.sav attrib -s -r -h c:\\${BootFile}.sav
  305. if exist c:\\${BootFile}.sav copy /y c:\\${BootFile}.sav c:\\${BootFile}
  306. if /i "$BootFile" equ "Boot.ini" if exist c:\\${BootFile} attrib +s +r +h c:\\${BootFile}
  307. if exist c:\\${BootFile}.sav attrib +s +r +h c:\\${BootFile}.sav
  308. Phase3a
  309. # Phase 4: Run winnt32
  310. @Phase4 = &FormStrToArray( <<Phase4);
  311. start /min $BootCmd
  312. Phase4
  313. # ------------ Code
  314. # Prepare the Phase 1's answer file
  315. open(F, ">$ENV{tmp}\\format_${lang}.txt");
  316. print F "Format \%$BootTestDriveVar\% /X /FS:NTFS /Q\n";
  317. print F "Y\n\n\n";
  318. close(F);
  319. # Phase 1: Format the Boot test drive
  320. &MyRemoteCommand($BootTestMachine, "BootTestRemote", "Echo Beginning boot test");
  321. &MyRemoteCommand($BootTestMachine, "BootTestRemote", "$ENV{tmp}\\format_${lang}.txt", 1);
  322. sleep 45;
  323. # Phase 2, Phase 3:
  324. for $cmd ( @Phase2, @Phase3) {
  325. &MyRemoteCommand($BootTestMachine, "BootTestRemote", $cmd);
  326. }
  327. # Phase 4: start setup
  328. for $cmd ( @Phase4) {
  329. &MyRemoteCommand($BootTestMachine, "BootTestRemote", $cmd);
  330. }
  331. }
  332. #
  333. # FormStrToArray(@strs)
  334. # Parameters:
  335. # @strs: multi-line string " This is a text.\n This is another line\n\t\tAnd, have tabs"
  336. #
  337. # purpose: Seperate the multi-line string into an array and format it
  338. #
  339. sub FormStrToArray {
  340. my (@strs)=@_;
  341. my (@result, $str, $line);
  342. for $str (@strs) {
  343. for $line (split(/\n/, $str)) {
  344. chomp $str;
  345. $line=~s/^\s+$//;
  346. $line=~s/\t/ /g;
  347. push @result, $line;
  348. }
  349. }
  350. return @result;
  351. }
  352. #
  353. # WritePostBootTestScript($postboottestfile, $boottestlist, $myprimary, $buildarch, $buildtype, $buildname, @ReleaseServers)
  354. # Parameters:
  355. # $postboottestfile: such as "postboottest.cmd"
  356. # $boottestlist: such as "i32bt0011 i32bt0021"
  357. # $myprimary: such as "i32fre"
  358. # $buildarch: such as "x86"
  359. # $buildtype: such as "fre"
  360. # $buildname: such as "3552.x86fre.main.010914-1644"
  361. # @ReleaseServers: such as ("intblds10", "intblds11" )
  362. #
  363. # purpose: According the parameters, generate postboottestfile
  364. #
  365. sub WritePostBootTestScript {
  366. # Write a script on the fly to use on the boot test machine. The reason
  367. # This needs to be done on the fly is so that we can use sources and
  368. # and environment variables only available on the build machines.
  369. my ($PostBootTestFile, $BootTestList, $MyPrimary, $buildarch, $buildtype, $buildname, @ReleaseServers ) = @_;
  370. my $langopt = ((defined $lang)&&(lc$lang ne "usa"))?"-l:$lang":"";
  371. my $ReleaseServers = join(" ", @ReleaseServers);
  372. `del /f $PostBootTestFile` if (-e $PostBootTestFile);
  373. open(F, ">$PostBootTestFile");
  374. print F <<PostBootTestFile;
  375. \@echo off
  376. if DEFINED _echo echo on
  377. if DEFINED verbose echo on
  378. REM This script will kick off stress after a boot test is complete.
  379. REM In addition, it will make a marker file indicating that boot tests have passed
  380. REM for the main build lab only so that we can raise to BVT automatically.
  381. REM Note that we will have to delete the marker files in postbuild before making them here.
  382. REM We need release to also have a list of files to match against based on boottestmachines.txt
  383. REM Provide usage.
  384. for \%\%a in (./ .- .) do if \".\%1.\" == \"\%\%a?.\" goto Usage
  385. REM Write the done file to be used by release
  386. set $BootTestDriveVar=\$\{$BootTestDriveVar\}
  387. set ${BootTestDriveVar}Share=\%$BootTestDriveVar:~0,1\%\$
  388. set LOGFILE=\%$BootTestDriveVar\%\\tools\\BootTest.log
  389. set BUILDNAME=$buildname
  390. REM Don't create a "booted" remote any longer! It's a security hole!
  391. REM call :LogMe "Create a remote for raiseall.pl"
  392. REM start \%BootTestDrive\%\\tools\\remote /S \"cmd.exe\" Booted
  393. :Connect
  394. call :LogMe "Connecting to release servers"
  395. for \%\%a in ($ReleaseServers) do (
  396. call :LogMe "Connecting to \%\%a"
  397. net use \\\\\%\%a /u:\${BT_U} \${BT_P}
  398. if errorlevel 1 (
  399. call :LogMe "Error - \%\%a cannot connect"
  400. )
  401. )
  402. :Raise
  403. call :LogMe "Raiseall to BVT on all release servers"
  404. for \%\%a in ($ReleaseServers) do (
  405. call :LogMe "Start Raiseall on \%\%a ..."
  406. echo start cmd /c perl ^^^\%\%RazzleToolPath^^^\%\%\\postbuildscripts\\raiseall.pl -n:$BuildNumber -q:bvt -a:$buildarch -t:$buildtype $langopt | \%$BootTestDriveVar\%\\tools\\remote /c \%\%a $ReleaseRemote /L 1>nul
  407. if errorlevel 1 (
  408. call :LogMe "Remote to \%\%a failed"
  409. )
  410. )
  411. call :LogMe "Give raiseall 5 mins to raise build to BVT"
  412. \%BootTestDrive\%\\tools\\sleep 300
  413. :Check
  414. call :LogMe "Check if build raised to BVT"
  415. set BVTCheck=
  416. for \%\%a in ($ReleaseServers) do (
  417. call :LogMe "Checking for BVT on \%\%a"
  418. dir \\\\\%\%a\\\%BUILDNAME\%.${lang}\\build_logs\\bvt.qly >nul 2>nul
  419. if errorlevel 1 (
  420. call :LogMe "No bvt.qly available on \%\%a"
  421. ) else (
  422. set BVTCheck=1
  423. )
  424. )
  425. :Disconnect
  426. call :LogMe "Disconnecting from release servers"
  427. \%BootTestDrive\%\\tools\\sleep 3
  428. for \%\%a in ($ReleaseServers) do (
  429. net use \\\\\%\%a /d
  430. if errorlevel 1 call :LogMe "Error - \%\%a cannot disconnect"
  431. )
  432. if not defined BVTCheck (
  433. call :LogMe "No release server at BVT yet, waiting 15 min to try again"
  434. \%BootTestDrive\%\\tools\\sleep 900
  435. goto :Connect
  436. )
  437. call :LogMe "Move PostBootTest.cmd to desktop"
  438. \%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\opshellfolder.wsf /op:copyfileto /path:Desktop /file:\%SYSTEMDRIVE\%\\TOOLS\\postboottest.cmd
  439. \%SYSTEMROOT\%\\SYSTEM32\\cscript.exe \%SYSTEMDRIVE\%\\TOOLS\\opshellfolder.wsf /op:delfile /path:startup /file:postboottest.cmd
  440. call :LogMe "PostBootTest.cmd finished."
  441. goto :exit
  442. :logme
  443. echo \%1
  444. echo \%DATE\% \%TIME\% \%1>>\%LOGFILE\%
  445. goto :EOF
  446. :exit
  447. endlocal
  448. PostBootTestFile
  449. close(F);
  450. logmsg "Failed to create postboottest.cmd" if (!-e $PostBootTestFile);
  451. return;
  452. }
  453. #################################### Reusable functions
  454. #
  455. # GetFirstBuildMachine($branch, $arch, $type)
  456. #
  457. # purpose: Get first primary build machine or first secondary build machine
  458. # if not defined primary from buildmachines.txt
  459. #
  460. sub GetFirstBuildMachine {
  461. # ($order, $branch, $arch, $type) = ("primary", @_);
  462. my $searchpattern = join(",", @_);
  463. my @BuildMachines;
  464. my ($machinename, $firstbuildmachine, $line);
  465. open(F, "$ENV{RazzleToolPath}\\BuildMachines.txt");
  466. @BuildMachines = <F>;
  467. close(F);
  468. for $line (@BuildMachines) {
  469. $machinename = (split(/\,/, $line))[0];
  470. if ($line =~ /$searchpattern/i) {
  471. return $machinename if ($line =~ /primary/i);
  472. $firstbuildmachine=$machinename if (!defined $firstbuildmachine);
  473. }
  474. }
  475. errmsg "Failed to find a build machine." if(!defined $firstbuildmachine);
  476. return $firstbuildmachine;
  477. }
  478. #
  479. # GetFirstBuildMachine($branch, $arch, $type)
  480. #
  481. # purpose: Get first primary build machine or first secondary build machine
  482. # if not defined primary from buildmachines.txt
  483. #
  484. sub GetAccount {
  485. my (@Request) = ("JoinDomain");
  486. my( $JoinDomain ) = &GetIniSetting::GetSetting( @Request );
  487. return $JoinDomain;
  488. }
  489. #
  490. # GetBuildPath($buildname, [$compname], [$releaseshare])
  491. #
  492. # purpose: Get the fullpath share, so we can write file correctly. such as \\i32fre\release\jpn\1234 => \\i32fre\f$\release\jpn\1234
  493. #
  494. sub GetBuildPath {
  495. my ($releaseshare) = @_;
  496. my ($computername, $sharename, $misc, $sharepath);
  497. # Get the computername, sharename, and remain paths
  498. if ($releaseshare =~ /^\\\\([^\\]+)\\([^\\]+)/) {
  499. ($computername, $sharename, $misc) = ($1, $2, $');
  500. } elsif ($releaseshare =~ /^([^\\]+)/) {
  501. ($computername, $sharename, $misc) = ($ENV{computername}, $1, $');
  502. } else {
  503. errmsg("Can not get correct build path ($releaseshare)");
  504. return;
  505. }
  506. # Replace d: to d$ if applicable
  507. $sharename =~ s/\:/\$/;
  508. for my $line (`rmtshare \\\\$computername\\$sharename`) {
  509. $sharepath=$1 if ($line =~ /^Path\s+(.+)$/);
  510. }
  511. if (!defined $sharepath) {
  512. errmsg("Can not find the path of this share ($sharename)");
  513. return;
  514. }
  515. # Remove d:\ to d: if applicable
  516. $sharepath =~ s/\\$//;
  517. # Replace d: to d$ if applicable
  518. $sharepath =~ s/\:/\$/;
  519. return "\\\\$computername\\$sharepath\\$misc";
  520. }
  521. #
  522. # GetBuildShare($buildname, [$compname], [$releaseshare])
  523. #
  524. # purpose: Get build share from computer ($compname). Default is $ENV{computername
  525. #
  526. sub GetBuildShare {
  527. my ($buildname, $compname, $releaseshare) = @_;
  528. # This setting is misnamed as it is actually used as both the directory
  529. # and share name
  530. my (@Request) = ("AlternateReleaseDir");
  531. my ($inirelease) = &GetIniSetting::GetSetting( @Request );
  532. $compname = $ENV{computername} if (!defined $compname);
  533. $releaseshare = $inirelease || 'release' if (!defined $releaseshare);
  534. my $BuildShare = (lc$lang eq "usa")?"\\\\$compname\\$releaseshare\\$buildname":
  535. "\\\\$compname\\$releaseshare\\$lang\\$buildname";
  536. logmsg "No latest build to test - aborting." if (!defined $BuildShare);
  537. logmsg "No latest build could find - aborting." if (!-e $BuildShare);
  538. return $BuildShare;
  539. }
  540. #
  541. # GetReleaseServers
  542. #
  543. # purpose: Get release server from ini file
  544. #
  545. sub GetReleaseServers {
  546. my (@Request) = ("ReleaseServers", $ENV{_BuildArch} . $ENV{_BuildType});
  547. my ($ReleaseServer) = &GetIniSetting::GetSetting( @Request );
  548. my @ReleaseServers;
  549. @Request = ("PrimaryReleaseServer");
  550. @ReleaseServers = &GetIniSetting::GetSetting( @Request );
  551. # Collect Release Servers to @ReleaseServers
  552. # Avoid to include primary release server twice
  553. #
  554. # hardcode exclude ntburnlab08
  555. push(@ReleaseServers,
  556. grep {!(
  557. # USA case
  558. ((lc$lang eq "usa") && (/ntburnlab08|intblds10/i)) ||
  559. # Primary release server
  560. ((defined $ReleaseServers[0]) && (/\Q$ReleaseServers[0]\E/i)))
  561. } split(/\s+/, $ReleaseServer)
  562. );
  563. wrnmsg "Could not find release servers to raise." if (!@ReleaseServers);
  564. return @ReleaseServers;
  565. }
  566. sub GetReleaseRemote {
  567. my (@Request) = ("AlternateReleaseRemote");
  568. my( $ReleaseRemote ) = &GetIniSetting::GetSetting( @Request );
  569. $ReleaseRemote = "release" if (!defined $ReleaseRemote);
  570. return $ReleaseRemote;
  571. }
  572. #
  573. # GetBootTestMachine($arch, $type, $sku)
  574. #
  575. # purpose: Get Boot Test Machine from ini file
  576. #
  577. sub GetBootTestMachine {
  578. my ($arch, $type, $sku) = @_;
  579. my (@Request) = ( "BootTestMachines", uc$arch . uc$type, $sku);
  580. return split(/\s+/, &GetIniSetting::GetSetting( @Request ));
  581. }
  582. #
  583. # GetLatestBuildName
  584. #
  585. # purpose: call getlatestrelease.cmd and handle its error
  586. #
  587. sub GetLatestBuildName {
  588. my $buildname = `$ENV{RazzleToolPath}\\PostBuildScripts\\GetLatestRelease.cmd -l:$lang`;
  589. chomp $buildname;
  590. if ($buildname =~ /none/i) {
  591. errmsg "No Binaries tree or latest release found - Aborting.";
  592. return;
  593. }
  594. return $buildname;
  595. }
  596. #
  597. # GetAutoRaise
  598. #
  599. # purpose: check the .ini file to see if we should try to auto raise or not
  600. #
  601. sub GetAutoRaise {
  602. my ($arch, $type) = @_;
  603. my (@Request) = ( "AutoRaise", uc$arch . uc$type);
  604. return (&GetIniSetting::GetSetting( @Request ) =~ /true/i);
  605. }
  606. #
  607. # MyRemoteCommand($Machine, $RemoteId, $cmd)
  608. #
  609. # purpose: Execute $cmd on remote console
  610. #
  611. sub MyRemoteCommand {
  612. my ($Machine, $RemoteId, $cmd, $echotype) = @_;
  613. $echotype = ($echotype eq "1")?"type":"echo";
  614. $cmd = ($cmd=~/\S/)?"$echotype $cmd" : "${echotype}.";
  615. # Make sure this gets logged properly
  616. logmsg("Remote Command: '$cmd'");
  617. # Wait 1 more second each time before each time we execute remote command
  618. sleep 1;
  619. return &MySystemCall("$cmd|remote /c $Machine $RemoteId >nul");
  620. }
  621. #
  622. # MySystemCall($cmd)
  623. #
  624. # purpose: Execute $cmd thru system call
  625. #
  626. sub MySystemCall {
  627. my ($cmd) = @_;
  628. my $r = system($cmd);
  629. $r >>= 8;
  630. # Because remote command always return 4, we should ignore it.
  631. if (($r)&&($r ne 4)&&($r ne 0)) {
  632. errmsg "Failed ($r): $cmd";
  633. return 0;
  634. }
  635. return 1;
  636. }
  637. #
  638. # splitcolon($str)
  639. #
  640. # purpose: split $str with delimiter ':' and return splited string
  641. #
  642. sub splitcolon {
  643. return grep {/\w+/} split(/\:/, $_[0]);
  644. }
  645. ##################################
  646. sub ValidateParams {
  647. #<Add your code for validating the parameters here>
  648. }
  649. # <Add your usage here>
  650. sub Usage {
  651. print <<USAGE;
  652. Purpose of program
  653. Usage: $0 [-l lang] [-y [pro\|ads\|ser\|dtd]]
  654. -l Language
  655. -y sku select
  656. -? Displays usage
  657. As of 02/13/01, the sku choice of [srv, pro] is available
  658. for GER x86, and JPN x86 only.
  659. Example:
  660. $0 -l jpn
  661. $0 -l:ger -y:pro
  662. USAGE
  663. }
  664. sub GetParams {
  665. # Step 1: Call pm getparams with specified arguments
  666. &GetParams::getparams(@_);
  667. # Step 2: Set the language into the enviroment
  668. $ENV{lang}=$lang;
  669. # Step 3: Call the usage if specified by /?
  670. if ($HELP) {
  671. &Usage();
  672. exit 1;
  673. }
  674. }
  675. # Cmd entry point for script.
  676. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  677. # Step 1: Parse the command line
  678. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  679. &GetParams ('-o', 'l:y:', '-p', 'lang selectedsku', @ARGV);
  680. # Include local environment extensions
  681. &LocalEnvEx::localenvex('initialize');
  682. # Set lang from the environment
  683. $lang=$ENV{lang};
  684. # Validate the option given as parameter.
  685. &ValidateParams;
  686. # Step 4: Call the main function
  687. &autoboottest::Main();
  688. # End local environment extensions.
  689. &LocalEnvEx::localenvex('end');
  690. }
  691. # -------------------------------------------------------------------------------------------
  692. # Script: autoboottest.pl
  693. # Purpose: Template perl perl script for the NT postbuild environment
  694. # SD Location: %sdxroot%\tools\postbuildscripts
  695. #
  696. # (1) Code section description:
  697. # CmdMain - Developer code section. This is where your work gets done.
  698. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  699. #
  700. # (2) Reserved Variables -
  701. # $ENV{HELP} - Flag that specifies usage.
  702. # $ENV{lang} - The specified language. Defaults to USA.
  703. # $ENV{logfile} - The path and filename of the logs file.
  704. # $ENV{logfile_bak} - The path and filename of the logfile.
  705. # $ENV{errfile} - The path and filename of the error file.
  706. # $ENV{tmpfile} - The path and filename of the temp file.
  707. # $ENV{errors} - The scripts errorlevel.
  708. # $ENV{script_name} - The script name.
  709. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  710. # postbuild operates on.
  711. # $ENV{_NTPostBld_Bak} - Reserved support var.
  712. # $ENV{_temp_bak} - Reserved support var.
  713. #
  714. # (3) Reserved Subs -
  715. # Usage - Use this sub to discribe the scripts usage.
  716. # ValidateParams - Use this sub to verify the parameters passed to the script.
  717. #
  718. # (4) Call other executables or command scripts by using:
  719. # system "foo.exe";
  720. # Note that the executable/script you're calling with system must return a
  721. # non-zero value on errors to make the error checking mechanism work.
  722. #
  723. # Example
  724. # if (system("perl.exe foo.pl -l $lang")){
  725. # errmsg("perl.exe foo.pl -l $lang failed.");
  726. # # If you need to terminate function's execution on this error
  727. # goto End;
  728. # }
  729. #
  730. # (5) Log non-error information by using:
  731. # logmsg "<log message>";
  732. # and log error information by using:
  733. # errmsg "<error message>";
  734. #
  735. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  736. # by a member of the international build team (ntbintl).
  737. #
  738. # -------------------------------------------------------------------------------------------
  739. =head1 NAME
  740. B<mypackage> - What this package for
  741. =head1 SYNOPSIS
  742. <An code example how to use>
  743. =head1 DESCRIPTION
  744. <Use above example to describe this package>
  745. =head1 INSTANCES
  746. =head2 <myinstances>
  747. <Description of myinstances>
  748. =head1 METHODS
  749. =head2 <mymathods>
  750. <Description of mymathods>
  751. =head1 SEE ALSO
  752. <Some related package or None>
  753. =head1 AUTHOR
  754. <Your Name <your e-mail address>>
  755. =cut
  756. 1;