def action_disconnect(args, test_step, expected, params_list): src = choose_src(params_list, 0) src_stream = choose_src_stream(params_list, 1) dst = choose_dst(params_list, 2) dst_stream = choose_dst_stream(params_list, 3) controller_disconnect(args, test_step, expected, src, dst_stream, dst, dst_stream) (talker_expect, listener_expect, controller_expect) = get_expected( args, test_step, src, src_stream, dst, dst_stream, 'disconnect') # Find the path between the src and dst and check whether there are any nodes between them forward_disable = [] nodes = endpoints.get_path_endpoints(graph.find_path(state.get_current(), src, dst)) for node in get_dual_port_nodes(nodes): if graph.node_will_see_stream_disable(state.get_current(), src, src_stream, dst, dst_stream, node): forward_disable += sequences.expected_seq('stream_forward_disable')(test_step, args.user, endpoints.get(node), endpoints.get(src)) forward_disable += sequences.expected_seq('port_shaper_disconnect')(test_step, endpoints.get(node), src, src_stream, dst, dst_stream) # If there are any nodes in the chain then the forward disabling is expected before the # audio will be seen to be lost if forward_disable and listener_expect: listener_expect = [Sequence([AllOf(forward_disable)] + listener_expect)] elif forward_disable: listener_expect = forward_disable elif listener_expect: listener_expect = listener_expect else: listener_expect = [] # Expect not to see any disables from other nodes not_forward_disable = [] temp_nodes = set(endpoints.get_all().keys()) - set(nodes) for node in get_dual_port_nodes(temp_nodes): not_forward_disable += sequences.expected_seq('stream_forward_disable')(test_step, args.user, endpoints.get(node), endpoints.get(src)) if not_forward_disable: if test_step.checkpoint is None: not_forward_disable = [NoneOf(not_forward_disable)] else: not_forward_disable = [] for node in get_dual_port_nodes(temp_nodes): not_forward_disable += sequences.expected_seq('port_shaper_disconnect')(test_step, endpoints.get(node), src, src_stream, dst, dst_stream) if test_step.checkpoint: final_port_shaper_states = sequences.get_and_clear_final_port_shaper_states() else: final_port_shaper_states = [] if test_step.do_checks and (talker_expect or listener_expect or controller_expect or not_forward_disable or final_port_shaper_states): expected += [AllOf(talker_expect + listener_expect + controller_expect + not_forward_disable + final_port_shaper_states)] yield args.master.expect(None)
def action_check_connections(args, test_step, expected, params_list): """ Check that the current state the controller reads from the endpoints matches the state the test framework expects. """ checks = [] # Expect all connections to be restored for c,n in state.get_current().active_connections.iteritems(): if n: if args.controller_type == 'python': checks += [Expected(args.controller_id, "0x%s\[%d\] -> 0x%s\[%d\]" % ( endpoints.guid_in_ascii(args.user, endpoints.get(c.talker.src)), c.talker.src_stream, endpoints.guid_in_ascii(args.user, endpoints.get(c.listener.dst)), c.listener.dst_stream), 10)] else: checks += [Expected(args.controller_id, "0x%s\[%d\] -> 0x%s\[%d\]" % ( endpoints.guid_in_ascii(args.user, endpoints.get(c.talker.src)).zfill(16), c.talker.src_stream, endpoints.guid_in_ascii(args.user, endpoints.get(c.listener.dst)).zfill(16), c.listener.dst_stream), 10)] print_title("Command: show_connections") args.master.sendLine(args.controller_id, "show connections") if test_step.do_checks: if checks: expected += [AllOf(checks)] elif test_step.checkpoint is None: expected += [NoneOf([Expected(args.controller_id, "->", 5)])] yield args.master.expect(None)
def talker_existing_connect_seq(test_step, user, src, src_stream, dst, dst_stream): stream_id = endpoints.stream_from_guid(endpoints.guid_in_ascii(user, endpoints.get(src))) listener_mac = endpoints.mac_in_ascii(user, endpoints.get(dst)) talker_connection = [ Sequence([Expected(src, "CONNECTING Talker stream #%d \(%s\) -> Listener %s" % (src_stream, stream_id, listener_mac), 10)]) ] return talker_connection
def controller_connect(args, test_step, expected, src, src_stream, dst, dst_stream): talker_ep = endpoints.get(src) listener_ep = endpoints.get(dst) state.get_next().connect(src, src_stream, dst, dst_stream) check_set_clock_masters(args, test_step, expected) args.master.sendLine(args.controller_id, "connect 0x%s %d 0x%s %d" % ( endpoints.guid_in_ascii(args.user, talker_ep), src_stream, endpoints.guid_in_ascii(args.user, listener_ep), dst_stream))
def controller_disconnect(args, test_step, expected, src, src_stream, dst, dst_stream): talker_ep = endpoints.get(src) listener_ep = endpoints.get(dst) state.get_next().disconnect(src, src_stream, dst, dst_stream) check_clear_clock_masters(args, test_step, expected) print_title("Command: disconnect %s %d %s %d" % (src, src_stream, dst, dst_stream)) args.master.sendLine(args.controller_id, "disconnect 0x%s %d 0x%s %d" % ( endpoints.guid_in_ascii(args.user, talker_ep), src_stream, endpoints.guid_in_ascii(args.user, listener_ep), dst_stream))
def talker_new_connect_seq(test_step, user, src, src_stream, dst, dst_stream): """ Only on the first time the talker is turned on must the 'ready' be seen. """ stream_id = endpoints.stream_from_guid(endpoints.guid_in_ascii(user, endpoints.get(src))) listener_mac = endpoints.mac_in_ascii(user, endpoints.get(dst)) seq = [Expected(src, "CONNECTING Talker stream #%d \(%s\) -> Listener %s" % (src_stream, stream_id, listener_mac), 10)] if not state.get_current().get_talker_on_count(src): seq += [Expected(src, "Talker stream #%d ready" % src_stream, 10)] seq += [Expected(src, "Talker stream #%d on" % src_stream, 10)] talker_connection = [Sequence(seq)] return talker_connection
def controller_enumerate(args, avb_ep): entity_id = endpoints.get(avb_ep) print_title("Command: enumerate %s" % avb_ep) if args.controller_type == 'python': args.master.sendLine(args.controller_id, "enumerate 0x%s" % ( endpoints.guid_in_ascii(args.user, entity_id))) else: select_endpoint(args, entity_id) descriptors = endpoints.get(avb_ep)['descriptors'] for dtor in sorted(descriptors.keys()): index = 0 command = "view descriptor %s %d" % (re.sub('\d*_', '', dtor, 1), index) args.master.sendLine(args.controller_id, command.encode('ascii', 'ignore'))
def analyzer_qav_seq(test_step, src, dst, action, user): """ Get the expected sequence for any QAV analyzers active. """ analyzer_expect = [] for analyzer_name,analyzer in analyzers.get_all().iteritems(): if analyzer['type'] != 'qav': continue # If the analyzer is a QAV analyzer then it will detect the stream through # the packets being forwarded through it if analyzer_name in graph.find_path(state.get_current(), src, dst): guid_string = endpoints.guid_in_ascii(user, endpoints.get(src)) stream_string = endpoints.stream_from_guid(guid_string) if action == 'connect': action_string = "Adding" completionFn = hook_register_error else: action_string = "Removing" completionFn = hook_unregister_error analyzer_expect += [Expected(analyzer_name, "%s stream 0x%s" % (action_string, stream_string), timeoutTime=10, completionFn=completionFn, completionArgs=(analyzer_name, ['ERROR']))] return analyzer_expect
def check_set_clock_masters(args, test_step, expected): for loop in graph.get_loops(state.get_next()): loop_master = loop[0] for ep_name in loop: # Look at the next state in case the node has just been set clock master if state.get_next().is_clock_source_master(ep_name): loop_master = ep_name break if not state.get_next().is_clock_source_master(loop_master): ep = endpoints.get(loop_master) print_title("Command: set_clock_source_master %s" % loop_master) if args.controller_type == 'python': args.master.sendLine(args.controller_id, "set_clock_source_master 0x%s" % ( endpoints.guid_in_ascii(args.user, ep))) else: select_endpoint(args, ep) args.master.sendLine(args.controller_id, "set clock_source 0 0 1") state.get_next().set_clock_source_master(ep['name']) if test_step.do_checks: controller_expect = sequences.expected_seq('controller_success_set_clock_source')(args, test_step) ep_expect = [Expected(loop_master, "Setting clock source: LOCAL_CLOCK", 5)] if controller_expect or ep_expect: expected += [AllOf(controller_expect + ep_expect)]
def data_bytes_per_packet(talker): """ Returns how many bytes per packet there will be. """ talker_ep = endpoints.get(talker.src) samples_per_packet = (talker_ep['sample_rate'] + (PACKETS_PER_SECOND-1)) / PACKETS_PER_SECOND num_channels = talker_ep['out_channels'] return samples_per_packet * 4 * num_channels
def action_ping(args, test_step, expected, params_list): """ Ping a node with and check that it responds accordingly. This is used to test connectivity. """ ep_name = choose_src(params_list, 0) ep = endpoints.get(ep_name) node_expect = [Expected(ep_name, "IDENTIFY Ping", 5)] if args.controller_type == 'python': controller_expect = [Expected(args.controller_id, "Success", 5)] print_title("Command: identify %s on" % ep_name) args.master.sendLine(args.controller_id, "identify 0x%s on" % endpoints.guid_in_ascii(args.user, ep)) print_title("Command: identify %s off" % ep_name) args.master.sendLine(args.controller_id, "identify 0x%s off" % endpoints.guid_in_ascii(args.user, ep)) else: controller_expect = [Expected(args.controller_id, "NOTIFICATION.*SET_CONTROL.*SUCCESS", 10, consumeOnMatch=True)] print_title("Command: identify on %s" % ep_name) args.master.sendLine(args.controller_id, "identify on 0x%s" % endpoints.guid_in_ascii(args.user, ep)) print_title("Command: identify off %s" % ep_name) args.master.sendLine(args.controller_id, "identify off 0x%s" % endpoints.guid_in_ascii(args.user, ep)) if test_step.do_checks and (node_expect or controller_expect): expected += [AllOf(node_expect + controller_expect)] yield args.master.expect(None)
def talker_new_connect_seq(test_step, user, src, src_stream, dst, dst_stream): """ Only on the first time the talker is turned on must the 'ready' be seen. """ stream_id = endpoints.stream_from_guid(endpoints.guid_in_ascii(user, endpoints.get(src))) listener_mac = endpoints.mac_in_ascii(user, endpoints.get(dst)) seq = [Expected(src, "CONNECTING Talker stream #%d \(%s\) -> Listener %s" % (src_stream, stream_id, listener_mac), 10)] if not state.get_current().get_talker_on_count(src): seq += [Expected(src, "Talker stream #%d ready" % src_stream, 10)] seq += [Expected(src, "Talker stream #%d on" % src_stream, 10)] # If in a sequence of commands then the order cannot be guaranteed - so only # expect a Sequence when not checkpointing if test_step.checkpoint is None: talker_connection = [Sequence(seq)] else: talker_connection = [AllOf(seq)] return talker_connection
def analyzer_listener_connect_seq(test_step, src, src_stream, dst, dst_stream): listener_ep = endpoints.get(dst) analyzer = listener_ep['analyzer'] analyzer_name = analyzer['name'] analyzer_offset = listener_ep['analyzer_offset'] + analyzer['base'] # Expect both of the stereo channels to lose signal signal_detect = [ Sequence([Expected(analyzer_name, "Channel %d: Signal detected" % (i + analyzer_offset), 10), Expected(analyzer_name, "Channel %d: Frequency %d" % (i + analyzer_offset, analyzers.siggen_frequency(endpoints.get(src), i)), timeoutTime=5, completionFn=hook_register_error, completionArgs=(analyzer_name, [ "Channel %d: %s" % (i + analyzer_offset, GLITCH_DETECTED_PATTERN), "Channel %d: %s" % (i + analyzer_offset, LOST_SIGNAL_PATTERN)]))]) for i in range(0, 2) ] return signal_detect
def controller_enumerate_seq(args, test_step, endpoint_name): """ Build an enumerated sequence for an entity by reading from a topology file """ expected_seq = [] descriptors = endpoints.get(endpoint_name)['descriptors'] if args.controller_type == 'python': # The python controller reads the descriptors each time. The C controller has # them cached and so can always return the values. visible_endpoints = graph.get_endpoints_connected_to(state.get_current(), args.controller_id) if endpoint_name not in visible_endpoints: return [Expected(args.controller_id, "No descriptors found", 10, consumeOnMatch=True)] for dtor in sorted(descriptors.keys()): # Note that the .* is required because the STREAM_INPUT/STREAM_OUTPUT are mapped to the same descriptor temp_string = "AVB 1722\.1.*%s" % re.sub('\d*_', '', dtor, 1) expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) for dtor_name in descriptors[str(dtor)].keys(): temp_string = "object_name\s*=\s*\'%s\'" % dtor_name expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) for element in descriptors[str(dtor)][dtor_name]: element_type = element.get('type', 'none') if element_type == 'hex': temp_string = "%s\s*=\s*0x%x" % (element['item'], element['value']) elif element_type == 'state': value = eval('state.get_current().get_%s' % element['item'])(endpoint_name) temp_string = "%s\s*=\s*%s" % (element['item'], value) else: temp_string = "%s\s*=\s*%s" % (element['item'], element['value']) expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) else: for dtor in sorted(descriptors.keys()): temp_string = "descriptor_type: %s" % re.sub('\d*_', '', dtor, 1) expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) for dtor_name in descriptors[str(dtor)].keys(): temp_string = "object_name\s*=\s*%s" % dtor_name expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) for element in descriptors[str(dtor)][dtor_name]: element_type = element.get('type', 'none') if element_type == 'flag': temp_string = "%s\s*=\s*1" % element['value'].lower() elif element_type == 'state': value = eval('state.get_current().get_%s' % element['item'])(endpoint_name) temp_string = "%s\s*=\s*%s" % (element['item'], value) else: temp_string = "%s\s*=\s*%s" % (element['item'], element['value']) expected_seq.append(Expected(args.controller_id, temp_string, 10, consumeOnMatch=True)) return [Sequence(expected_seq)]
def listener_connect_seq(test_step, dst, dst_stream, analyzer_expect): ep = endpoints.get(dst) listener_connection = [ Expected(dst, "CONNECTING Listener sink #%d" % dst_stream, 20), AllOf([Expected(dst, "%d -> %d" % (n, n), 10) for n in range(ep['in_channels'])]), AllOf([Expected(dst, "Media output %d locked" % n, 10) for n in range(ep['in_channels'])]) ] listener_connection += analyzer_expect if test_step.checkpoint is None: return [Sequence(listener_connection + [NoneOf([Expected(dst, "Media output \d+ lost lock", 10)]) ])] else: return [Sequence(listener_connection)]
def action_ping(args, test_step, expected, params_list): """ Ping a node with and check that it responds accordingly. This is used to test connectivity. """ ep_name = choose_src(params_list, 0) ep = endpoints.get(ep_name) node_expect = [Expected(ep_name, "IDENTIFY Ping", 5)] controller_expect = [Expected(args.controller_id, "Success", 5)] args.master.sendLine(args.controller_id, "identify 0x%s on" % endpoints.guid_in_ascii(args.user, ep)) args.master.sendLine(args.controller_id, "identify 0x%s off" % endpoints.guid_in_ascii(args.user, ep)) if test_step.do_checks and (node_expect or controller_expect): expected += [AllOf(node_expect + controller_expect)] yield args.master.expect(None)
def check_set_clock_masters(args, test_step, expected): for loop in graph.get_loops(state.get_current()): loop_master = loop[0] for ep_name in loop: if state.get_current().is_clock_source_master(ep_name): loop_master = ep_name break if not state.get_current().is_clock_source_master(loop_master): ep = endpoints.get(loop_master) args.master.sendLine(args.controller_id, "set_clock_source_master 0x%s" % ( endpoints.guid_in_ascii(args.user, ep))) state.get_next().set_clock_source_master(ep['name']) if test_step.do_checks: controller_expect = [Expected(args.controller_id, "Success", 5)] ep_expect = [Expected(loop_master, "Setting clock source: LOCAL_CLOCK", 5)] if controller_expect or ep_expect: expected += [AllOf(controller_expect + ep_expect)]
def controller_enumerate_seq(test_step, controller_id, endpoint_name): """ Build an enumerated sequence for an entity by reading from a topology file """ expected_seq = [] visible_endpoints = graph.get_endpoints_connected_to(state.get_current(), controller_id) if endpoint_name not in visible_endpoints: return [Expected(controller_id, "No descriptors found", 10)] descriptors = endpoints.get(endpoint_name)['descriptors'] for dtor in sorted(descriptors.keys()): temp_string = "AVB 1722.1 {0} ".format(re.sub('\d*_', '', dtor, 1)) expected_seq.append(Expected(controller_id, temp_string, 10)) for dtor_name in descriptors[str(dtor)].keys(): temp_string = "object_name\s*=\s*\'{0}\'".format(dtor_name) expected_seq.append(Expected(controller_id, temp_string, 10)) for element in descriptors[str(dtor)][dtor_name]: temp_string = "{0}\s*=\s*{1}".format(element['item'], element['value']) expected_seq.append(Expected(controller_id, temp_string, 10)) return [Sequence(expected_seq)]
def analyzer_listener_disconnect_seq(test_step, src, src_stream, dst, dst_stream): listener_ep = endpoints.get(dst) analyzer = listener_ep['analyzer'] analyzer_name = analyzer['name'] analyzer_offset = listener_ep['analyzer_offset'] + analyzer['base'] # Expect both of the stereo channels to lose signal signal_lost = [ Expected(analyzer_name, "Channel %d: Lost signal" % (i + analyzer_offset), timeoutTime=5, completionFn=hook_unregister_error, completionArgs=(analyzer_name, [ "Channel %d: %s" % (i + analyzer_offset, GLITCH_DETECTED_PATTERN)])) for i in range(0, 2) ] # Unregister the lost signal error pattern now process = getActiveProcesses()[analyzer_name] for i in range(0, 2): process.unregisterErrorPattern("Channel %d: %s" % (i + analyzer_offset, LOST_SIGNAL_PATTERN)) return signal_lost
def get_dual_port_nodes(nodes): return [node for node in nodes if endpoints.get(node)['ports'] == 2]
def controller_enumerate(args, avb_ep): entity_id = endpoints.get(avb_ep) args.master.sendLine(args.controller_id, "enumerate 0x%s" % ( endpoints.guid_in_ascii(args.user, entity_id)))