-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark2.psm1
1577 lines (1150 loc) · 41.1 KB
/
benchmark2.psm1
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function benchmark2 ([string]$para1, [string]$para2, [string]$para3,[string]$para4){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$wshell=New-Object -com wscript.shell
#$shell=New-Object -ComObject shell.application
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#region functions
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
}
public class Win32 {
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
}
public struct RECT {
public int Left;
public int Top;
public int Right;
public int Bottom;
}
"@
$cSource = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Clicker
{
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public int type; // 0 = INPUT_MOUSE,
// 1 = INPUT_KEYBOARD
// 2 = INPUT_HARDWARE
public MOUSEINPUT mi;
}
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx ;
public int dy ;
public int mouseData ;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
//This covers most use cases although complex mice may have additional buttons
//There are additional constants you can use for those cases, see the msdn page
const int MOUSEEVENTF_MOVED = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN = 0x0002 ;
const int MOUSEEVENTF_LEFTUP = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP = 0x0040 ;
const int MOUSEEVENTF_WHEEL = 0x0080 ;
const int MOUSEEVENTF_XDOWN = 0x0100 ;
const int MOUSEEVENTF_XUP = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE = 0x8000 ;
const int screen_length = 0x10000 ;
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public static void LeftClickAtPoint(int x, int y)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
}
'@
Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing
Function Set-ScreenResolution {
<#
.Synopsis
Sets the Screen Resolution of the primary monitor
.Description
Uses Pinvoke and ChangeDisplaySettings Win32API to make the change
.Example
Set-ScreenResolution -Width 1024 -Height 768
#>
param (
[Parameter(Mandatory=$true,
Position = 0)]
[int]
$Width,
[Parameter(Mandatory=$true,
Position = 1)]
[int]
$Height
)
$pinvokeCode = @"
using System;
using System.Runtime.InteropServices;
namespace Resolution
{
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE1
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public short dmOrientation;
public short dmPaperSize;
public short dmPaperLength;
public short dmPaperWidth;
public short dmScale;
public short dmCopies;
public short dmDefaultSource;
public short dmPrintQuality;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
class User_32
{
[DllImport("user32.dll")]
public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);
public const int ENUM_CURRENT_SETTINGS = -1;
public const int CDS_UPDATEREGISTRY = 0x01;
public const int CDS_TEST = 0x02;
public const int DISP_CHANGE_SUCCESSFUL = 0;
public const int DISP_CHANGE_RESTART = 1;
public const int DISP_CHANGE_FAILED = -1;
}
public class PrmaryScreenResolution
{
static public string ChangeResolution(int width, int height)
{
DEVMODE1 dm = GetDevMode1();
if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);
if (iRet == User_32.DISP_CHANGE_FAILED)
{
return "Unable To Process Your Request. Sorry For This Inconvenience.";
}
else
{
iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
switch (iRet)
{
case User_32.DISP_CHANGE_SUCCESSFUL:
{
return "Success";
}
case User_32.DISP_CHANGE_RESTART:
{
return "You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode.";
}
default:
{
return "Failed To Change The Resolution";
}
}
}
}
else
{
return "Failed To Change The Resolution.";
}
}
private static DEVMODE1 GetDevMode1()
{
DEVMODE1 dm = new DEVMODE1();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
}
}
"@
Add-Type $pinvokeCode -ErrorAction SilentlyContinue
[Resolution.PrmaryScreenResolution]::ChangeResolution($width,$height)
}
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class SFW {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
$source = @"
using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace KeySends
{
public class KeySend
{
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private const int KEYEVENTF_EXTENDEDKEY = 1;
private const int KEYEVENTF_KEYUP = 2;
public static void KeyDown(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
}
public static void KeyUp(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
}
}
"@
Add-Type -TypeDefinition $source -ReferencedAssemblies "System.Windows.Forms"
$Signature = @"
[DllImport("user32.dll")]public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
"@
#$ShowWindowAsync = Add-Type -MemberDefinition $Signature -Name "Win32ShowWindowAsync" -Namespace Win32Functions -PassThru
#endregion
#$paracheck1=$PSBoundParameters.ContainsKey('para1')
#$paracheck2=$PSBoundParameters.ContainsKey('para2')
$paracheck3=$PSBoundParameters.ContainsKey('para3')
if($paracheck3 -eq $false -or $para3.Length -eq 0){
$para3=""
}
$bitype=$para1
$bitconfig=$para2
$noexit_flag=$para3
$nonlog_flag=$para4
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
#$timenow=get-date -format "yyMMdd_HHmmss"
#$picpath=(Split-Path -Parent $scriptRoot)+"\logs\screenshot\"
$picpath=(Split-Path -Parent $scriptRoot)+"\logs\$($tcnumber)\"
if(-not(test-path $picpath)){new-item -ItemType directory -path $picpath |out-null}
$width = (([string]::Join("`n", (wmic path Win32_VideoController get CurrentHorizontalResolution))).split("`n") -match "\d{1,}")[0]
$height = (([string]::Join("`n", (wmic path Win32_VideoController get CurrentVerticalResolution))).split("`n") -match "\d{1,}")[0]
$actionss="screenshot"
Get-Module -name $actionss|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionss\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
$actioncmd="cmdline"
Get-Module -name $actioncmd|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actioncmd\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
if($bitype -match "SPECviewperf13"){
$action="SPECviewperf13 Benchmark"
## copy tool ##
function netdisk_connect([string]$webpath,[string]$username,[string]$passwd,[string]$diskid){
net use $webpath /delete
net use $webpath /user:$username $passwd /PERSISTENT:yes
net use $webpath /SAVECRED
if($diskid.length -ne 0){
$diskpath=$diskid+":"
$checkdisk=net use
if($checkdisk -match $diskpath){net use $diskpath /delete}
net use $diskpath $webpath
}
}
netdisk_connect -webpath \\192.168.2.249\srvprj\Inventec\Dell -username pctest -passwd pctest -diskid Y
$autopath="Y:\Matagorda\07.Tool\_AutoTool"
$copytopath="C:\testing_AI\modules\BITools\SPECviewperf13"
if(!(test-path $copytopath)){
Expand-Archive "$autopath\extra_tools\SPECviewperf13.zip" -DestinationPath $copytopath
<#
new-item -ItemType directory $copytopath |Out-Null
$zipfile="$autopath\extra_tools\SPECviewperf13.zip"
$copytopath="C:\testing_AI\modules\BITools\SPECviewperf13"
write-host "unzip $zipfile to $copytopath"
$shell.NameSpace($copytopath).copyhere($shell.NameSpace($zipfile).Items(),16)
#>
}
$resultss= Set-ScreenResolution -Width 1920 -Height 1080
if( $resultss -match "failed"){
$results="NG, Fail to change resolution to 1920*1080"
$Index="-"
$noexit_flag="noexit"
}
else{
<##
$displayw=[int64](([System.Windows.Forms.Screen]::AllScreens).Bounds).Width
$displayh=[int64](([System.Windows.Forms.Screen]::AllScreens).Bounds).Height
$systemw= [int64](($width.split())[0])
$systemh=[int64](($height.split())[0])
$diffw=$displayw- $systemw
$diffh= $displayh- $systemh
if(-not($diffw -eq 0 -and $diffh -eq 0)){
Set-ScreenResolution -Width $systemw -Height $systemh
}
#>
start-sleep -s 5
$bipath=(Get-ChildItem "$scriptRoot\BITools\$bitype\" -r -file |Where-object{$_.name -match "exe"}).FullName
get-process nw -ErrorAction SilentlyContinue|stop-process -Force
get-process viewperf -ErrorAction Silent|stop-process -Force
start-sleep -s 10
## check install and install ###
$installspec13=$false
(Get-ChildItem "HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\")|ForEach-Object{
$n=$_.name
$n=$n.Replace("HKEY_LOCAL_MACHINE\","HKLM:")
($p=Get-ItemProperty $n)|ForEach-Object{
#$_.DisplayName
if($_.DisplayName -match "SPECviewperf" -and $_.DisplayName -match "13"){
$installspec13=$true
}
}
}
if($installspec13 -eq $false){
#&$bipath /VERYSILENT
&$bipath /VERYSILENT
$starttime= (get-date).ToString()
write-host "installing will take about 30 minutes" -nonewline
set-content $picpath\installtime.txt -value "installing will take about 25+ minutes from $starttime"
do{
start-sleep -s 10
$check13=((Get-Process -name SPECgpcViewperf13.0 -ErrorAction SilentlyContinue).Id).count
write-host "." -nonewline
}until($check13 -eq 0 )
write-host
$endtime= (get-date).ToString()
write-host "installing done $endtime"
add-content $picpath\installtime.txt -value "installing done $endtime"
start-sleep -s 10
$idrelesaenote=(get-process *|Where-object{$_.MainWindowTitle -match "release_note"}).Id
if($idrelesaenote){
[Microsoft.VisualBasic.interaction]::AppActivate( $idrelesaenote)|out-null
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("%{F4}")
start-sleep -s 2
}
}
<### setting viewsets ##
if($bitconfig.Length -ne 0){
$viewsets=$bitconfig.split("+")
$folders=Get-ChildItem -Directory C:\SPEC\SPECgpc\SPECviewperf13\viewsets\
foreach ($folder in $folders){
if($folder.Name -notin $viewsets){
$des="C:\SPEC\SPECgpc\SPECviewperf13\temp\"
if( -not(test-path $des) ){new-item -ItemType directory $des|out-null}
Move-Item -Path $folder.fullname -Destination $des -Force
}
}
}
###>
### revise 【index.html】 ##
$setindex="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\index.html"
$setindexb="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\index_0.html"
$mgntjs="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\gwpgManageBenchmark.js"
$mgntjsb="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\gwpgManageBenchmark_0.js"
$mgntjsb1="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\gwpgManageBenchmark_1.js"
$mgntrbjs="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\gwpgRunBenchmark.js"
$mgntrbjsb="C:\SPEC\SPECgpc\SPECviewperf13\vp13bench\gwpgRunBenchmark_0.js"
if(Test-Path $setindexb){
move-item $setindexb $setindex -Force -ErrorAction SilentlyContinue
}
$newhtml=get-content $setindex|ForEach-Object{
if($_ -match "<footer>"){
" <script>window.setInterval (run_benchmark,20000);</script>" ###<footer>前加入 <script>window.setInterval (run_benchmark,10000);</script> ->30秒後自動開始
}
$_
}
#move-item $setindex $setindexb -Force
#$newhtml|set-content $setindex ## wait 2nd time replace
### revise 【gwpgManageBenchmark.js】 1. viewset settings ##
if(Test-Path $mgntjsb ){
move-item $mgntjsb $mgntjs -Force -ErrorAction SilentlyContinue
}
if($bitconfig.Length -ne 0){
$defviewset=($bitconfig.split("+")|ForEach-Object{"'"+$_+"'"}) -join "," # ['3dsmax-06','catia-05'];
$oriline="'3dsmax-06','catia-05','creo-02','energy-02','maya-05','medical-02','showcase-02','snx-03','sw-04'"
}
$changefalse=999
$newmngmjs=get-content $mgntjs|ForEach-Object{
if($bitconfig.Length -ne 0 -and $_ -like "*var official_viewsets*"){
$_ = " var official_viewsets = ["+$defviewset+"];"
}
if ($_ -like "*if (onSubmission)*"){
$changefalse=0
}
$changefalse++
if($changefalse -eq 9){
$addline="document.getElementById(""official-run"").checked = false;"
$addline
}
$_
}
move-item $mgntjs $mgntjsb -Force -ErrorAction SilentlyContinue
$newmngmjs|set-content $mgntjs
### revise 【gwpgManageBenchmark.js】 2. disable alert ## 【gwpgManageBenchmark.js】// alert('DPI must be 96 for a submission candidate.');
$newmngmjs2=get-content $mgntjs|ForEach-Object{
$oriline="alert('DPI must be 96 for a submission candidate.')"
if($_ -like "*$oriline*"){
$_ = "// " +$_
}
$_
}
move-item $mgntjs $mgntjsb1 -Force -ErrorAction SilentlyContinue
$newmngmjs2|set-content $mgntjs
### revise【gwpgRunBenchmark.js】for auto running ###
if(Test-Path $mgntjsb ){
move-item $mgntrbjsb $mgntrbjs -Force -ErrorAction SilentlyContinue
}
$remarklines=@("122","125")
$n=0
$newrunjs=get-content $mgntrbjs|ForEach-Object{
if($n -in $remarklines){
if(-not ($_ -match "//")){$_ = "// " +$_}
}
$_
$n++
}
move-item $mgntrbjs $mgntrbjsb -Force -ErrorAction SilentlyContinue
$newrunjs|set-content $mgntrbjs
### start UI & screenshot ###
start-sleep -s 5
$runcommand=".\gui\nw.exe"
set-location "C:\SPEC\SPECgpc\SPECviewperf13\"
&$runcommand vp13bench
start-sleep -s 10
## screenshot for settings at start ###
&$actionss -para3 nonlog -para5 "$action-start"
$picfile1=(Get-ChildItem $picpath |Where-object{$_.name -match ".jpg" -and $_.name -match "$action-start" }).FullName
stop-process -name nw
## revise index for autostarting
move-item $setindex $setindexb -Force -ErrorAction SilentlyContinue
$newhtml|set-content $setindex ## wait 2nd time replace
### start UI & screenshot ###
start-sleep -s 5
&$runcommand vp13bench
## screenshot for running ###
start-sleep -s 40
#### check if fail to open##
if( ((get-process -Name nw).Id).count -eq 0 -and ((get-process -Name viewperf).Id).count -eq 0 ){
#### outlog parameteres ###
$results="NG"
$Index="Fail to open programs"
}
else{
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyDown("B")
[KeySends.KeySend]::KeyUp("LWin")
[KeySends.KeySend]::KeyUp("B")
Start-Sleep -s 1
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyUp("LWin")
Start-Sleep -s 1
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyUp("LWin")
Start-Sleep -s 2
## screenshot for runnings ###
&$actionss -para3 nonlog -para5 "$action-running"
$picfile2=(Get-ChildItem $picpath |Where-object{$_.name -match ".jpg" -and $_.name -match "$action-running" }).FullName
start-sleep -s 5
&$actionss -para3 nonlog -para5 "$action-running2"
$picfile3=(Get-ChildItem $picpath |Where-object{$_.name -match ".jpg" -and $_.name -match "$action-running2\b" }).FullName
### assign task schedule ####
### assign task schedule ####
start-process cmd -ArgumentList '/c schtasks /delete /TN "Auto_Run" -f'
start-sleep -s 5
$actionsch = New-ScheduledTaskAction -Execute "C:\testing_AI\AutoRun.bat"
$etime=(Get-Date).AddMinutes(5)
$trigger = New-ScheduledTaskTrigger -Once -At $etime -RepetitionInterval ([TimeSpan]::FromMinutes(5))
$Stset = New-ScheduledTaskSettingsSet -Priority 0 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
$user=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$STPrin= New-ScheduledTaskPrincipal -User $user -RunLevel Highest
Register-ScheduledTask -Action $actionsch -Trigger $trigger -Settings $Stset -Force -TaskName "Auto_Run" -Principal $STPrin
start-sleep -s 5
#### outlog parameteres ###
$Index=$picfile1+"`n"+$picfile2+"`n"+$picfile3
$results="chceck screenshots"
}
}
}
if($bitype -match "SPECviewperf2020"){
#check if exe dowloaded form web
$flowcheck=(import-csv -path C:\testing_AI\logs\logs_timemap.csv|where-object{$_.tc -match $tcnumber -and $_.program -match "specview_dl"}).results
$copyfromserver=$true
if($flowcheck -match "ok"){
$copyfromserver=$false
}
## copy tool ##
if($copyfromserver -eq $true){
function netdisk_connect([string]$webpath,[string]$username,[string]$passwd,[string]$diskid){
net use $webpath /delete
net use $webpath /user:$username $passwd /PERSISTENT:yes
net use $webpath /SAVECRED
if($diskid.length -ne 0){
$diskpath=$diskid+":"
$checkdisk=net use
if($checkdisk -match $diskpath){net use $diskpath /delete}
net use $diskpath $webpath
}
}
netdisk_connect -webpath \\192.168.2.249\srvprj\Inventec\Dell -username pctest -passwd pctest -diskid Y
$autopath="Y:\Matagorda\07.Tool\_AutoTool"
$copytopath="C:\testing_AI\modules\BITools\SPECviewperf2020"
if(!(test-path $copytopath)){
Expand-Archive "$autopath\extra_tools\SPECviewperf2020.zip" -DestinationPath $copytopath
<#
new-item -ItemType directory $copytopath |Out-Null
$zipfile="$autopath\extra_tools\SPECviewperf2020.zip"
$copytopath="C:\testing_AI\modules\BITools\SPECviewperf2020"
write-host "unzip $zipfile to $copytopath"
$shell.NameSpace($copytopath).copyhere($shell.NameSpace($zipfile).Items(),16)
#>
}
}
$action="SPECviewperf2020 Benchmark"
$resultss= Set-ScreenResolution -Width 1920 -Height 1080
if( $resultss -match "failed"){
$results="NG, Fail to change resolution to 1920*1080"
$Index="-"
$noexit_flag="noexit"
}
else{
$bipath=(Get-ChildItem "$scriptRoot\BITools\$bitype\" -r -file |Where-object{$_.name -match "exe"}).FullName
get-process nw -ErrorAction SilentlyContinue|stop-process -Force
get-process RunViewperf -ErrorAction Silent|stop-process -Force
start-sleep -s 10
## check install and install ###
$installspec2020=$false
(Get-ChildItem "HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\")|ForEach-Object{
$n=$_.name
$n=$n.Replace("HKEY_LOCAL_MACHINE\","HKLM:")
($p=Get-ItemProperty $n)|ForEach-Object{
#$_.DisplayName
if($_.DisplayName -match "SPECviewperf" -and $_.DisplayName -match "2020"){
$installspec2020=$true
write-host "SPECviewperf2020 has been installed"
}
}
}
if($installspec2020 -eq $false){
#&$bipath /VERYSILENT
$id0=((get-process notepad -ea SilentlyContinue).Id).count
&$bipath /VERYSILENT
$starttime= (get-date).ToString()
write-host "installing will take about few minutes" -nonewline
set-content $picpath\installtime.txt -value "installing will take about 25+ minutes from $starttime"
start-sleep -s 60
do{
start-sleep -s 10
$id1=((get-process notepad -ea SilentlyContinue).Id).count
$check2020heck2020=((Get-Process -name SPECviewperf2020* -ErrorAction SilentlyContinue).Id).count
}until($id1 -gt $id0 -or $check2020heck2020 -eq 0)
Stop-Process -name notepad -ea SilentlyContinue
start-sleep -s 10
$idrelesaenote=(get-process notepad -ea SilentlyContinue|Where-object{$_.MainWindowTitle -match "note"}).Id
if( $idrelesaenote){
[Microsoft.VisualBasic.interaction]::AppActivate( $idrelesaenote)|out-null
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("%{F4}")
start-sleep -s 2
}
}
### copy viewsets ##
if(!(test-path C:\SPEC\SPECgpc\SPECviewperf2020\viewsets\)){
write-host "start copying viewsets"
copy-item -path "\\192.168.2.249\srvprj\Inventec\Dell\Matagorda\07.Tool\SPECviewperf\SPECviewperf 2020\downloaded_viewsets\viewsets\" -destination C:\SPEC\SPECgpc\SPECviewperf2020\ -Force -Recurse
$endtime= (get-date).ToString()
write-host "installing done $endtime"
add-content $picpath\installtime.txt -value "installing done $endtime"
start-sleep -s 10
}
### revise 【index.html】 ##
$setindex="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\index.html"
$setindexb="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\index_0.html"
$mgntjs="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgManageBenchmark.js"
$mgntjsb="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgManageBenchmark_0.js"
$mgntjsb1="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgManageBenchmark_1.js"
$mgntrbjs="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgRunBenchmark.js"
$mgntrbjsb="C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgRunBenchmark_0.js"
if(Test-Path $setindexb){
move-item $setindexb $setindex -Force -ErrorAction SilentlyContinue
}
$newhtml=get-content $setindex|ForEach-Object{
if($_ -match "<footer>"){
" <script>window.setInterval (run_benchmark,20000);</script>" ###<footer>前加入 <script>window.setInterval (run_benchmark,10000);</script> ->30秒後自動開始
}
$_
}
#move-item $setindex $setindexb -Force
#$newhtml|set-content $setindex
if(Test-Path $mgntjsb ){
move-item $mgntjsb $mgntjs -Force -ErrorAction SilentlyContinue
}
### revise 【gwpgManageBenchmark.js】 1. viewset settings
if($bitconfig.Length -ne 0){
$defviewset=($bitconfig.split("+")|ForEach-Object{"'"+$_+"'"}) -join "," # ['3dsmax-06','catia-05'];
$oriline="'3dsmax-07','catia-06','creo-03','energy-03','maya-06','medical-03','snx-04','solidworks-07'"
}
$changefalse=999
$newmngmjs=get-content $mgntjs|ForEach-Object{
if($bitconfig.Length -ne 0 -and $_ -like "*$oriline*"){
$_ = $_.replace($oriline,$defviewset)
}
##
if ($_ -like "*if (onSubmission)*"){
$changefalse=0
}
$changefalse++
if($changefalse -eq 9){
$addline="document.getElementById(""official-run"").checked = false;"
$addline
}
$_
}
move-item $mgntjs $mgntjsb -Force -ErrorAction SilentlyContinue
$newmngmjs|set-content $mgntjs
###>
### revise 【gwpgManageBenchmark.js】 2. disable alert ## 【gwpgManageBenchmark.js】// alert('DPI must be 96 for a submission candidate.');
$newmngmjs2=get-content C:\SPEC\SPECgpc\SPECviewperf2020\vpbench\gwpgManageBenchmark.js|ForEach-Object{
$oriline="lert('DPI must be 96 for a submission candidate.')"
if($_ -like "*$oriline*"){
$_ = "// " +$_
}
$_
}
move-item $mgntjs $mgntjsb1 -Force -ErrorAction SilentlyContinue
$newmngmjs2|set-content $mgntjs
### revise【gwpgRunBenchmark.js】for auto running ###
if(Test-Path $mgntrbjsb ){
move-item $mgntrbjsb $mgntrbjs -Force -ErrorAction SilentlyContinue
}
$remarklines=@("114","117")
$n=0
$newrunjs=get-content $mgntrbjs|ForEach-Object{
if($n -in $remarklines){
if(-not ($_ -match "//")){$_ = "// " +$_}
}
$_
$n++
}
move-item $mgntrbjs $mgntrbjsb -Force -ErrorAction SilentlyContinue
$newrunjs|set-content $mgntrbjs
### start UI & screenshot ###
start-sleep -s 5
$runcommand=".\gui\nw.exe"
set-location "C:\SPEC\SPECgpc\SPECviewperf2020\"
&$runcommand vpbench
start-sleep -s 10
## screenshot for settings at start ###
&$actionss -para3 nonlog -para5 "$action-start"
$picfile1=(Get-ChildItem $picpath |Where-object{$_.name -match ".jpg" -and $_.name -match "$action-start" }).FullName
stop-process -name nw
## revise index for autostarting
move-item $setindex $setindexb -Force -ErrorAction SilentlyContinue
$newhtml|set-content $setindex ## wait 2nd time replace
### start UI & screenshot ###
start-sleep -s 5
&$runcommand vpbench
## screenshot for running ###
start-sleep -s 40
#### check if fail to open##
if( ((get-process -Name nw).Id).count -eq 0 -and ((get-process -Name viewperf).Id).count -eq 0 ){
#### outlog parameteres ###
$results="NG"
$Index="Fail to open programs"
}
else{
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyDown("B")
[KeySends.KeySend]::KeyUp("LWin")
[KeySends.KeySend]::KeyUp("B")
Start-Sleep -s 1
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyUp("LWin")
Start-Sleep -s 1
[KeySends.KeySend]::KeyDown("LWin")
[KeySends.KeySend]::KeyUp("LWin")
Start-Sleep -s 2
## screenshot for runnings ###
&$actionss -para3 nonlog -para5 "$action-running"