-
Notifications
You must be signed in to change notification settings - Fork 0
/
winauto_benchmark.py
484 lines (358 loc) · 14.6 KB
/
winauto_benchmark.py
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
#-*-coding:utf-8-*-
import win32gui
import win32api
import win32con
import os
import ctypes
import time
import subprocess
import threading
import diskpart_tool
import screenPrt
import unittest
tool_dic = {
"ASSD" : ("AS SSD Benchmark 1.9.5986.35387", r"D:\SSD performance\AS SSD Benchmark\AS SSD Benchmark.exe"),
"CDM" : ("CrystalDiskMark 6.0.1 x64", r"D:\SSD performance\CrystalDiskMark6_0_1DiskMark64.exe"),
#"CDM" : ("CrystalDiskMark 5.1.2 x64", r"D:\SSD performance\CrystalDiskMark5\DiskMark64.exe"),
"ATTO" : ("Untitled - ATTO Disk Benchmark", r"D:\SSD performance\ATTO Disk Benchmark\ATTO Disk Benchmark.exe"),
"TXB" : ("TxBENCH - New project", r"D:\SSD performance\TxBENCH.exe"),
"HDtune": ("HD Tune Pro 5.60 - 硬盘/固态硬盘实用程序 ", r"D:\SSD performance\HD Tune Pro.exe"),
"Anvil" : ("Anvil's Storage Utilities 1.1.0 (2014-January-1)", r"D:\SSD performance\Anvil`s Storage Utilities\AnvilPro.exe"),
"CDI" : ("CrystalDiskInfo 7.6.0 ", r"C:\Program Files (x86)\CrystalDiskInfo\DiskInfo32.exe")
}
def get_child_windows(parent):
""" 获得parent的所有子窗口句柄
Arguments:
parent {int} -- 父窗口句柄号
Returns:
[list] -- 返回子窗口句柄列表
"""
hwndChildList = []
win32gui.EnumChildWindows(parent, lambda hwnd, param: param.append(hwnd), hwndChildList)
return hwndChildList
def get_all_child(tool="Untitled - ATTO Disk Benchmark"):
"""
function:列出窗口所有子类,类型,名称
"""
#tool = "Untitled - ATTO Disk Benchmark"
hwnd = win32gui.FindWindow(None, tool)
hwndChildList = get_child_windows(hwnd)
print(hwndChildList)
a = ""
for k in hwndChildList:
b = "{}---{}---{}---{}---{}".format(hwndChildList.index(k),k,win32gui.GetWindowText(k),win32gui.GetClassName(k),win32gui.GetWindowRect(k))
#print("{}:{}:{}".format(win32gui.GetWindowText(k),win32gui.GetClassName(k),win32gui.GetWindowRect(k)))
a = a + b + "\n"
return a
def mouse_move(new_x, new_y):
"""移动鼠标
Arguments:
new_x {int} -- 横坐标
new_y {int} -- 纵坐标
"""
point = (new_x, new_y)
win32api.SetCursorPos(point)
def mouse_click(x, y, idle=1):
mouse_move(x, y)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
time.sleep(idle)
def keybd_single_char(input_key, idle=1):
"""键盘输入字符
Arguments:
input_key {str} -- 键盘字符
Keyword Arguments:
idle {int} -- 字符输入后等待时间 (default: {1})
"""
input_key = ord(input_key)
win32api.keybd_event(input_key, 0, 0, 0)
win32api.keybd_event(input_key, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(idle)
def button_center(phwnd):
"""获取句柄中心点
Arguments:
phwnd {int} -- 句柄号
Returns:
int -- 中心点坐标
"""
center_xy = win32gui.GetWindowRect(phwnd)
center_x = ( center_xy[0] + center_xy[2] ) // 2
center_y = ( center_xy[1] + center_xy[3] ) // 2
return center_x, center_y
def run_tool(tool="", wait = 5):
cmd = 'start "aa" "{}"'.format(tool)
os.system(cmd)
time.sleep(wait)
def run_assd(target = "F"):
tool, tool_path= tool_dic["ASSD"]
run_tool(tool_path)
#找到tool 所在的窗口
hwnd = win32gui.FindWindow(None, tool)
#设置assd窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,140,0,0, win32con.SWP_NOSIZE)
hwndChildList = get_child_windows(hwnd)
#磁盘选择窗口/磁盘名称窗口/开始按键
disk_select = hwndChildList[10]
write_aactime = hwndChildList[31]
#选择待测试磁盘
xy = button_center(disk_select)
mouse_click(xy[0], xy[1])
keybd_single_char("C")
keybd_single_char(target)
mouse_click(xy[0], xy[1])
# 找到 start按键
hwnd1= win32gui.FindWindowEx(hwnd, None, None, "Start")
xy = button_center(hwnd1)
mouse_move(xy[0], xy[1])
#开始运行
mouse_click(xy[0], xy[1])
while True:
write_aactime_current = win32gui.GetWindowText(write_aactime)
flag = 0
#判断当前是否Acc time write 是否 为0
if write_aactime_current != "0.000 ms" :
for cnt in range(0, 10):
if write_aactime_current != win32gui.GetWindowText(write_aactime):
break
else:
flag = flag + 1
time.sleep(1)
if flag == 10:
break
filename = "{}.bmp".format(tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
close_window(tool)
def close_window(window="TxBENCH - New project"):
"""关闭窗口
Keyword Arguments:
window {str} -- 窗口名称 (default: {"TxBENCH - New project"})
"""
win32gui.PostMessage(win32gui.FindWindow(0, window), win32con.WM_CLOSE, 0, 0)
def run_CrystalDiskMark5(target = "T"):
tool = "CrystalDiskMark 5.1.2 x64"
tool, tool_path= tool_dic["CDM"]
run_tool(tool_path)
#找到tool 所在的窗口
hwnd = win32gui.FindWindow(None, tool)
#设置窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,140,0,0, win32con.SWP_NOSIZE)
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
x1, y1, x2 ,y2 = win32gui.GetWindowRect(hwndChildList[0])
disk_select_xy = [x1 + 300, y1 + 25]
start_xy = [x1 + 50, y1 + 35]
mouse_click(disk_select_xy[0], disk_select_xy[1])
mouse_click(disk_select_xy[0], disk_select_xy[1])
keybd_single_char(target)
#开始测试
mouse_click(start_xy[0], start_xy[1])
if "CrystalDiskMark 5." in tool:
run_check = [#"Sequential Read Multi [5/5]",
"Sequential Write Multi [5/5]",
#"Random Read 4KiB Multi [5/5]",
"Random Write 4KiB Multi [5/5]",
#"Sequential Read [5/5]",
"Sequential Write [5/5]",
"Random Write 4KiB [5/5]"
]
elif "CrystalDiskMark 6." in tool:
run_check = [#"Sequential Read Multi [5/5]",
# "Sequential Write Multi [5/5]",
# #"Random Read 4KiB Multi [5/5]",
# "Random Write 4KiB Multi [5/5]",
#"Sequential Read [5/5]",
"Sequential Write [5/5]",
"Interval Time 1/5 sec",
"Random Write 4KiB [5/5]",
"Interval Time 1/5 sec",
"Random Write 4KiB [5/5]",
"Interval Time 1/5 sec",
"Random Write 4KiB [5/5]"
]
for status in run_check:
while True:
if win32gui.GetWindowText(hwnd) != status:
time.sleep(0.1)
else:
time.sleep(1)
break
print(status)
while win32gui.GetWindowText(hwnd) != tool:
time.sleep(1)
filename = "{}.bmp".format(tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
close_window(tool)
def run_Anvil(target = "T"):
tool = "Anvil's Storage Utilities 1.1.0 (2014-January-1)"
tool, tool_path= tool_dic["Anvil"]
run_tool(tool_path,7)
#找到tool 所在的窗口
hwnd = win32gui.FindWindow(None, tool)
#设置窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,140,0,0, win32con.SWP_NOSIZE)
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
hwnd_QD_Write = win32gui.FindWindow(None, "IO - Threaded QD (Random Write)")
disk_select = button_center(hwndChildList[8])
disk_run = button_center(hwndChildList[14])
disk_tmp = button_center(hwndChildList[10])
mouse_click(disk_select[0], disk_select[1])
mouse_click(disk_select[0], disk_select[1])
keybd_single_char(target)
mouse_click(disk_run[0], disk_run[1])
# #print(disk_select)
# mouse_move(disk_select[0], disk_select[1])
for i in range(0, 3):
while not win32gui.IsWindowVisible(hwnd_QD_Write):
time.sleep(0.1)
while win32gui.IsWindowVisible(hwnd_QD_Write):
time.sleep(0.1)
else:
time.sleep(3)
# win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,140,0,0, win32con.SWP_NOSIZE)
#time.sleep(3)
#开始测试
mouse_click(disk_tmp[0], disk_tmp[1],2)
mouse_click(disk_tmp[0], disk_tmp[1],2)
filename = "{}.bmp".format(tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
#time.sleep(10)
#close_window(tool)
def run_ATTO_Disk_Benchmark(target = "T"):
tool = "Untitled - ATTO Disk Benchmark"
tool_path = r'start "aa" "D:\SSD performance\ATTO Disk Benchmark\ATTO Disk Benchmark.exe"'
tool, tool_path= tool_dic["ATTO"]
run_tool(tool_path)
#找到tool 所在的窗口
hwnd = win32gui.FindWindow(None, tool)
#设置窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,0,0,0, win32con.SWP_NOSIZE)
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
disk_select = button_center(hwndChildList[2])
mouse_move(disk_select[0], disk_select[1])
keybd_single_char(target)
start_button = button_center(hwndChildList[27])
mouse_click(start_button[0], start_button[1])
start_time = time.time()
while win32gui.GetWindowText(hwndChildList[-10]) == "":
time.sleep(1)
elapsed_time = time.time() - start_time
assert elapsed_time < 6000 , "timeout!"
filename = "{}.bmp".format(tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
print("run {} finished!".format(tool))
cmd = r'taskkill /F /IM "ATTO Disk Benchmark.exe"'
os.system(cmd)
def run_TxBENCH(target = "T"):
tool = "TxBENCH - New project"
tool_path = r'start "aa" "D:\SSD performance\TxBENCH.exe'
tool, tool_path= tool_dic["TXB"]
run_tool(tool_path)
#找到tool 所在的窗口
hwnd = win32gui.FindWindow(None, tool)
#设置窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,140,0,0, win32con.SWP_NOSIZE)
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
start_button = button_center(hwndChildList[13])
start_init = win32gui.GetWindowText(hwndChildList[13])
mouse_click(start_button[0], start_button[1])
time.sleep(4)
start_time = time.time()
while win32gui.GetWindowText(hwndChildList[13]) != start_init:
time.sleep(1)
elapsed_time = time.time() - start_time
assert elapsed_time < 6000 , "timeout!"
filename = "{}.bmp".format(tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
print("run {} finished!".format(tool))
close_window(tool)
def get_DiskInfo(target = 0, image = ""):
tool, tool_path= tool_dic["CDI"]
run_tool(tool_path)
hwnd = win32gui.FindWindow(None, tool)#找到tool 的句柄
print(hwnd)
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0,0,2000,2000, win32con.SWP_SHOWWINDOW)#设置窗口为焦点
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
target_button = button_center(hwndChildList[2 + target]) #获取所需磁盘的按键
mouse_click(target_button[0], target_button[1])
filename = "{}-{}.bmp".format(image,tool)
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
print("run {} finished!".format(tool))
#close_window(tool)
return filename
def run_HDtune(disk_number=100):
a= diskpart_tool.DiskPart()
a.clean(disk_number)
tool = "HD Tune Pro 5.60 - 硬盘/固态硬盘实用程序 "
tool_path = r'start "aa" "D:\SSD performance\HD Tune Pro.exe'
tool, tool_path= tool_dic["HDtune"]
run_tool(tool_path)
hwnd = win32gui.FindWindow(None, tool)
#设置窗口为焦点
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 383,0,0,0, win32con.SWP_NOSIZE)
assert win32gui.GetWindowText(hwnd) == tool, "run tool name wrong!"
hwndChildList = get_child_windows(hwnd)
disk_select = button_center(hwndChildList[0])
mouse_click(disk_select[0], disk_select[1])
mouse_click(disk_select[0], disk_select[1] + 14 *(disk_number + 1))
start_button = button_center(hwndChildList[13])
read_button = button_center(hwndChildList[14])
write_button = button_center(hwndChildList[15])
start_init = win32gui.GetWindowText(hwndChildList[13])
print(start_init)
mouse_click(write_button[0],write_button[1])
time.sleep(0.5)
mouse_click(start_button[0],start_button[1])
time.sleep(0.5)
hwnd_write_yes_window = win32gui.FindWindow(None, "警告!")
hwnd_ChildList = get_child_windows(hwnd_write_yes_window)
run_write_button = button_center(hwnd_ChildList[3])
confirm_button = button_center(hwnd_ChildList[0])
mouse_click(run_write_button[0], run_write_button[1])
time.sleep(2)
mouse_click(confirm_button[0], confirm_button[1])
time.sleep(5)
start_time = time.time()
while win32gui.GetWindowText(hwndChildList[13]) != start_init:
time.sleep(1)
elapsed_time = time.time() - start_time
assert elapsed_time < 600 , "timeout!"
time.sleep(2)
filename = "HDtune_write.bmp"
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
time.sleep(4)
mouse_click(read_button[0], read_button[1])
time.sleep(0.5)
mouse_click(start_button[0],start_button[1])
time.sleep(5)
start_time = time.time()
while win32gui.GetWindowText(hwndChildList[13]) != start_init:
time.sleep(1)
elapsed_time = time.time() - start_time
assert elapsed_time < 600 , "timeout!"
time.sleep(1)
filename = "HDtune_read.bmp"
screenPrt.ScreenPrintWin().save_bitmap(bmp_filename= filename)
close_window(tool)
return filename
def run_performance(disk_number=100, partition_name = "A"):
# a = diskpart_tool.DiskPart()
# a.clean(disk_number)
# a.create_partition_primary(disk_number=disk_number, filesystem="ntfs",partition_name =partition_name)
#print(a.scan())
time.sleep(2)
run_assd(partition_name)
time.sleep(2)
run_CrystalDiskMark5(partition_name)
time.sleep(2)
run_ATTO_Disk_Benchmark(partition_name)
time.sleep(2)
run_TxBENCH(partition_name)
time.sleep(2)
#run_HDtune(disk_number=disk_number)
if __name__ == "__main__" :
get_DiskInfo(2, "ss")