How to use get_cpu_status_string method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...878 sent1 += port.sock.send("a")879 except socket.timeout:880"Data sending to closed port timed out.")881"Bytes sent to client: %d" % (sent1))882"\n" + loads.get_cpu_status_string()[:-1])883 on_guest('echo -n "PASS:"', vm, 10)884"Open and then close port %s" % ( init_guest(vm, consoles)886 # Test of live and open and close port again887 _clean_ports(vm, consoles)888 on_guest("virt.close('%s')" % (, vm, 10)889 # With serialport it is a different behavior890 on_guest("guest_exit()", vm, 10)891 port.sock.settimeout(20.0)892 loads.start()893 try:894 sent2 = 0895 for i in range(40000):896 sent2 = port.sock.send("a")897 except socket.timeout:898"Data sending to closed port timed out.")899"Bytes sent to client: %d" % (sent2))900"\n" + loads.get_cpu_status_string()[:-1])901 loads.stop()902 if (sent1 != sent2):903 logging.warning("Inconsistent behavior: First sent %d bytes and "904 "second sent %d bytes" % (sent1, sent2))905 port.sock.settimeout(None)906 (vm[0], vm[1], vm[3]) = _restore_vm()907 init_guest(vm, consoles)908 _clean_ports(vm, consoles)909 def trw_blocking_mode(vm, port):910 """911 Guest read\write data in blocking mode.912 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].913 @param port: Port used in test.914 """915 # Blocking mode916 if not port.is_open:917 on_guest("virt.blocking('%s', True)" %, vm, 10)919 # Recv should timed out920 match, tmp = _on_guest("virt.recv('%s', 10, 1024, False)" %921, vm, 10)922 if match == 0:923 raise error.TestFail("Received data even when none was sent\n"924 "Data:\n%s" % tmp)925 elif match is not None:926 raise error.TestFail("Unexpected fail\nMatch: %s\nData:\n%s" %927 (match, tmp))928 port.sock.sendall("1234567890")929 # Now guest received the data end escaped from the recv()930 on_guest("print('PASS: nothing')", vm, 10)931 def trw_nonblocking_mode(vm, port):932 """933 Guest read\write data in nonblocking mode.934 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].935 @param port: Port used in test.936 """937 # Non-blocking mode938 if not port.is_open:939 on_guest("virt.blocking('%s', False)" %, vm, 10)941 # Recv should return FAIL with 0 received data942 match, tmp = _on_guest("virt.recv('%s', 10, 1024, False)" %943, vm, 10)944 if match == 0:945 raise error.TestFail("Received data even when none was sent\n"946 "Data:\n%s" % tmp)947 elif match is None:948 raise error.TestFail("Timed out, probably in blocking mode\n"949 "Data:\n%s" % tmp)950 elif match != 1:951 raise error.TestFail("Unexpected fail\nMatch: %s\nData:\n%s" %952 (match, tmp))953 port.sock.sendall("1234567890")954 on_guest("virt.recv('%s', 10, 1024, False)" %, vm, 10)955 def tbasic_loopback(vm, send_port, recv_port, data="Smoke test data"):956 """957 Easy loop back test with loop over only two ports.958 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].959 @param port: Port used in test.960 """961 if not send_port.is_open:962 if not recv_port.is_open:964 on_guest("virt.loopback(['%s'], ['%s'], 1024, virt.LOOP_NONE)" %966 (,, vm, 10)967 send_port.sock.sendall(data)968 tmp = ""969 i = 0970 while i <= 10:971 i += 1972 ret =[recv_port.sock], [], [], 1.0)973 if ret:974 tmp += recv_port.sock.recv(1024)975 if len(tmp) >= len(data):976 break977 if tmp != data:978 raise error.TestFail("Incorrect data: '%s' != '%s'",979 data, tmp)980 _guest_exit_threads(vm, [send_port], [recv_port])981 def trmmod(vm, consoles):982 """983 Remove and load virtio_console kernel modules.984 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].985 @param consoles: Consoles which should be close before rmmod.986 """987 on_guest("guest_exit()", vm, 5)988 on_guest("rmmod -f virtio_console && echo -n PASS: rmmod "989 "|| echo -n FAIL: rmmod", vm, 10)990 on_guest("modprobe virtio_console "991 "&& echo -n PASS: modprobe || echo -n FAIL: modprobe",992 vm, 10)993 init_guest(vm, consoles)994 try:995 cname = consoles[0][0].name996 except (IndexError):997 cname = consoles[1][0].name998 on_guest("virt.clean_port('%s'),1024" % cname, vm, 2)999 def tmax_serial_ports(vm, consoles):1000 """1001 Test maximum count of ports in guest machine.1002 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1003 @param consoles: Consoles which should be close before rmmod.1004 """1005 logging.debug("Count of serial ports: 30")1006 vm[0].destroy(gracefully = False)1007 (vm, consoles) = _vm_create(0, 30, False)1008 try:1009 init_guest(vm, consoles)1010 except error.TestFail, ints:1011"Count of serial ports: 30")1012 raise ints1013 clean_reload_vm(vm, consoles, expected=True)1014 def tmax_console_ports(vm, consoles):1015 """1016 Test maximum count of ports in guest machine.1017 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1018 @param consoles: Consoles which should be close before rmmod.1019 """1020 logging.debug("Count of console ports: 30")1021 vm[0].destroy(gracefully = False)1022 (vm, consoles) = _vm_create(30, 0, False)1023 try:1024 init_guest(vm, consoles)1025 except error.TestFail, ints:1026"Count of console ports: 30")1027 raise ints1028 clean_reload_vm(vm, consoles, expected=True)1029 def tmax_mix_serial_conosle_port(vm, consoles):1030 """1031 Test maximim count of ports in guest machine.1032 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1033 @param consoles: Consoles which should be close before rmmod.1034 """1035 logging.debug("Count of ports (serial+console): 30")1036 vm[0].destroy(gracefully = False)1037 (vm, consoles) = _vm_create(15, 15, False)1038 try:1039 init_guest(vm, consoles)1040 except error.TestFail, ints:1041"Count of ports (serial+console): 30")1042 raise ints1043 clean_reload_vm(vm, consoles, expected=True)1044 def tshutdown(vm, consoles):1045 """1046 Try to gently shutdown the machine. Virtio_console shouldn't block this.1047 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1048 @param consoles: Consoles which should be close before rmmod.1049 """1050 ports = []1051 for console in consoles[0]:1052 ports.append(console)1053 for console in consoles[1]:1054 ports.append(console)1055 for port in ports:1056 # If more than one, send data on the other ports1058 for port in ports[1:]:1059 on_guest("virt.close('%s')" % (, vm, 2)1060 on_guest("'%s')" % (, vm, 2)1061 try:1062 os.system("dd if=/dev/random of='%s' bs=4096 >/dev/null 2>&1 &"1063 % port.path)1064 except:1065 pass1066 # Just start sending, it won't finish anyway...1067 _on_guest("virt.send('%s', 1024**3, True, is_static=True)"1068 % ports[0].name, vm, 1)1069 # Let the computer transfer some bytes :-)1070 time.sleep(2)1071 # Power off the computer1072 vm[0].destroy(gracefully=True)1073 clean_reload_vm(vm, consoles, expected=True)1074 def __tmigrate(vm, consoles, parms, offline=True):1075 """1076 An actual migration test. It creates loopback on guest from first port1077 to all remaining ports. Than it sends and validates the data.1078 During this it tries to migrate the vm n-times.1079 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1080 @param consoles: Field of virtio ports with the minimum of 2 items.1081 @param parms: [media, no_migration, send-, recv-, loopback-buffer_len]1082 """1083 # PREPARE1084 send_pt = consoles[parms[0]][0]1085 recv_pts = consoles[parms[0]][1:]1086 # TODO BUG: sendlen = max allowed data to be lost per one migration1087 # TODO BUG: using SMP the data loss is upto 4 buffers1088 # 2048 = char. dev. socket size, parms[2] = host->guest send buffer size1089 sendlen = 2*2*max(2048, parms[2])1090 if not offline: # TODO BUG: online migration causes more loses1091 # TODO: Online migration lose n*buffer. n depends on the console1092 # troughput. FIX or analyse it's cause.1093 sendlen = 1000 * sendlen1094 for p in recv_pts:1095 if not p.is_open:1096 if not send_pt.is_open:1098 threads = []1100 queues = []1101 verified = []1102 for i in range(0, len(recv_pts)):1103 queues.append(deque())1104 verified.append(0)1105 tmp = "'%s'" % recv_pts[0].name1106 for recv_pt in recv_pts[1:]:1107 tmp += ", '%s'" % ( on_guest("virt.loopback(['%s'], [%s], %d, virt.LOOP_POLL)"1109 % (, tmp, parms[4]), vm, 10)1110 exit_event = threading.Event()1111 # TEST1112 thread = ThSendCheck(send_pt, exit_event, queues,1113 parms[2])1114 thread.start()1115 threads.append(thread)1116 for i in range(len(recv_pts)):1117 thread = ThRecvCheck(recv_pts[i], queues[i], exit_event,1118 parms[3], sendlen=sendlen)1119 thread.start()1120 threads.append(thread)1121 i=01122 while i < 6:1123 tmp = "%d data sent; " % threads[0].idx1124 for thread in threads[1:]:1125 tmp += "%d, " % thread.idx1126 logging.debug("test_loopback: %s data received and verified",1127 tmp[:-2])1128 i+=11129 time.sleep(2)1130 for j in range(parms[1]):1131 vm[0] = virt_test_utils.migrate(vm[0], env, 3600, "exec", 0,1132 offline)1133 if not vm[1]:1134 raise error.TestFail("Could not log into guest after migration")1135 vm[1] = virt_test_utils.wait_for_login(vm[0], 0,1136 float(params.get("boot_timeout", 100)),1137 0, 2)1138 # OS is sometime a bit dizzy. DL=301139 _init_guest(vm, 30)1140 i=01141 while i < 6:1142 tmp = "%d data sent; " % threads[0].idx1143 for thread in threads[1:]:1144 tmp += "%d, " % thread.idx1145 logging.debug("test_loopback: %s data received and verified",1146 tmp[:-2])1147 i+=11148 time.sleep(2)1149 if not threads[0].is_alive():1150 if exit_event.isSet():1151 raise error.TestFail("Exit event emited, check the log for"1152 "send/recv thread failure.")1153 else:1154 raise error.TestFail("Send thread died unexpectedly in "1155 "migration %d", (j+1))1156 for i in range(0, len(recv_pts)):1157 if not threads[i+1].is_alive():1158 raise error.TestFail("Recv thread %d died unexpectedly in "1159 "migration %d", i, (j+1))1160 if verified[i] == threads[i+1].idx:1161 raise error.TestFail("No new data in %d console were "1162 "transfered after migration %d"1163 , i, (j+1))1164 verified[i] = threads[i+1].idx1165"%d out of %d migration(s) passed" % ((j+1), parms[1]))1166 # TODO detect recv-thread failure and throw out whole test1167 # FINISH1168 exit_event.set()1169 # Send thread might fail to exit when the guest stucks1170 i = 301171 while threads[0].is_alive():1172 if i <= 0:1173 raise error.TestFail("Send thread did not finish")1174 time.sleep(1)1175 i -= 11176 tmp = "%d data sent; " % threads[0].idx1177 for thread in threads[1:]:1178 thread.join()1179 tmp += "%d, " % thread.idx1180"test_loopback: %s data received and verified during %d "1181 "migrations", tmp[:-2], parms[1])1182 # CLEANUP1183 _guest_exit_threads(vm, [send_pt], recv_pts)1184 del exit_event1185 del threads[:]1186 def _tmigrate(vm, consoles, parms, offline):1187 """1188 Wrapper which parses the params for __migrate test.1189 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1190 @param consoles: Field of virtio ports with the minimum of 2 items.1191 @param parms: test parameters, multiple recievers allowed.1192 '[{serialport,console}]:$no_migrations:send_buf_len:recv_buf_len:1193 loopback_buf_len;...'1194 """1195 for param in parms.split(';'):1196 if not param:1197 continue1198 if offline:1199"test_migrate_offline: params: %s", param)1200 else:1201"test_migrate_online: params: %s", param)1202 param = param.split(':')1203 media = 11204 if param[0].isalpha():1205 if param[0] == "console":1206 param[0] = 01207 else:1208 param[0] = 11209 else:1210 param = [0] + param1211 for i in range(1,5):1212 if not param[i].isdigit():1213 param[i] = 11214 else:1215 param[i] = int(param[i])1216 __tmigrate(vm, consoles, param, offline=offline)1217 def tmigrate_offline(vm, consoles, parms):1218 """1219 Tests whether the virtio-{console,port} are able to survive the offline1220 migration.1221 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1222 @param consoles: Field of virtio ports with the minimum of 2 items.1223 @param parms: test parameters, multiple recievers allowed.1224 '[{serialport,console}]:$no_migrations:send_buf_len:recv_buf_len:1225 loopback_buf_len;...'1226 """1227 _tmigrate(vm, consoles, parms, offline=True)1228 def tmigrate_online(vm, consoles, parms):1229 """1230 Tests whether the virtio-{console,port} are able to survive the online1231 migration.1232 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1233 @param consoles: Field of virtio ports with the minimum of 2 items.1234 @param parms: test parameters, multiple recievers allowed.1235 '[{serialport,console}]:$no_migrations:send_buf_len:recv_buf_len:1236 loopback_buf_len;...'1237 """1238 _tmigrate(vm, consoles, parms, offline=False)1239 def _virtio_dev_create(vm, ports_name, pciid, id, console="no"):1240 """1241 Add virtio serialport device.1242 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1243 @param ports_name: Structure of ports.1244 @param pciid: Id of virtio-serial-pci device.1245 @param id: Id of port.1246 @param console: if "yes" inicialize console.1247 """1248 port = "serialport-"1249 port_type = "virtserialport"1250 if console == "yes":1251 port = "console-"1252 port_type = "virtconsole"1253 port += "%d%d" % (pciid, id)1254 ret = vm[0].monitors[0].cmd("device_add %s,"1255 "bus=virtio-serial-pci%d.0,"1256 "id=%s,"1257 "name=%s"1258 % (port_type, pciid, port, port))1259 ports_name.append([ port, console])1260 if ret != "":1261 logging.error(ret)1262 def _virtio_dev_del(vm, ports_name, pciid, id):1263 """1264 Del virtio serialport device.1265 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1266 @param ports_name: Structure of ports.1267 @param pciid: Id of virtio-serial-pci device.1268 @param id: Id of port.1269 """1270 port = filter(lambda x: x[0].endswith("-%d%d" % (pciid, id)),1271 ports_name)1272 ret = vm[0].monitors[0].cmd("device_del %s"1273 % (port[0][0]))1274 ports_name.remove(port[0])1275 if ret != "":1276 logging.error(ret)1277 def thotplug(vm, consoles, console="no", timeout=1):1278 """1279 Try hotplug function of virtio-consoles ports.1280 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1281 @param consoles: Consoles.1282 @param console: If "yes" inicialize console.1283 @param timeout: Timeout between hotplug operations.1284 """1285"Timeout between hotplug operations t=%fs" % timeout)1286 _reset_vm(vm, consoles, 1, 1)1287 ports_name = []1288 ports_name.append(['serialport-1','no'])1289 ports_name.append(['console-0','yes'])1290"Test correct initialization of hotplug ports")1291 for id in range(1,5): #count of pci device1292 ret = vm[0].monitors[0].cmd("device_add virtio-serial-pci,"1293 "id=virtio-serial-pci%d" % (id))1294 if ret != "":1295 logging.error(ret)1296 for i in range(id*5+5): #max port 301297 _virtio_dev_create(vm, ports_name, id, i, console)1298 time.sleep(timeout)1299 # Test correct initialization of hotplug ports1300 time.sleep(10) # Timeout for port initialization1301 _init_guest(vm, 10)1302 on_guest('virt.init(%s)' % (ports_name), vm, 10)1303"Delete ports when ports are used")1304 # Delete ports when ports are used.1305 if not consoles[0][0].is_open:1306 consoles[0][0].open()1307 if not consoles[1][0].is_open:1308 consoles[1][0].open()1309 on_guest("virt.loopback(['%s'], ['%s'], 1024,"1310 "virt.LOOP_POLL)" % (consoles[0][0].name,1311 consoles[1][0].name), vm, 10)1312 exit_event = threading.Event()1313 send = ThSend(consoles[0][0].sock, "Data", exit_event, quiet = True)1314 recv = ThRecv(consoles[1][0].sock, exit_event, quiet = True)1315 send.start()1316 time.sleep(2)1317 recv.start()1318 # Try to delete ports under load1319 ret = vm[0].monitors[0].cmd("device_del serialport-1")1320 ret += vm[0].monitors[0].cmd("device_del console-0")1321 ports_name.remove(['serialport-1','no'])1322 ports_name.remove(['console-0','yes'])1323 if ret != "":1324 logging.error(ret)1325 exit_event.set()1326 send.join()1327 recv.join()1328 on_guest("virt.exit_threads()", vm, 10)1329 on_guest('guest_exit()', vm, 10)1330"Trying to add maximum count of ports to one pci device")1331 # Try to add ports1332 for i in range(30): # max port 301333 _virtio_dev_create(vm, ports_name, 0, i, console)1334 time.sleep(timeout)1335 _init_guest(vm, 10)1336 time.sleep(10)1337 on_guest('virt.init(%s)' % (ports_name), vm, 20)1338 on_guest('guest_exit()', vm, 10)1339"Trying delete and add again part of ports")1340 # Try to delete ports1341 for i in range(25): # max port 301342 _virtio_dev_del(vm, ports_name, 0, i)1343 time.sleep(timeout)1344 _init_guest(vm, 10)1345 on_guest('virt.init(%s)' % (ports_name), vm, 10)1346 on_guest('guest_exit()', vm, 10)1347 # Try to add ports1348 for i in range(5): # max port 301349 _virtio_dev_create(vm, ports_name, 0, i, console)1350 time.sleep(timeout)1351 _init_guest(vm, 10)1352 on_guest('virt.init(%s)' % (ports_name), vm, 10)1353 on_guest('guest_exit()', vm, 10)1354"Trying to add and delete one port 100 times")1355 # Try 100 times add and delete one port.1356 for i in range(100):1357 _virtio_dev_del(vm, ports_name, 0, 0)1358 time.sleep(timeout)1359 _virtio_dev_create(vm, ports_name, 0, 0, console)1360 time.sleep(timeout)1361 _init_guest(vm, 10)1362 on_guest('virt.init(%s)' % (ports_name), vm, 10)1363 on_guest('guest_exit()', vm, 10)1364 def thotplug_no_timeout(vm, consoles, console="no"):1365 """1366 Start hotplug test without any timeout.1367 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1368 @param consoles: Consoles which should be close before rmmod.1369 @param console: If "yes" inicialize console.1370 """1371 thotplug(vm, consoles, console, 0)1372 def thotplug_virtio_pci(vm, consoles):1373 """1374 Test hotplug of virtio-serial-pci.1375 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1376 @param consoles: Consoles which should be close before rmmod.1377 """1378 vm[0].destroy(gracefully = False)1379 (vm, consoles) = _vm_create(1, 1, False)1380 id = 11381 ret = vm[0].monitors[0].cmd("device_add virtio-serial-pci,"1382 "id=virtio-serial-pci%d" % (id))1383 time.sleep(10)1384 ret += vm[0].monitors[0].cmd("device_del virtio-serial-pci%d" % (id))1385 time.sleep(10)1386 ret += vm[0].monitors[0].cmd("device_add virtio-serial-pci,"1387 "id=virtio-serial-pci%d" % (id))1388 if ret != "":1389 logging.error(ret)1390 def tloopback(vm, consoles, params):1391 """1392 Virtio console loopback subtest.1393 Creates loopback on the vm machine between send_pt and recv_pts1394 ports and sends length amount of data through this connection.1395 It validates the correctness of the data sent.1396 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1397 @param consoles: Field of virtio ports with the minimum of 2 items.1398 @param params: test parameters, multiple recievers allowed.1399 '$source_console_type@buffer_length:1400 $destination_console_type1@$buffer_length:...:1401 $loopback_buffer_length;...'1402 """1403 # PREPARE1404 for param in params.split(';'):1405 if not param:1406 continue1407"test_loopback: params: %s", param)1408 param = param.split(':')1409 idx_serialport = 01410 idx_console = 01411 buf_len = []1412 if (param[0].startswith('console')):1413 send_pt = consoles[0][idx_console]1414 idx_console += 11415 else:1416 send_pt = consoles[1][idx_serialport]1417 idx_serialport += 11418 if (len(param[0].split('@')) == 2):1419 buf_len.append(int(param[0].split('@')[1]))1420 else:1421 buf_len.append(1024)1422 recv_pts = []1423 for parm in param[1:]:1424 if (parm.isdigit()):1425 buf_len.append(int(parm))1426 break # buf_len is the last portion of param1427 if (parm.startswith('console')):1428 recv_pts.append(consoles[0][idx_console])1429 idx_console += 11430 else:1431 recv_pts.append(consoles[1][idx_serialport])1432 idx_serialport += 11433 if (len(parm[0].split('@')) == 2):1434 buf_len.append(int(parm[0].split('@')[1]))1435 else:1436 buf_len.append(1024)1437 # There must be sum(idx_*) consoles + last item as loopback buf_len1438 if len(buf_len) == (idx_console + idx_serialport):1439 buf_len.append(1024)1440 for p in recv_pts:1441 if not p.is_open:1442 if not send_pt.is_open:1444 if len(recv_pts) == 0:1446 raise error.TestFail("test_loopback: incorrect recv consoles"1447 "definition")1448 threads = []1449 queues = []1450 for i in range(0, len(recv_pts)):1451 queues.append(deque())1452 tmp = "'%s'" % recv_pts[0].name1453 for recv_pt in recv_pts[1:]:1454 tmp += ", '%s'" % ( on_guest("virt.loopback(['%s'], [%s], %d, virt.LOOP_POLL)"1456 % (, tmp, buf_len[-1]), vm, 10)1457 exit_event = threading.Event()1458 # TEST1459 thread = ThSendCheck(send_pt, exit_event, queues,1460 buf_len[0])1461 thread.start()1462 threads.append(thread)1463 for i in range(len(recv_pts)):1464 thread = ThRecvCheck(recv_pts[i], queues[i], exit_event,1465 buf_len[i + 1])1466 thread.start()1467 threads.append(thread)1468 time.sleep(60)1469 exit_event.set()1470 threads[0].join()1471 tmp = "%d data sent; " % threads[0].idx1472 for thread in threads[1:]:1473 thread.join()1474 tmp += "%d, " % thread.idx1475"test_loopback: %s data received and verified",1476 tmp[:-2])1477 # Read-out all remaining data1478 for recv_pt in recv_pts:1479 while[recv_pt.sock], [], [], 0.1)[0]:1480 recv_pt.sock.recv(1024)1481 _guest_exit_threads(vm, [send_pt], recv_pts)1482 del exit_event1483 del threads[:]1484 def tperf(vm, consoles, params):1485 """1486 Tests performance of the virtio_console tunel. First it sends the data1487 from host to guest and than back. It provides informations about1488 computer utilisation and statistic informations about the troughput.1489 @param vm: Target virtual machine [vm, session, tmp_dir, ser_session].1490 @param consoles: Field of virtio ports with the minimum of 2 items.1491 @param params: test parameters:1492 '$console_type@$buffer_length:$test_duration;...'1493 """1494 for param in params.split(';'):1495 if not param:1496 continue1497"test_perf: params: %s", param)1498 param = param.split(':')1499 duration = 60.01500 if len(param) > 1:1501 try:1502 duration = float(param[1])1503 except:1504 pass1505 param = param[0].split('@')1506 if len(param) > 1 and param[1].isdigit():1507 buf_len = int(param[1])1508 else:1509 buf_len = 10241510 param = (param[0] == 'serialport')1511 port = consoles[param][0]1512 if not port.is_open:1513 data = ""1515 for i in range(buf_len):1516 data += "%c" % random.randrange(255)1517 exit_event = threading.Event()1518 time_slice = float(duration) / 1001519 # HOST -> GUEST1520 on_guest('virt.loopback(["%s"], [], %d, virt.LOOP_NONE)' %1521 (, buf_len), vm, 10)1522 thread = ThSend(port.sock, data, exit_event)1523 stats = array.array('f', [])1524 loads = utils.SystemLoad([(os.getpid(), 'autotest'),1525 (vm[0].get_pid(), 'VM'), 0])1526 loads.start()1527 _time = time.time()1528 thread.start()1529 for i in range(100):1530 stats.append(thread.idx)1531 time.sleep(time_slice)1532 _time = time.time() - _time - duration1533"\n" + loads.get_cpu_status_string()[:-1])1534"\n" + loads.get_mem_status_string()[:-1])1535 exit_event.set()1536 thread.join()1537 # Let the guest read-out all the remaining data1538 while not _on_guest("virt.poll('%s', %s)" %1539 (, select.POLLIN), vm, 10)[0]:1540 time.sleep(1)1541 _guest_exit_threads(vm, [port], [])1542 if (_time > time_slice):1543 logging.error(1544 "Test ran %fs longer which is more than one time slice", _time)1545 else:1546 logging.debug("Test ran %fs longer", _time)1547 stats = process_stats(stats[1:], time_slice * 1048576)1548 logging.debug("Stats = %s", stats)1549"Host -> Guest [MB/s] (min/med/max) = %.3f/%.3f/%.3f",1550 stats[0], stats[len(stats) / 2], stats[-1])1551 del thread1552 # GUEST -> HOST1553 exit_event.clear()1554 stats = array.array('f', [])1555 on_guest("virt.send_loop_init('%s', %d)" % (, buf_len),1556 vm, 30)1557 thread = ThRecv(port.sock, exit_event, buf_len)1558 thread.start()1559 loads.start()1560 on_guest("virt.send_loop()", vm, 10)1561 _time = time.time()1562 for i in range(100):1563 stats.append(thread.idx)1564 time.sleep(time_slice)1565 _time = time.time() - _time - duration1566"\n" + loads.get_cpu_status_string()[:-1])1567"\n" + loads.get_mem_status_string()[:-1])1568 on_guest("virt.exit_threads()", vm, 10)1569 exit_event.set()1570 thread.join()1571 if (_time > time_slice): # Deviation is higher than 1 time_slice1572 logging.error(1573 "Test ran %fs longer which is more than one time slice", _time)1574 else:1575 logging.debug("Test ran %fs longer", _time)1576 stats = process_stats(stats[1:], time_slice * 1048576)1577 logging.debug("Stats = %s", stats)1578"Guest -> Host [MB/s] (min/med/max) = %.3f/%.3f/%.3f",1579 stats[0], stats[len(stats) / 2], stats[-1])1580 del thread...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?