Exemple #1
0
def test_find_path_direct_connection():
    a = Vertex("A13")
    b = Vertex("A14")
    a.add_edge(Edge(b))
    assert find_path(a, b) == [a, b]
    # Path is only in one direction
    assert find_path(b, a) == []
Exemple #2
0
def action_link_down(args, test_step, expected, params_list):
  analyzer_name = choose_analyzer(params_list, 0)

  checks = []
  affected_talkers = set()
  # Expect all the connections which cross the relay to be lost
  for c,n in state.get_current().active_connections.iteritems():
    if not n:
      continue

    path = graph.find_path(state.get_current(), c.talker.src, c.listener.dst)
    if path and analyzer_name in path:
      affected_talkers |= set([c.talker])
      checks += [Expected(c.listener.dst, "ADP: Removing entity who timed out -> GUID", 30)]
      checks += sequences.analyzer_listener_disconnect_seq(test_step,
                      c.talker.src, c.talker.src_stream,
                      c.listener.dst, c.listener.dst_stream)
      state.get_next().disconnect(c.talker.src, c.talker.src_stream, c.listener.dst, c.listener.dst_stream)

  for talker in affected_talkers:
    if not state.get_next().talker_active_count(talker.src, talker.src_stream):
      checks += [Expected(talker.src, "Talker stream #%d off" % talker.src_stream, 30)]

  # Send the command to close the relay '(r)elay (c)lose'
  args.master.sendLine(analyzer_name, "r o")
  state.get_next().set_relay_open(analyzer_name)

  if test_step.do_checks and checks:
    expected += [AllOf(checks)]
    yield args.master.expect(None)
  else:
    # At least allow time for the relay to actually be closed
    yield base.sleep(0.1)
Exemple #3
0
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
Exemple #4
0
def test_find_path_chain():
    a = Vertex("A15")
    b = Vertex("A16")
    c = Vertex("A17")
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    assert find_path(a, c) == [a, b, c]
Exemple #5
0
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)
Exemple #6
0
  def get_talker_state(self, src, src_stream, dst, dst_stream, action):
    if graph.find_path(self, src, dst) is None:
      state = 'talker_redundant'

    elif action == 'connect':
      if self.connected(src, src_stream, dst, dst_stream):
        state = 'talker_redundant'
      else:
        if self.listener_active_count(dst, dst_stream):
          state = 'talker_redundant'
        elif self.talker_active_count(src, src_stream):
          state = 'talker_existing'
        else:
          state = 'talker_new'

    elif action == 'disconnect':
      if not self.connected(src, src_stream, dst, dst_stream):
        state = 'talker_redundant'
      else:
        if self.talker_active_count(src, src_stream) == 1:
          state = 'talker_all'
        else:
          state = 'talker_existing'

    else:
      base.testError("Unknown action '%s'" % action, critical=True)

    log_debug("get_talker_state for %s %d %s %d: %s" % (src, src_stream, dst, dst_stream, state))
    return (state + '_' + action)
Exemple #7
0
  def connect(self, src, src_stream, dst, dst_stream):
    """ A connection will occur if the connection doesn't already exist
        and the listener is not in use. There must also be a valid path
        between the two endpoints and the src and dst must be different.
    """
    if (self.connected(src, src_stream, dst, dst_stream) or
        self.listener_active_count(dst, dst_stream)):
      return

    # If it is a self-connect the talker will still be made ready
    self.talker_on_count[src] = self.talker_on_count.get(src, 0) + 1

    if src == dst:
      return

    path = graph.find_path(self, src, dst)
    if not path:
      return

    talker = Talker(src, src_stream)
    listener = Listener(dst, dst_stream)
    connection = Connection(talker, listener)

    self.active_talkers[talker] = self.active_talkers.get(talker, 0) + 1
    self.active_listeners[listener] = 1 # Listeners can only accept one connection
    self.active_connections[connection] = self.active_connections.get(connection, 0) + 1
Exemple #8
0
def test_find_path_cycle():
    a = Vertex("A33")
    b = Vertex("A34")
    c = Vertex("A35")
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    b.add_edge(Edge(c))
    assert find_path(a, c) == [a, b, c]
Exemple #9
0
def test_find_path_ignores_weights():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b, 1))
    c = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(c, 100))
    b.add_edge(Edge(c, 1))
    assert find_path(a, c) == [a, c]
