def test_construct_core_commands(router_access_core):
    # XXX: This test is *very* far from being complete. In particular, though
    # the problem supplied is realistic, the output is not checked thouroughly
    # enough.
    e = Experiment(Mock())

    # A simple example network as follows:
    #       f0
    #  c0 ---+--> c1
    #   |    '--> c2
    #   +-------> c3
    #      f1
    # We'll pretend all of them are on the same chip and core0 is the one
    # designated as the router-value recording core.

    core0 = e.new_core()
    core1 = e.new_core()
    core2 = e.new_core()
    core3 = e.new_core()

    cores = [core0, core1, core2, core3]

    flow0 = e.new_flow(core0, [core1, core2])
    flow1 = e.new_flow(core0, core3)

    # Seed randomly
    e.seed = None

    e.timestep = 1e-6
    e.warmup = 0.001
    e.duration = 1.0
    e.cooldown = 0.001
    e.flush_time = 0.01

    e.record_sent = True

    e.reinject_packets = True

    # By default, nothing should send and everything should consume
    e.probability = 0.0
    e.consume = True
    e.router_timeout = 240

    # In group0, everything consumes and f0 sends 100% packets and f1 sends 50%
    # packets.
    with e.new_group():
        flow0.probability = 1.0
        flow1.probability = 0.5

    # In group1, nothing consumes and f0 and f1 send 100%
    with e.new_group():
        flow0.probability = 1.0
        flow1.probability = 1.0
        e.consume = False
        e.router_timeout = 0

    # In group2, we have a timeout with emergency routing enabled
    with e.new_group():
        e.router_timeout = (16, 16)

    flow_keys = {flow0: 0xAA00, flow1: 0xBB00}

    cores_source_flows = {
        core0: [flow0, flow1],
        core1: [],
        core2: [],
        core3: [],
    }
    cores_sink_flows = {
        core0: [],
        core1: [flow0],
        core2: [flow0],
        core3: [flow1],
    }

    core_commands = {
        core: e._construct_core_commands(
            core=core,
            source_flows=cores_source_flows[core],
            sink_flows=cores_sink_flows[core],
            flow_keys=flow_keys,
            records=[Counters.deadlines_missed, Counters.sent],
            router_access_core=router_access_core).pack()
        for core in cores
    }

    # Make sure all cores have the right number of sources/sinks set
    for core in cores:
        commands = core_commands[core]
        num_sources = len(cores_source_flows[core])
        num_sinks = len(cores_sink_flows[core])
        ref_cmd = struct.pack("<II", NT_CMD.NUM,
                              (num_sources | num_sinks << 16))
        assert ref_cmd in commands

    # Make sure all cores have the right set of sources and sinks
    for core in cores:
        commands = core_commands[core]
        sources = cores_source_flows[core]
        sinks = cores_sink_flows[core]

        for source_num, source_flow in enumerate(sources):
            ref_cmd = struct.pack("<II", NT_CMD.SOURCE_KEY | (source_num << 8),
                                  flow_keys[source_flow])
            assert ref_cmd in commands

        for sink_num, sink_flow in enumerate(sinks):
            ref_cmd = struct.pack("<II", NT_CMD.SINK_KEY | (sink_num << 8),
                                  flow_keys[sink_flow])
            assert ref_cmd in commands

    # Make sure all cores have the right set of timing values
    for core in cores:
        commands = core_commands[core]

        ref_cmd = struct.pack("<II", NT_CMD.TIMESTEP, 1000)
        assert ref_cmd in commands

    # Make sure all cores have the right timeout set
    for core in cores:
        commands = core_commands[core]

        ref_cmd0 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT)
        ref_cmd1 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT_RESTORE)
        if router_access_core:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands

    # Make sure all cores packet reinjection enabled if requested
    for core in cores:
        commands = core_commands[core]

        ref_cmd0 = struct.pack("<I", NT_CMD.REINJECTION_ENABLE)
        ref_cmd1 = struct.pack("<I", NT_CMD.REINJECTION_DISABLE)
        if router_access_core:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands
