def Main(argv):
    """Instantiate the group of message-sequences used to seed the fuzzer.

  Args:
    argv: command-line arguments used to run the sequencer.
  """
    parsed = wlu.ParseOpts(argv)

    protocols = wlu.ReadProtocols(parsed.spec)
    dep_graph = GetDependencyGraph(protocols)
    for _, interface in wlu.AllInterfaces(protocols):
        for req in interface.findall('request'):
            interface_name = interface.attrib['name']
            message_name = req.attrib['name']
            builder = SequenceBuilder(interface_name + '_' + message_name,
                                      dep_graph)
            builder.BuildMessage(interface_name, message_name, '')

            # Add a round-trip to the sequence in case the server wants to do
            # something funky.
            builder.AppendRoundTrip()

            SequenceToTemplate(parsed, builder)

    # For sequences which are more complicated than a dependency search, we have
    # a manual backup.
    for sequence_builder in GetManualSequences(dep_graph):
        SequenceToTemplate(parsed, sequence_builder)
def GetDependencyGraph(protocols):
    """Determine the dependencies between interfaces and their messages.

  Args:
    protocols: the list of wayland xml protocols you want the dependencies of.

  Returns:
    A bipartite graph where messages (i, m) depend on interfaces (i) and
    vice-versa. An edge from (i,m) to (i') indicates an i' instance is needed to
    invoke m, whereas (i) to (i',m') indicates m' is a constructor for i
    instances.
  """
    dep_graph = {}
    constructed_interfaces = set()
    for _, i, m in wlu.AllMessages(protocols):
        dep_graph[ToNode(i, m)] = [('receiver', i.attrib['name'])] + [
            (a.attrib['name'], a.get('interface', '?'))
            for a in m.findall('arg') if a.attrib['type'] == 'object'
        ]
        constructed = wlu.GetConstructedInterface(m)
        if constructed:
            constructed_interfaces.add(constructed)
            dep_graph[constructed] = ToNode(i, m)
    for _, i in wlu.AllInterfaces(protocols):
        if i.attrib['name'] not in constructed_interfaces:
            dep_graph[i.attrib['name']] = ('wl_registry', 'bind')
    return dep_graph
Example #3
0
def Main(argv):
    """Instantiate the group of message-sequences used to seed the fuzzer.

  Args:
    argv: command-line arguments used to run the sequencer.
  """
    parsed = wlu.ParseOpts(argv)
    out_dir = parsed.output
    if not os.path.exists(out_dir):
        os.mkdir(out_dir)

    protocols = wlu.ReadProtocols(parsed.spec)
    dep_graph = GetDependencyGraph(protocols)
    for _, interface in wlu.AllInterfaces(protocols):
        for req in interface.findall('request'):
            interface_name = interface.attrib['name']
            message_name = req.attrib['name']
            sequence = GetSequenceForMessage(interface_name, message_name,
                                             SequenceContext(dep_graph), '')
            # Add a round-trip to the sequence in case the server wants to do
            # something funky.
            sequence += [round_trip]

            out_path = os.path.join(
                out_dir, '%s_%s.asciipb' % (interface_name, message_name))
            wayland_templater.InstantiateTemplate(parsed.input,
                                                  {'sequence': sequence},
                                                  out_path, parsed.directory)
Example #4
0
 def __init__(self, protocols):
     self.non_global_names = {
         wlu.GetConstructedInterface(m)
         for _, _, m in wlu.AllMessages(protocols)
     } - {None}
     self.interfaces_with_listeners = {
         i.attrib['name']
         for p, i in wlu.AllInterfaces(protocols) if wlu.NeedsListener(i)
     }
     self.counts = {}