Exemple #10
0
def action_link_downup(args, test_step, expected, params_list):
  """ Expect all connections which bridge the relay to be lost and restored if there
      is a quick link down/up event. The first argument is the analyzer controlling
      the relay. The second is the time to sleep before restoring the link.
  """
  analyzer_name = choose_analyzer(params_list, 0)
  sleep_time = int(params_list[1])

  lost = []
  # Expect all the connections which cross the relay to be lost
  for c,n in state.get_current().active_connections.iteritems():
    if n and analyzer_name in graph.find_path(state.get_current(), c.talker.src, c.listener.dst):
      lost += sequences.analyzer_listener_disconnect_seq(test_step,
                      c.talker.src, c.talker.src_stream,
                      c.listener.dst, c.listener.dst_stream)

  # Send the command to open the relay '(r)elay (o)pen'
  args.master.sendLine(analyzer_name, "r o")
  state.get_next().set_relay_open(analyzer_name)

  if test_step.do_checks and lost:
    expected += [AllOf(lost)]

  # Perform a sleep as defined by the second argument
  yield base.sleep(sleep_time)

  found = []
  # Expect all the connections which cross the relay to be restored
  state.get_next().set_relay_closed(analyzer_name)
  for c,n in state.get_current().active_connections.iteritems():
    if n and analyzer_name in graph.find_path(state.get_current(), c.talker.src, c.listener.dst):
      found += sequences.analyzer_listener_connect_seq(test_step,
                      c.talker.src, c.talker.src_stream,
                      c.listener.dst, c.listener.dst_stream)

  # Send the command to close the relay '(r)elay (c)lose'
  args.master.sendLine(analyzer_name, "r c")

  if test_step.do_checks and found:
    expected += [AllOf(found)]

  yield args.master.expect(None)
Exemple #11
0
    def find_path(self, start, end, skips=None, callback=None,  _=''):
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
        if callback:
            cherrypy.response.headers['Content-Type']= 'text/javascript'
        else:
            cherrypy.response.headers['Content-Type']= 'application/json'

        start_time = time.time()
        skips =  make_list(skips)
        status, path = graph.find_path(start, end, skips)
        results = {}
        results['status'] = status
        if path:
            results['path'] = [graph.get_artist(id) for id in path]
        results['time'] = time.time() - start_time
        return to_json(results, callback)
Exemple #12
0
    def find_path_to_end(self, g, start):
        '''
        Find the start and end points in order for the solution route to be the longest
        possible with no backtracking.  Uses dynamic programming(???).

        Arg: reached is a dictionary whose keys are the vertices that can be reached
        the maze start and reached[u] is the vertex that discovered u in the search

        Returns the route as a list with the first entry as the start and the last 
        entry as the end. 
        '''
        paths = []  # store all possible paths from the start
        vertices = list(g.vertices())
        reached = graph.search(g, start)

        for v in vertices:
            # find the path from start to v
            paths.append(graph.find_path(g, start, v, reached))

        # return the longest path
        # the last entry is the end of the maze
        return max(paths, key=len)
Exemple #13
0
def test_find_path_start_is_end():
    a = Vertex("A12")
    assert find_path(a, a) == [a]
Exemple #14
0
def test_find_path_no_path():
    a = Vertex("A10")
    b = Vertex("A11")
    assert find_path(a, b) == []
Exemple #15
0
		points = graph.articulation_point(g)
		print("Os pontos de articulação são:")
		print("\n".join(points))
	elif choice == 4:
		bridges = graph.bridges(g)
		print("As pontes são:")
		for key, value in bridges.items():
			if not key: continue
			print(key + " - " + ", ".join(value))
	else:
		c1 = raw_input("Personagem 1 >>> ")
		c2 = raw_input("Personagem 2 >>> ")
		c1 = c1.lower().capitalize()
		c2 = c2.lower().capitalize()

		if choice == 1:
			dist = graph.distance_between(g, c1, c2)
			print("A distância entre [{0}] e [{1}] é {2}".format(c1, c2, dist))
		elif choice == 2:
			path = graph.find_path(g, c1, c2)
			if path != []:
				print(" - ".join(path))
			else:
				print("O caminho entre [{0}] e [{1}] não existe!".format(c1, c2))

	print("\n\nNovamente? (s/n)")
	ans = raw_input(">>> ")
	utils.clear()

print("Bye bye!")