def test_option_descriptors():
    """Make sure the option descriptors work."""
    e = Experiment(Mock())

    # Defualts should work
    assert e.seed is None
    assert e.probability == 1.0

    # Should be able to set
    e.probability = 0.1
    assert e.probability == 0.1

    # Should be able to set exceptions for groups
    with e.new_group():
        assert e.probability == 0.1
        e.probability = 1.0
        assert e.probability == 1.0

    assert e.probability == 0.1

    # Should be able to set non-exception-supporting options globally
    assert e.record_sent is False
    e.record_sent = True
    assert e.record_sent is True

    # Should be able to set exceptions for cores
    core0 = e.new_core()
    assert core0.probability == 0.1
    core0.probability = 0.5
    assert core0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions for flows
    flow0 = e.new_flow(core0, core0)
    assert flow0.probability == 0.5
    flow0.probability = 0.6
    assert flow0.probability == 0.6
    assert core0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions in groups for cores and flows
    with e.new_group():
        assert e.probability == 0.1
        assert core0.probability == 0.5
        assert flow0.probability == 0.6

        # Group probability shouldn't override core/flow probability
        e.probability = 1.0
        assert e.probability == 1.0
        assert core0.probability == 0.5
        assert flow0.probability == 0.6

        # Group+core probability should take precidence (but not over flows)
        core0.probability = 10.0
        assert e.probability == 1.0
        assert core0.probability == 10.0
        assert flow0.probability == 0.6

        # Group+flow probability should take overall precidence
        flow0.probability = 20.0
        assert e.probability == 1.0
        assert core0.probability == 10.0
        assert flow0.probability == 20.0

        # Should be able to get non-exception supporting options
        assert e.record_sent is True

        # Shouldn't be able to set non-exception-supporting options
        with pytest.raises(ValueError):
            e.record_sent = False

    # ...but only within the group
    assert e.probability == 0.1
    assert core0.probability == 0.5
    assert flow0.probability == 0.6
Beispiel #3
0
def test_construct_core_commands(router_access_core):
    # XXX: This test is *very* far from being complete. In particular, though
    # the problem supplied is realistic, the output is not checked thouroughly
    # enough.
    e = Experiment(Mock())

    # A simple example network as follows:
    #       f0
    #  c0 ---+--> c1
    #   |    '--> c2
    #   +-------> c3
    #      f1
    # We'll pretend all of them are on the same chip and core0 is the one
    # designated as the router-value recording core.

    core0 = e.new_core()
    core1 = e.new_core()
    core2 = e.new_core()
    core3 = e.new_core()

    cores = [core0, core1, core2, core3]

    flow0 = e.new_flow(core0, [core1, core2])
    flow1 = e.new_flow(core0, core3)

    # Seed randomly
    e.seed = None

    e.timestep = 1e-6
    e.warmup = 0.001
    e.duration = 1.0
    e.cooldown = 0.001
    e.flush_time = 0.01

    e.record_sent = True

    e.reinject_packets = True

    # By default, nothing should send and everything should consume
    e.probability = 0.0
    e.consume = True
    e.router_timeout = 240

    # In group0, everything consumes and f0 sends 100% packets and f1 sends 50%
    # packets.
    with e.new_group():
        flow0.probability = 1.0
        flow1.probability = 0.5

    # In group1, nothing consumes and f0 and f1 send 100%
    with e.new_group():
        flow0.probability = 1.0
        flow1.probability = 1.0
        e.consume = False
        e.router_timeout = 0

    # In group2, we have a timeout with emergency routing enabled
    with e.new_group():
        e.router_timeout = (16, 16)

    flow_keys = {flow0: 0xAA00, flow1: 0xBB00}

    cores_source_flows = {
        core0: [flow0, flow1],
        core1: [],
        core2: [],
        core3: [],
    }
    cores_sink_flows = {
        core0: [],
        core1: [flow0],
        core2: [flow0],
        core3: [flow1],
    }

    core_commands = {
        core: e._construct_core_commands(
            core=core,
            source_flows=cores_source_flows[core],
            sink_flows=cores_sink_flows[core],
            flow_keys=flow_keys,
            records=[Counters.deadlines_missed, Counters.sent],
            router_access_core=router_access_core).pack()
        for core in cores
    }

    # Make sure all cores have the right number of sources/sinks set
    for core in cores:
        commands = core_commands[core]
        num_sources = len(cores_source_flows[core])
        num_sinks = len(cores_sink_flows[core])
        ref_cmd = struct.pack("<II", NT_CMD.NUM,
                              (num_sources | num_sinks << 16))
        assert ref_cmd in commands

    # Make sure all cores have the right set of sources and sinks
    for core in cores:
        commands = core_commands[core]
        sources = cores_source_flows[core]
        sinks = cores_sink_flows[core]

        for source_num, source_flow in enumerate(sources):
            ref_cmd = struct.pack("<II", NT_CMD.SOURCE_KEY | (source_num << 8),
                                  flow_keys[source_flow])
            assert ref_cmd in commands

        for sink_num, sink_flow in enumerate(sinks):
            ref_cmd = struct.pack("<II", NT_CMD.SINK_KEY | (sink_num << 8),
                                  flow_keys[sink_flow])
            assert ref_cmd in commands

    # Make sure all cores have the right set of timing values
    for core in cores:
        commands = core_commands[core]

        ref_cmd = struct.pack("<II", NT_CMD.TIMESTEP, 1000)
        assert ref_cmd in commands

    # Make sure all cores have the right timeout set
    for core in cores:
        commands = core_commands[core]

        ref_cmd0 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT)
        ref_cmd1 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT_RESTORE)
        if router_access_core:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands

    # Make sure all cores packet reinjection enabled if requested
    for core in cores:
        commands = core_commands[core]

        ref_cmd0 = struct.pack("<I", NT_CMD.REINJECTION_ENABLE)
        ref_cmd1 = struct.pack("<I", NT_CMD.REINJECTION_DISABLE)
        if router_access_core:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands
