Source code of Windows XP (NT5)
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.

894 lines
24 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, @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. }
  119. sub StartBootTest {
  120. my ($BuildArch, $BuildShare, $sku, $PostBootTestFile, $BootTestMachine) = @_;
  121. my $BootCmd;
  122. # For some reason there is no environment variable for i386
  123. my $TargetArch = ($BuildArch eq "x86")?"i386":$BuildArch;
  124. my $UnattendFile = "$ENV{tmp}\\$UnAttend";
  125. my $OpShellFolderFile = "$ENV{RazzleToolPath}\\postbuildscripts\\$OpShellFolder";
  126. # Compose Boot Command
  127. $BootCmd = &ComposeBootCmd($TargetArch, $BuildShare, $sku);
  128. # Make the Unattend file
  129. &WriteUnattendFile($UnattendFile, $BootTestMachine, $BuildBranch);
  130. errmsg "Unable to create answer file." if (!-e $UnattendFile);
  131. # Issue Commands
  132. &IssueBootTestCommands($BuildArch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd);
  133. }
  134. #
  135. # ComposeBootCmd($TargetArch, $BuildShare, $sku)
  136. #
  137. # purpose: Generate the boot command. Such as "winnt32 ....", so we can call issue command
  138. #
  139. sub ComposeBootCmd {
  140. my ($TargetArch, $BuildShare, $sku) = @_;
  141. my $BinSource = "$BuildShare\\$sku\\$TargetArch";
  142. my $UnattendFile = "/Unattend:\%$BootTestDriveVar\%\\tools\\$UnAttend";
  143. my $CmdOpt;
  144. if ($AutoRaise) {
  145. $CmdOpt = "/cmd:\"\%$BootTestDriveVar\%\\tools\\perl\\bin\\perl.exe " .
  146. "\%$BootTestDriveVar\%\\tools\\OpShellFolder.pl " .
  147. "CopyFileTo Startup \%$BootTestDriveVar\%\\tools\\PostBootTest.cmd\"";
  148. }
  149. # Set the boot command to issue
  150. # Have to remove winnt32 when testing on MP machines
  151. return "$BinSource\\winnt32.exe /#bvt:nosymbols /tempdrive:\%$BootTestDriveVar\% $UnattendFile $CmdOpt";
  152. }
  153. #
  154. # WriteUnattendFile($UnattendFile, $BootTestMachine, $Branch)
  155. #
  156. # purpose: Generate Unattend File
  157. #
  158. sub WriteUnattendFile {
  159. my($UnattendFile, $BootTestMachine, $Branch) = @_;
  160. open(F, ">$UnattendFile");
  161. print F <<UnattendFile;
  162. [data]
  163. Unattendedinstall=yes
  164. msdosinitiated="0"
  165. [Unattended]
  166. UnattendMode = fullUnattended
  167. OemSkipEula = yes
  168. TargetPath=test
  169. Filesystem=LeaveAlone
  170. NtUpgrade=no
  171. ConfirmHardware = No
  172. Repartition = No
  173. [branding]
  174. brandieusingunattended = yes
  175. [Proxy]
  176. Proxy_Enable = 1
  177. Use_Same_Proxy = 1
  178. HTTP_Proxy_Server = http://itgproxy:80
  179. Secure_Proxy_Server = http://itgproxy:80
  180. [GuiUnattended]
  181. AutoLogon =Yes
  182. AutoLogonCount = 1
  183. TimeZone=04
  184. AdminPassword=*
  185. oemskipregional =1
  186. oemskipwelcome = 1
  187. [UserData]
  188. FullName="$Branch"
  189. OrgName="Microsoft"
  190. ComputerName="${BootTestMachine}1"
  191. ProductID="\$\{P_roductID\}"
  192. [LicenseFilePrintData]
  193. AutoMode = "PerServer"
  194. AutoUsers = "50"
  195. [Display]
  196. BitsPerPel=0x10
  197. XResolution=0x400
  198. YResolution=0x300
  199. VRefresh=0x3C
  200. Flags=0x0
  201. AutoConfirm=0x1
  202. [RegionalSettings]
  203. LanguageGroup = 1, 7, 8, 9, 10, 11, 12, 13
  204. [Networking]
  205. InstallDefaultComponents=Yes
  206. [Identification]
  207. JoinDomain=$JoinDomain[0]
  208. DomainAdmin=\${BT_U}
  209. DomainAdminPassword=\${BT_P}
  210. [SetupData]
  211. OsLoadOptionsVar="/fastdetect /debug /baudrate=115200"
  212. UnattendFile
  213. close(F);
  214. }
  215. #
  216. # IssueBootTestCommands($buildarch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd)
  217. #
  218. # purpose: According the paramters and issue below commands to Boot Test machine
  219. # Phase 1: Format the Boot test drive
  220. # Phase 2: Prepare reference files (such as unattend.txt, opshellfolder.pl, postboottest.cmd)
  221. # Phase 3: Process Boot file (boot.ini or boot.nvr or nvram.sav)
  222. # Phase 4: Run winnt32
  223. #
  224. sub IssueBootTestCommands {
  225. # ------------ Data definition
  226. my ($buildarch, $BootTestMachine, $UnattendFile, $PostBootTestFile, $OpShellFolderFile, $BootCmd) = @_;
  227. my $cmd;
  228. # Set the tools copy command
  229. my $SourceToolDir="\\\\$ENV{ComputerName}\\$ENV{RazzleToolPath}\\$buildarch";
  230. my $TargetToolDir="\^\%$BootTestDriveVar\^\%\\tools";
  231. # Construct the UNC
  232. $UnattendFile = "\\\\$ENV{ComputerName}\\$UnattendFile";
  233. $PostBootTestFile = "\\\\$ENV{ComputerName}\\$PostBootTestFile";
  234. $OpShellFolderFile = "\\\\$ENV{ComputerName}\\$OpShellFolderFile";
  235. # replace <drv>: with <drv>$
  236. $UnattendFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  237. $SourceToolDir =~ s/\\(\w)\:\\/\\$1\$\\/;
  238. $PostBootTestFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  239. $OpShellFolderFile =~ s/\\(\w)\:\\/\\$1\$\\/;
  240. # Phase 1: Format the Boot test drive (details see below the 'code' part)
  241. #
  242. # Phase 2: Prepare reference files (such as unattend.txt, opshellfolder.pl, postboottest.cmd)
  243. my @Phase2 = &FormStrToArray( <<Phase2);
  244. if not exist $TargetToolDir md $TargetToolDir
  245. start /w /min cmd /c copy /y $PostBootTestFile $TargetToolDir\\${PostBootTest}.cmd.temp
  246. start /w /min cmd /c copy /y $UnattendFile $TargetToolDir\\${UnAttend}.temp
  247. start /min cmd /c xcopy /fdice $SourceToolDir $TargetToolDir
  248. start /min cmd /c copy /y $OpShellFolderFile $TargetToolDir\\$OpShellFolder
  249. \^\^\%systemdrive\^\^\%\\simple_perl\\perl \^\^\%systemdrive\^\^\%\\simple_perl\\ParseSys.pl $TargetToolDir\\${PostBootTest}.cmd.temp $TargetToolDir\\${PostBootTest}.cmd
  250. \^\^\%systemdrive\^\^\%\\simple_perl\\perl \^\^\%systemdrive\^\^\%\\simple_perl\\ParseSys.pl $TargetToolDir\\${UnAttend}.temp $TargetToolDir\\$UnAttend
  251. Phase2
  252. # Phase 3: Process Boot file (boot.ini or boot.nvr)
  253. my @Phase3;
  254. my $BootFile;
  255. $BootFile="boot.ini" if (lc$buildarch eq "x86");
  256. $BootFile="boot.ini" if (lc$buildarch eq "amd64");
  257. $BootFile="boot.nvr" if (lc$buildarch eq "ia64");
  258. # Phase 3a: Save off the boot file for intel machines
  259. @Phase3 = &FormStrToArray( <<Phase3a);
  260. if exist c:\\${BootFile} attrib -s -r -h c:\\${BootFile}
  261. if exist c:\\${BootFile}.sav attrib -s -r -h c:\\${BootFile}.sav
  262. if exist c:\\${BootFile}.sav copy /y c:\\${BootFile}.sav c:\\${BootFile}
  263. if /i "$BootFile" equ "Boot.ini" if exist c:\\${BootFile} attrib +s +r +h c:\\${BootFile}
  264. if exist c:\\${BootFile}.sav attrib +s +r +h c:\\${BootFile}.sav
  265. Phase3a
  266. # Phase 4: Run winnt32
  267. @Phase4 = &FormStrToArray( <<Phase4);
  268. start /min $BootCmd
  269. Phase4
  270. # ------------ Code
  271. # Prepare the Phase 1's answer file
  272. open(F, ">$ENV{tmp}\\format_${lang}.txt");
  273. print F "Format \%$BootTestDriveVar\% /X /FS:NTFS /Q\n";
  274. print F "Y\n\n\n";
  275. close(F);
  276. # Phase 1: Format the Boot test drive
  277. &MyRemoteCommand($BootTestMachine, "BootTestRemote", "Echo Beginning boot test");
  278. &MyRemoteCommand($BootTestMachine, "BootTestRemote", "$ENV{tmp}\\format_${lang}.txt", 1);
  279. sleep 45;
  280. # Phase 2, Phase 3:
  281. for $cmd ( @Phase2, @Phase3) {
  282. &MyRemoteCommand($BootTestMachine, "BootTestRemote", $cmd);
  283. }
  284. # Phase 4: start setup
  285. for $cmd ( @Phase4) {
  286. &MyRemoteCommand($BootTestMachine, "BootTestRemote", $cmd);
  287. }
  288. }
  289. #
  290. # FormStrToArray(@strs)
  291. # Parameters:
  292. # @strs: multi-line string " This is a text.\n This is another line\n\t\tAnd, have tabs"
  293. #
  294. # purpose: Seperate the multi-line string into an array and format it
  295. #
  296. sub FormStrToArray {
  297. my (@strs)=@_;
  298. my (@result, $str, $line);
  299. for $str (@strs) {
  300. for $line (split(/\n/, $str)) {
  301. chomp $str;
  302. $line=~s/^\s+$//;
  303. $line=~s/\t/ /g;
  304. push @result, $line;
  305. }
  306. }
  307. return @result;
  308. }
  309. #
  310. # WritePostBootTestScript($postboottestfile, $boottestlist, $myprimary, $buildarch, $buildtype, @ReleaseServers)
  311. # Parameters:
  312. # $postboottestfile: such as "postboottest.cmd"
  313. # $boottestlist: such as "i32bt0011 i32bt0021"
  314. # $myprimary: such as "i32fre"
  315. # $buildarch: such as "x86"
  316. # $buildtype: such as "fre"
  317. # @ReleaseServers: such as ("intblds10", "intblds11" )
  318. #
  319. # purpose: According the parameters, generate postboottestfile
  320. #
  321. sub WritePostBootTestScript {
  322. # Write a script on the fly to use on the boot test machine. The reason
  323. # This needs to be done on the fly is so that we can use sources and
  324. # and environment variables only available on the build machines.
  325. my ($PostBootTestFile, $BootTestList, $MyPrimary, $buildarch, $buildtype, @ReleaseServers ) = @_;
  326. my $langopt = ((defined $lang)&&(lc$lang ne "usa"))?"-l:$lang":"";
  327. my $ReleaseServers = join(" ", @ReleaseServers);
  328. `del /f $PostBootTestFile` if (-e $PostBootTestFile);
  329. open(F, ">$PostBootTestFile");
  330. print F <<PostBootTestFile;
  331. \@echo off
  332. if DEFINED _echo echo on
  333. if DEFINED verbose echo on
  334. REM This script will kick off stress after a boot test is complete.
  335. REM In addition, it will make a marker file indicating that boot tests have passed
  336. REM for the main build lab only so that we can raise to BVT automatically.
  337. REM Note that we will have to delete the marker files in postbuild before making them here.
  338. REM We need release to also have a list of files to match against based on boottestmachines.txt
  339. REM Provide usage.
  340. for \%\%a in (./ .- .) do if \".\%1.\" == \"\%\%a?.\" goto Usage
  341. REM Write the done file to be used by release
  342. set $BootTestDriveVar=\$\{$BootTestDriveVar\}
  343. set ${BootTestDriveVar}Share=\%$BootTestDriveVar:~0,1\%\$
  344. set LOGFILE=\%$BootTestDriveVar\%\\tools\\BootTest.log
  345. REM Don't create a "booted" remote any longer! It's a security hole!
  346. REM call :LogMe "Create a remote for raiseall.pl"
  347. REM start \%BootTestDrive\%\\tools\\remote /S \"cmd.exe\" Booted
  348. REM If no wait, start raiseall with quality bvt
  349. if not defined Wait (
  350. REM BUGBUG Wait 27 minutes before we try to raise the build to give release time to complete.
  351. sleep 1620
  352. call :LogMe "Raiseall to BVT on all release servers"
  353. for \%\%a in ($ReleaseServers) do (
  354. net use \\\\\%\%a /u:\${BT_U} \${BT_P}
  355. if errorlevel 1 (
  356. call :LogMe "Error - \%\%a can not connect"
  357. ) else (
  358. call :LogMe "Start Raiseall..."
  359. 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
  360. REM 300
  361. \%BootTestDrive\%\\tools\\sleep 3
  362. net use \\\\\%\%a /d
  363. if errorlevel 1 call :LogMe "Error - \%\%a can not disconnect"
  364. )
  365. )
  366. )
  367. call :LogMe "Move PostBootTest.cmd to desktop"
  368. \%$BootTestDriveVar\%\\tools\\perl\\bin\\perl \%$BootTestDriveVar\%\\tools\\OpShellFolder.pl CopyFileTo Desktop \%$BootTestDriveVar\%\\tools\\postboottest.cmd
  369. \%$BootTestDriveVar\%\\tools\\perl\\bin\\perl \%$BootTestDriveVar\%\\tools\\OpShellFolder.pl Delfile Startup postboottest.cmd
  370. call :LogMe "PostBootTest.cmd finished."
  371. goto :exit
  372. :logme
  373. echo \%1
  374. echo \%1>>\%LOGFILE\%
  375. goto :EOF
  376. :exit
  377. endlocal
  378. PostBootTestFile
  379. close(F);
  380. logmsg "Failed to create postboottest.cmd" if (!-e $PostBootTestFile);
  381. return;
  382. }
  383. #################################### Reusable functions
  384. #
  385. # GetFirstBuildMachine($branch, $arch, $type)
  386. #
  387. # purpose: Get first primary build machine or first secondary build machine
  388. # if not defined primary from buildmachines.txt
  389. #
  390. sub GetFirstBuildMachine {
  391. # ($order, $branch, $arch, $type) = ("primary", @_);
  392. my $searchpattern = join(",", @_);
  393. my @BuildMachines;
  394. my ($machinename, $firstbuildmachine, $line);
  395. open(F, "$ENV{RazzleToolPath}\\BuildMachines.txt");
  396. @BuildMachines = <F>;
  397. close(F);
  398. for $line (@BuildMachines) {
  399. $machinename = (split(/\,/, $line))[0];
  400. if ($line =~ /$searchpattern/i) {
  401. return $machinename if ($line =~ /primary/i);
  402. $firstbuildmachine=$machinename if (!defined $firstbuildmachine);
  403. }
  404. }
  405. errmsg "Failed to find a build machine." if(!defined $firstbuildmachine);
  406. return $firstbuildmachine;
  407. }
  408. #
  409. # GetFirstBuildMachine($branch, $arch, $type)
  410. #
  411. # purpose: Get first primary build machine or first secondary build machine
  412. # if not defined primary from buildmachines.txt
  413. #
  414. sub GetAccount {
  415. my (@Request) = ("JoinDomain");
  416. my( $JoinDomain ) = &GetIniSetting::GetSetting( @Request );
  417. return $JoinDomain;
  418. }
  419. #
  420. # GetBuildPath($buildname, [$compname], [$releaseshare])
  421. #
  422. # purpose: Get the fullpath share, so we can write file correctly. such as \\i32fre\release\jpn\1234 => \\i32fre\f$\release\jpn\1234
  423. #
  424. sub GetBuildPath {
  425. my ($releaseshare) = @_;
  426. my ($computername, $sharename, $misc, $sharepath);
  427. # Get the computername, sharename, and remain paths
  428. if ($releaseshare =~ /^\\\\([^\\]+)\\([^\\]+)/) {
  429. ($computername, $sharename, $misc) = ($1, $2, $');
  430. } elsif ($releaseshare =~ /^([^\\]+)/) {
  431. ($computername, $sharename, $misc) = ($ENV{computername}, $1, $');
  432. } else {
  433. errmsg("Can not get correct build path ($releaseshare)");
  434. return;
  435. }
  436. # Replace d: to d$ if applicable
  437. $sharename =~ s/\:/\$/;
  438. for my $line (`rmtshare \\\\$computername\\$sharename`) {
  439. $sharepath=$1 if ($line =~ /^Path\s+(.+)$/);
  440. }
  441. if (!defined $sharepath) {
  442. errmsg("Can not find the path of this share ($sharename)");
  443. return;
  444. }
  445. # Remove d:\ to d: if applicable
  446. $sharepath =~ s/\\$//;
  447. # Replace d: to d$ if applicable
  448. $sharepath =~ s/\:/\$/;
  449. return "\\\\$computername\\$sharepath\\$misc";
  450. }
  451. #
  452. # GetBuildShare($buildname, [$compname], [$releaseshare])
  453. #
  454. # purpose: Get build share from computer ($compname). Default is $ENV{computername
  455. #
  456. sub GetBuildShare {
  457. my ($buildname, $compname, $releaseshare) = @_;
  458. # This setting is misnamed as it is actually used as both the directory
  459. # and share name
  460. my (@Request) = ("AlternateReleaseDir");
  461. my ($inirelease) = &GetIniSetting::GetSetting( @Request );
  462. $compname = $ENV{computername} if (!defined $compname);
  463. $releaseshare = $inirelease || 'release' if (!defined $releaseshare);
  464. my $BuildShare = (lc$lang eq "usa")?"\\\\$compname\\$releaseshare\\$buildname":
  465. "\\\\$compname\\$releaseshare\\$lang\\$buildname";
  466. logmsg "No latest build to test - aborting." if (!defined $BuildShare);
  467. logmsg "No latest build could find - aborting." if (!-e $BuildShare);
  468. return $BuildShare;
  469. }
  470. #
  471. # GetReleaseServers
  472. #
  473. # purpose: Get release server from ini file
  474. #
  475. sub GetReleaseServers {
  476. my (@Request) = ("ReleaseServers", $ENV{_BuildArch} . $ENV{_BuildType});
  477. my ($ReleaseServer) = &GetIniSetting::GetSetting( @Request );
  478. my @ReleaseServers;
  479. @Request = ("PrimaryReleaseServer");
  480. @ReleaseServers = &GetIniSetting::GetSetting( @Request );
  481. # Collect Release Servers to @ReleaseServers
  482. # Avoid to include primary release server twice
  483. #
  484. # hardcode exclude ntburnlab08
  485. push(@ReleaseServers,
  486. grep {!(
  487. # USA case
  488. ((lc$lang eq "usa") && (/ntburnlab08|intblds10/i)) ||
  489. # Primary release server
  490. ((defined $ReleaseServers[0]) && (/\Q$ReleaseServers[0]\E/i)))
  491. } split(/\s+/, $ReleaseServer)
  492. );
  493. errmsg "Could not find release servers to raise." if (!@ReleaseServers);
  494. return @ReleaseServers;
  495. }
  496. sub GetReleaseRemote {
  497. my (@Request) = ("AlternateReleaseRemote");
  498. my( $ReleaseRemote ) = &GetIniSetting::GetSetting( @Request );
  499. $ReleaseRemote = "release" if (!defined $ReleaseRemote);
  500. return $ReleaseRemote;
  501. }
  502. #
  503. # GetBootTestMachine($arch, $type, $sku)
  504. #
  505. # purpose: Get Boot Test Machine from ini file
  506. #
  507. sub GetBootTestMachine {
  508. my ($arch, $type, $sku) = @_;
  509. my (@Request) = ( "BootTestMachines", uc$arch . uc$type, $sku);
  510. return split(/\s+/, &GetIniSetting::GetSetting( @Request ));
  511. }
  512. #
  513. # GetLatestBuildName
  514. #
  515. # purpose: call getlatestrelease.cmd and handle its error
  516. #
  517. sub GetLatestBuildName {
  518. my $buildname = `$ENV{RazzleToolPath}\\PostBuildScripts\\GetLatestRelease.cmd -l:$lang`;
  519. chomp $buildname;
  520. if ($buildname =~ /none/i) {
  521. errmsg "No Binaries tree or latest release found - Aborting.";
  522. return;
  523. }
  524. return $buildname;
  525. }
  526. #
  527. # GetAutoRaise
  528. #
  529. # purpose: check the .ini file to see if we should try to auto raise or not
  530. #
  531. sub GetAutoRaise {
  532. my ($arch, $type) = @_;
  533. my (@Request) = ( "AutoRaise", uc$arch . uc$type);
  534. return (&GetIniSetting::GetSetting( @Request ) =~ /true/i);
  535. }
  536. #
  537. # MyRemoteCommand($Machine, $RemoteId, $cmd)
  538. #
  539. # purpose: Execute $cmd on remote console
  540. #
  541. sub MyRemoteCommand {
  542. my ($Machine, $RemoteId, $cmd, $echotype) = @_;
  543. $echotype = ($echotype eq "1")?"type":"echo";
  544. $cmd = ($cmd=~/\S/)?"$echotype $cmd" : "${echotype}.";
  545. # Make sure this gets logged properly
  546. logmsg("Remote Command: '$cmd'");
  547. # Wait 1 more second each time before each time we execute remote command
  548. sleep 1;
  549. return &MySystemCall("$cmd|remote /c $Machine $RemoteId >nul");
  550. }
  551. #
  552. # MySystemCall($cmd)
  553. #
  554. # purpose: Execute $cmd thru system call
  555. #
  556. sub MySystemCall {
  557. my ($cmd) = @_;
  558. my $r = system($cmd);
  559. $r >>= 8;
  560. # Because remote command always return 4, we should ignore it.
  561. if (($r)&&($r ne 4)&&($r ne 0)) {
  562. errmsg "Failed ($r): $cmd";
  563. return 0;
  564. }
  565. return 1;
  566. }
  567. #
  568. # splitcolon($str)
  569. #
  570. # purpose: split $str with delimiter ':' and return splited string
  571. #
  572. sub splitcolon {
  573. return grep {/\w+/} split(/\:/, $_[0]);
  574. }
  575. ##################################
  576. sub ValidateParams {
  577. #<Add your code for validating the parameters here>
  578. }
  579. # <Add your usage here>
  580. sub Usage {
  581. print <<USAGE;
  582. Purpose of program
  583. Usage: $0 [-l lang] [-y [pro\|ads\|ser\|dtd]]
  584. -l Language
  585. -y sku select
  586. -? Displays usage
  587. As of 02/13/01, the sku choice of [srv, pro] is available
  588. for GER x86, and JPN x86 only.
  589. Example:
  590. $0 -l jpn
  591. $0 -l:ger -y:pro
  592. USAGE
  593. }
  594. sub GetParams {
  595. # Step 1: Call pm getparams with specified arguments
  596. &GetParams::getparams(@_);
  597. # Step 2: Set the language into the enviroment
  598. $ENV{lang}=$lang;
  599. # Step 3: Call the usage if specified by /?
  600. if ($HELP) {
  601. &Usage();
  602. exit 1;
  603. }
  604. }
  605. # Cmd entry point for script.
  606. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  607. # Step 1: Parse the command line
  608. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  609. &GetParams ('-o', 'l:y:', '-p', 'lang selectedsku', @ARGV);
  610. # Include local environment extensions
  611. &LocalEnvEx::localenvex('initialize');
  612. # Set lang from the environment
  613. $lang=$ENV{lang};
  614. # Validate the option given as parameter.
  615. &ValidateParams;
  616. # Step 4: Call the main function
  617. &autoboottest::Main();
  618. # End local environment extensions.
  619. &LocalEnvEx::localenvex('end');
  620. }
  621. # -------------------------------------------------------------------------------------------
  622. # Script: autoboottest.pl
  623. # Purpose: Template perl perl script for the NT postbuild environment
  624. # SD Location: %sdxroot%\tools\postbuildscripts
  625. #
  626. # (1) Code section description:
  627. # CmdMain - Developer code section. This is where your work gets done.
  628. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  629. #
  630. # (2) Reserved Variables -
  631. # $ENV{HELP} - Flag that specifies usage.
  632. # $ENV{lang} - The specified language. Defaults to USA.
  633. # $ENV{logfile} - The path and filename of the logs file.
  634. # $ENV{logfile_bak} - The path and filename of the logfile.
  635. # $ENV{errfile} - The path and filename of the error file.
  636. # $ENV{tmpfile} - The path and filename of the temp file.
  637. # $ENV{errors} - The scripts errorlevel.
  638. # $ENV{script_name} - The script name.
  639. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  640. # postbuild operates on.
  641. # $ENV{_NTPostBld_Bak} - Reserved support var.
  642. # $ENV{_temp_bak} - Reserved support var.
  643. #
  644. # (3) Reserved Subs -
  645. # Usage - Use this sub to discribe the scripts usage.
  646. # ValidateParams - Use this sub to verify the parameters passed to the script.
  647. #
  648. # (4) Call other executables or command scripts by using:
  649. # system "foo.exe";
  650. # Note that the executable/script you're calling with system must return a
  651. # non-zero value on errors to make the error checking mechanism work.
  652. #
  653. # Example
  654. # if (system("perl.exe foo.pl -l $lang")){
  655. # errmsg("perl.exe foo.pl -l $lang failed.");
  656. # # If you need to terminate function's execution on this error
  657. # goto End;
  658. # }
  659. #
  660. # (5) Log non-error information by using:
  661. # logmsg "<log message>";
  662. # and log error information by using:
  663. # errmsg "<error message>";
  664. #
  665. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  666. # by a member of the international build team (ntbintl).
  667. #
  668. # -------------------------------------------------------------------------------------------
  669. =head1 NAME
  670. B<mypackage> - What this package for
  671. =head1 SYNOPSIS
  672. <An code example how to use>
  673. =head1 DESCRIPTION
  674. <Use above example to describe this package>
  675. =head1 INSTANCES
  676. =head2 <myinstances>
  677. <Description of myinstances>
  678. =head1 METHODS
  679. =head2 <mymathods>
  680. <Description of mymathods>
  681. =head1 SEE ALSO
  682. <Some related package or None>
  683. =head1 AUTHOR
  684. <Your Name <your e-mail address>>
  685. =cut
  686. 1;