-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself-test.py
executable file
·189 lines (153 loc) · 5.56 KB
/
self-test.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
#!/usr/bin/python3
import os
import sys
import random
import string
import subprocess
import re
import math
from time import sleep
#
# Tester for procprog
# Example: make debug && ./procprog ./self-test.py $(tput cols)
#
print("hello")
def cursorPos():
_ = ""
sys.stdout.write("\x1b[6n")
sys.stdout.flush()
while not (_ := _ + sys.stdin.read(1)).endswith('R'):
True
res = re.match(r".*\[(?P<y>\d*);(?P<x>\d*)R", _)
if(res):
return (int(res.group("x")), int(res.group("y")))
return (-1, -1)
try:
term_width = int(sys.argv[1])
except:
term_width = 80
print("\033[33mWarning Add $(tput cols) to your command, assuming 80\033[0m", flush=True)
sleep(3)
extented_ascii = [chr(i) for i in range(256)]
dec_private_modes = [str(i) for i in range(100)]
dec_private_modes.extend([str(i) for i in range(1000, 1062)])
dec_private_modes.append('2004')
starting_x, starting_y = cursorPos()
def prepare_check():
global starting_x
global starting_y
starting_x, starting_y = cursorPos()
def check_cursor_pos(num_chars, test_string):
correct_x = starting_x
correct_y = starting_y #+ (math.ceil(num_chars / term_width) - 1)
actual_x, actual_y = cursorPos()
if (actual_x != correct_x) or (actual_y != correct_y):
print(f"\033[33mCursor in wrong position ({actual_x}, {actual_y}) ({num_chars}, {term_width}, {starting_y}) \
should be ({correct_x}, {correct_y}). Input: {test_string})\033[0m", flush=True)
sys.exit(1)
def csi_commands():
print('Starting csi_commands test 1', flush=True)
sleep(0.5)
for _ in range(0,500):
command = 'test\033[' + ''.join(random.choices(['-1', '', '0', '1', '2', '4', '5', '6'], k=1))
command += ''.join(random.choices(string.ascii_letters, k=1))
print(command, flush=True)
print('Starting csi_commands test 2', flush=True)
sleep(0.5)
for _ in range(0,500):
command = 'test\033[' + ''.join(random.choices(['-1', '', '0', '1', '2', '4', '5', '6'], k=1))
command += ';' + ''.join(random.choices(['-1', '', '0', '1', '2', '4', '5', '6'], k=1))
command += ''.join(random.choices(string.ascii_letters, k=1))
print(command, flush=True)
print('Starting csi_commands test 3', flush=True)
sleep(0.5)
for _ in range(0,500):
command = '\033[' + str(random.randint(0,110)) + 'mtest'
print(command, flush=True)
print('\033[0mStarting csi_commands test 4', flush=True)
sleep(0.5)
for _ in range(0,500):
command = 'test\033[?' + ''.join(random.choices(dec_private_modes, k=1))
command += ''.join(random.choices(['h', 'l'], k=1))
print(command, flush=True)
def full_width():
print('Starting full_width test 1', flush=True)
sleep(0.5)
for i in range(1,10):
for _ in range(0,10):
test_string = ''.join(random.choices(string.ascii_lowercase, k=term_width * i))
print(test_string, flush=True)
print('Starting full_width test 2', flush=True)
sleep(0.5)
for i in range(1,10):
for _ in range(0,10):
test_string = ''.join(random.choices(string.ascii_lowercase, k=(term_width * i) + 1))
print(test_string, flush=True)
print('Starting full_width test 3', flush=True)
sleep(0.5)
for i in range(1,256):
print('a' * term_width, flush=True, end='')
test_string = ''.join(chr(i))
print(test_string, flush=True)
print('Starting full_width test 4', flush=True)
sleep(0.5)
for i in range(1,256):
print('a' * (term_width + 1), flush=True, end='')
test_string = ''.join(chr(i))
print(test_string, flush=True)
print('Starting full_width test 5', flush=True)
sleep(0.5)
for i in range(1,256):
print('a' * term_width, flush=True, end='')
test_string = ''.join(chr(i))
test_string += 'a\nb'
print(test_string, flush=True)
print('Starting full_width test 6', flush=True)
sleep(0.5)
for i in range(1,256):
print('a' * (term_width + 1), flush=True, end='')
test_string = ''.join(chr(i))
test_string += 'a\nb'
print(test_string, flush=True)
print('\n')
def simple():
print('Starting simple test 1', flush=True)
sleep(0.5)
for i in range(1,10):
print(str(i), flush=True)
sleep(0.1)
print('Starting simple test 2', flush=True)
sleep(0.5)
for i in range(1,500):
for _ in range(0,10):
test_string = ''.join(random.choices(string.ascii_lowercase, k=i))
print(test_string, flush=True)
print('Starting simple test 3', flush=True)
sleep(0.5)
for i in range(1,500):
for _ in range(0,10):
test_string = ''.join(random.choices(string.whitespace, k=i))
print(test_string, flush=True)
print('Starting simple test 4', flush=True)
sleep(0.5)
for i in range(1,500):
for _ in range(0,10):
test_string = ''.join(random.choices(string.printable, k=i))
print(test_string, flush=True)
print('Starting simple test 5', flush=True)
sleep(0.5)
#prepare_check()
for i in range(1,500):
for _ in range(0,10):
test_string = ''.join(random.choices(extented_ascii, k=i))
print(test_string, flush=True)
#check_cursor_pos(i, test_string)
print('\033[0m\n')
def diskBench():
subprocess.run(["sudo", "hdparm", "-tT", "/dev/sda"])
if __name__ == '__main__':
print(f"Starting ({starting_x}, {starting_y})", flush=True)
sleep(1)
simple()
full_width()
csi_commands()