Beispiel #4
0
def test_option_descriptors():
    """Make sure the option descriptors work."""
    e = Experiment(Mock())

    # Defualts should work
    assert e.seed is None
    assert e.probability == 1.0

    # Should be able to set
    e.probability = 0.1
    assert e.probability == 0.1

    # Should be able to set exceptions for groups
    with e.new_group():
        assert e.probability == 0.1
        e.probability = 1.0
        assert e.probability == 1.0

    assert e.probability == 0.1

    # Should be able to set non-exception-supporting options globally
    assert e.record_sent is False
    e.record_sent = True
    assert e.record_sent is True

    # Should be able to set exceptions for cores
    core0 = e.new_core()
    assert core0.probability == 0.1
    core0.probability = 0.5
    assert core0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions for flows
    flow0 = e.new_flow(core0, core0)
    assert flow0.probability == 0.5
    flow0.probability = 0.6
    assert flow0.probability == 0.6
    assert core0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions in groups for cores and flows
    with e.new_group():
        assert e.probability == 0.1
        assert core0.probability == 0.5
        assert flow0.probability == 0.6

        # Group probability shouldn't override core/flow probability
        e.probability = 1.0
        assert e.probability == 1.0
        assert core0.probability == 0.5
        assert flow0.probability == 0.6

        # Group+core probability should take precidence (but not over flows)
        core0.probability = 10.0
        assert e.probability == 1.0
        assert core0.probability == 10.0
        assert flow0.probability == 0.6

        # Group+flow probability should take overall precidence
        flow0.probability = 20.0
        assert e.probability == 1.0
        assert core0.probability == 10.0
        assert flow0.probability == 20.0

        # Should be able to get non-exception supporting options
        assert e.record_sent is True

        # Shouldn't be able to set non-exception-supporting options
        with pytest.raises(ValueError):
            e.record_sent = False

    # ...but only within the group
    assert e.probability == 0.1
    assert core0.probability == 0.5
    assert flow0.probability == 0.6
