def test_sync_verify_speed(self): dc = DataClient(host, port, storage_sender, gui_data_sender, active_channels) dc.start_sync_verification_thread() dc.start_parser_thread() dc.synchronized = True input_length = 10000 chunk_size = 20 with dc.expected_readings_verified_lock: dc.expected_readings_verified = input_length / chunk_size normal_bytearray_chunk = bytearray(0) for i in range(chunk_size): normal_bytearray_chunk += normal_bytearray start = time.time() for i in range(input_length / chunk_size): dc.fast_path_sender.send(normal_bytearray_chunk) with dc.frame_to_be_verified_cond: dc.frame_to_be_verified_cond.notify() with dc.sync_filter_done_cond: dc.sync_filter_done_cond.wait() elapsed = time.time() - start speed = 1 / (elapsed / input_length) print '\n\nSync Verification Stage: effective frequency over %d samples is %d Hz\n' % ( input_length, speed)
def test_recv_and_verify_speed(self): dc = DataClient(host, port, storage_sender, gui_data_sender, active_channels) server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_sock.bind(('localhost', 10002)) server_sock.listen(1) print 'listening on %s:%d' % ('localhost', 10002) dc.connect_data_port() conn, addr = server_sock.accept() print 'accepted connection from %s:%d' % (addr[0], addr[1]) input_length = 1000 with dc.expected_readings_verified_lock: dc.expected_readings_verified = input_length - 2 start = time.time() for i in range(input_length): for j in range(len(normal_reading)): conn.send(np.uint16(normal_reading[j])) with dc.sync_filter_done_cond: dc.sync_filter_done_cond.wait() elapsed = time.time() - start speed = 1 / (elapsed / input_length) print '\n\nReceive and Verify Stages: effective frequency over %d samples is %d Hz\n' % ( input_length, speed) dc.close_data_port() conn.close() server_sock.close()
def test_receive_and_sync_verification(self): dc = DataClient(host, port, storage_sender, gui_data_sender, active_channels) server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_sock.bind(('localhost', 10002)) server_sock.listen(1) print 'listening on %s:%d' % ('localhost', 10002) dc.connect_data_port() conn, addr = server_sock.accept() print 'accepted connection from %s:%d' % (addr[0], addr[1]) input_length = 4 bytes_sent = 0 with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = 99999999 with dc.expected_readings_verified_lock: dc.expected_readings_verified = 99999999 for i in range(input_length): for j in range(len(normal_reading)): bytes_sent += conn.send(np.uint16(normal_reading[j])) with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = bytes_sent print 'Test: finished sending part 1, bytes_sent = %d' % bytes_sent # first two readings will get dropped by sync. recovery filter with dc.expected_readings_verified_lock: dc.expected_readings_verified = input_length - 2 # with dc.receiver_done_cond: # dc.receiver_done_cond.wait() # print 'Receiver finished task 1' with dc.sync_filter_done_cond: dc.sync_filter_done_cond.wait() print 'Sync filter finished task 1' assert dc.synchronized print 'Part 1 passed, synchronization achieved' with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = 99999999 for j in range(len(corrupt_reading)): bytes_sent += conn.send(np.uint16(corrupt_reading[j])) print 'Test: finished sending part 2, bytes_sent = %d' % bytes_sent with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = bytes_sent with dc.receiver_done_cond: dc.receiver_done_cond.wait() print 'Receiver finished task 2' assert not dc.synchronized print 'Part 2 passed, synchronization lost as expected' with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = 99999999 with dc.expected_readings_verified_lock: dc.expected_readings_verified = 99999999 for i in range(input_length): for j in range(len(normal_reading)): bytes_sent += conn.send(np.uint16(normal_reading[j])) print 'Test: finished sending part 3, bytes_sent = %d' % bytes_sent with dc.expected_bytes_sent_lock: dc.expected_bytes_sent = bytes_sent with dc.expected_readings_verified_lock: dc.expected_readings_verified = (input_length - 2) * 2 with dc.sync_filter_done_cond: dc.sync_filter_done_cond.wait() print 'Sync filter finished task 3' assert dc.synchronized dc.close_data_port() conn.close() server_sock.close()