def propagate(nodes):
    nodes.extend(build_tree(binary_tree(7)))

    m1 = gen_token()
    nodes[3].sendmsg(2, m1)
    grade(5, nodes.verify_output({1: [], 2: [m1], 3: [], 4: [m1], 5: [m1], 6: [], 7: []}))

    m2 = gen_token()
    nodes[3].sendmsg(1, m2)
    grade(5, nodes.verify_output({1: [m2], 2: [m2], 3: [m2], 4: [m2], 5: [m2], 6: [m2], 7: [m2]}))
def type1x(nodes):
    nodes.extend(build_tree({1: {}, 2: {}}, {1: {'bin': 'model'}}))
    nodes[2].setparent_node(nodes[1])
    grade(
        2,
        nodes.verify_structure({
            1: [-1, {2: []}],
        })
    )

    nodes[2].exit()
    grade(
        2,
        nodes.verify_structure({
            1: [-1, {}],
        })
    )
Example #3
0
def explicit_exit(nodes):
    nodes.extend(build_tree(binary_tree(7)))
    nodes[7].exit()
    grade(
        4,
        nodes.verify_structure({
            1: [-1, {2: [4, 5], 3: [6]}],
            3: [1, {6: []}],
        })
    )

    nodes[3].exit()
    grade(
        3,
        nodes.verify_structure({
            6: [-1, {}],  # expect 6 to reset its parent
            1: [-1, {2: [4, 5]}],
        })
    )
def simple_sendmsg(nodes):
    nodes.extend(build_tree(binary_tree(7)))
    m1 = gen_token()

    nodes[1].sendmsg(4, m1)
    grade(
        5,
        nodes.verify_output({
            4: [m1],
        })
    )

    m2 = gen_token()
    nodes[7].sendmsg(5, m2)
    grade(
        5,
        nodes.verify_output({
            5: [m2],
        })
    )
Example #5
0
def join(nodes):
    nodes.extend(build_tree({i: {} for i in range(1, 8)}))
    nodes[2].setparent_node(nodes[1])
    grade(
        3,
        nodes.verify_structure({
            1: [-1, {2: []}],
            2: [1, {}],
        })
    )

    nodes[3].setparent_node(nodes[2])
    nodes[4].setparent_node(nodes[2])
    grade(
        5,
        nodes.verify_structure({
            1: [-1, {2: [3, 4]}],
            2: [1, {3: [], 4: []}],
            3: [2, {}],
            4: [2, {}],
        })
    )

    nodes[6].setparent_node(nodes[5])
    nodes[7].setparent_node(nodes[5])
    nodes[5].setparent_node(nodes[1])
    grade(
        5,
        nodes.verify_structure({
            1: [-1, {2: [3, 4], 5: [6, 7]}],
        })
    )
def type2x_30(nodes):
    nodes.extend(build_tree({1: {2: {3: {}}}}, {2: {'bin': 'model'}}))

    m1 = gen_token()
    nodes[1].sendmsg(3, m1)
    grade(
        2,
        nodes.verify_output({
            1: [],
            2: [],
            3: [m1],
        })
    )

    m2 = gen_token()
    nodes[3].sendmsg(1, m2)
    grade(
        2,
        nodes.verify_output({
            1: [m2],
        })
    )
    grade(
        2,
        nodes.verify_output({
            2: [m2],
            3: [m2],
        })
    )
Example #7
0
def change_parent(nodes):
    nodes.extend(build_tree({
        1: {
            2: {
                3: {},
                4: {},
            },
        },
        5: {},
    }))
    nodes[3].setparent_node(nodes[5])
    nodes[2].setparent_node(nodes[3])
    grade(
        3,
        nodes.verify_structure({
            1: [-1, {}],
            2: [3, {4: []}],
            3: [5, {2: [4]}],
            4: [2, {}],
            5: [-1, {3: [2, 4]}],
        })
    )
def mixed_scenario(nodes):
    node_count = 31
    nodes.extend(build_tree(
        binary_tree(node_count),
        opts={i: {FULL_TRACK: True} for i in range(1, node_count + 1)},
    ))

    cmds = [nodes[i].exit for i in range(1, node_count + 1)]
    for _ in range(node_count):
        fr, to = random.randint(1, node_count), random.randint(1, node_count)
        cmds.append(partial(nodes[fr].setparent_node, nodes[to]))
    for _ in range(10 * node_count):
        fr, to, m = random.randint(1, node_count), random.randint(1, node_count), gen_token()
        cmds.append(partial(nodes[fr].sendmsg, to, m))
    random.shuffle(cmds)
    for cmd in cmds:
        cmd()

    clean = nodes.verify_clean_exit()
    grade(4, clean)
    grade(8, clean and nodes.verify_no_memory_leak())
    grade(8, clean and nodes.verify_no_open_sockets())
Example #9
0
def basic_print(nodes):
    nodes.extend(build_tree({1: {}}))
    grade(2, nodes.verify_structure({1: [-1, {}]}))
def m20_from_parent(nodes):
    nodes.extend(build_tree({1: {2: {}}}, {1: {'bin': 'model'}}))
    nodes[1].run_command('sendcustom 20 2 %s' % gen_token())
    grade(2, nodes.verify_output({2: []}))
    grade(2, nodes.verify_structure({2: [-1, {}]}))
def invalid_message(nodes):
    nodes.extend(build_tree({1: {2: {}}}, {2: {'bin': 'model'}}))
    nodes[2].run_command('sendcustom 50 1 %s' % gen_token())
    grade(3, nodes.verify_structure({1: [-1, {}]}))
def m30_from_child(nodes):
    nodes.extend(build_tree({1: {2: {}}}, {2: {'bin': 'model'}}))
    nodes[2].run_command('sendcustom 30 1 %s' % gen_token())
    grade(2, nodes.verify_output({1: []}))
    grade(2, nodes.verify_structure({1: [-1, {}]}))