def test_construct_vertex_commands(router_access_vertex):
    # XXX: This test is *very* far from being complete. In particular, though
    # the problem supplied is realistic, the output is not checked thouroughly
    # enough.
    e = Experiment(Mock())

    # A simple example network as follows:
    #       n0
    #  v0 ---+--> v1
    #   |    '--> v2
    #   +-------> v3
    #      n1
    # We'll pretend all of them are on the same chip and vertex0 is the one
    # designated as the router-value recording vertex.

    vertex0 = e.new_vertex()
    vertex1 = e.new_vertex()
    vertex2 = e.new_vertex()
    vertex3 = e.new_vertex()

    vertices = [vertex0, vertex1, vertex2, vertex3]

    net0 = e.new_net(vertex0, [vertex1, vertex2])
    net1 = e.new_net(vertex0, vertex3)

    # Seed randomly
    e.seed = None

    e.timestep = 1e-6
    e.warmup = 0.001
    e.duration = 1.0
    e.cooldown = 0.001
    e.flush_time = 0.01

    e.record_sent = True

    e.reinject_packets = True

    # By default, nothing should send and everything should consume
    e.probability = 0.0
    e.consume = True
    e.router_timeout = 240

    # In group0, everything consumes and n0 sends 100% packets and n1 sends 50%
    # packets.
    with e.new_group():
        net0.probability = 1.0
        net1.probability = 0.5

    # In group1, nothing consumes and n0 and n1 send 100%
    with e.new_group():
        net0.probability = 1.0
        net1.probability = 1.0
        e.consume = False
        e.router_timeout = 0

    # In group2, we have a timeout with emergency routing enabled
    with e.new_group():
        e.router_timeout = (16, 16)

    net_keys = {net0: 0xAA00, net1: 0xBB00}

    vertices_source_nets = {
        vertex0: [net0, net1],
        vertex1: [],
        vertex2: [],
        vertex3: [],
    }
    vertices_sink_nets = {
        vertex0: [],
        vertex1: [net0],
        vertex2: [net0],
        vertex3: [net1],
    }

    vertex_commands = {
        vertex: e._construct_vertex_commands(
            vertex=vertex,
            source_nets=vertices_source_nets[vertex],
            sink_nets=vertices_sink_nets[vertex],
            net_keys=net_keys,
            records=[Counters.sent],
            router_access_vertex=router_access_vertex).pack()
        for vertex in vertices
    }

    # Make sure all vertices have the right number of sources/sinks set
    for vertex in vertices:
        commands = vertex_commands[vertex]
        num_sources = len(vertices_source_nets[vertex])
        num_sinks = len(vertices_sink_nets[vertex])
        ref_cmd = struct.pack("<II", NT_CMD.NUM,
                              (num_sources | num_sinks << 8))
        assert ref_cmd in commands

    # Make sure all vertices have the right set of sources and sinks
    for vertex in vertices:
        commands = vertex_commands[vertex]
        sources = vertices_source_nets[vertex]
        sinks = vertices_sink_nets[vertex]

        for source_num, source_net in enumerate(sources):
            ref_cmd = struct.pack("<II", NT_CMD.SOURCE_KEY | (source_num << 8),
                                  net_keys[source_net])
            assert ref_cmd in commands

        for sink_num, sink_net in enumerate(sinks):
            ref_cmd = struct.pack("<II", NT_CMD.SINK_KEY | (sink_num << 8),
                                  net_keys[sink_net])
            assert ref_cmd in commands

    # Make sure all vertices have the right set of timing values
    for vertex in vertices:
        commands = vertex_commands[vertex]

        ref_cmd = struct.pack("<II", NT_CMD.TIMESTEP, 1000)
        assert ref_cmd in commands

    # Make sure all vertices have the right timeout set
    for vertex in vertices:
        commands = vertex_commands[vertex]

        ref_cmd0 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT)
        ref_cmd1 = struct.pack("<I", NT_CMD.ROUTER_TIMEOUT_RESTORE)
        if router_access_vertex:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands

    # Make sure all vertices packet reinjection enabled if requested
    for vertex in vertices:
        commands = vertex_commands[vertex]

        ref_cmd0 = struct.pack("<I", NT_CMD.REINJECTION_ENABLE)
        ref_cmd1 = struct.pack("<I", NT_CMD.REINJECTION_DISABLE)
        if router_access_vertex:
            assert ref_cmd0 in commands
            assert ref_cmd1 in commands
        else:
            assert ref_cmd0 not in commands
            assert ref_cmd1 not in commands
def test_option_descriptors():
    """Make sure the option descriptors work."""
    e = Experiment(Mock())

    # Defualts should work
    assert e.seed is None
    assert e.probability == 1.0

    # Should be able to set
    e.probability = 0.1
    assert e.probability == 0.1

    # Should be able to set exceptions for groups
    with e.new_group():
        assert e.probability == 0.1
        e.probability = 1.0
        assert e.probability == 1.0

    assert e.probability == 0.1

    # Should be able to set non-exception-supporting options globally
    assert e.record_sent is False
    e.record_sent = True
    assert e.record_sent is True

    # Should be able to set exceptions for vertices
    vertex0 = e.new_vertex()
    assert vertex0.probability == 0.1
    vertex0.probability = 0.5
    assert vertex0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions for nets
    net0 = e.new_net(vertex0, vertex0)
    assert net0.probability == 0.5
    net0.probability = 0.6
    assert net0.probability == 0.6
    assert vertex0.probability == 0.5
    assert e.probability == 0.1

    # Should be able to set exceptions in groups for vertices and nets
    with e.new_group():
        assert e.probability == 0.1
        assert vertex0.probability == 0.5
        assert net0.probability == 0.6

        # Group probability shouldn't override vertex/net probability
        e.probability = 1.0
        assert e.probability == 1.0
        assert vertex0.probability == 0.5
        assert net0.probability == 0.6

        # Group+vertex probability should take precidence (but not over nets)
        vertex0.probability = 10.0
        assert e.probability == 1.0
        assert vertex0.probability == 10.0
        assert net0.probability == 0.6

        # Group+net probability should take overall precidence
        net0.probability = 20.0
        assert e.probability == 1.0
        assert vertex0.probability == 10.0
        assert net0.probability == 20.0

        # Should be able to get non-exception supporting options
        assert e.record_sent is True

        # Shouldn't be able to set non-exception-supporting options
        with pytest.raises(ValueError):
            e.record_sent = False

    # ...but only within the group
    assert e.probability == 0.1
    assert vertex0.probability == 0.5
    assert net0.probability == 0.6