예제 #1
0
def test_visualize_log_file():
    # Briefly run RIFT to produce a valid log file
    res = rift_expect_session.RiftExpectSession("2n_l0_l1")
    res.stop()
    # If rift.log.html still exists from a previous run, remove it
    html_file_name = "rift.log.html"
    if os.path.exists(html_file_name):
        os.remove(html_file_name)
    # Run the visualization tool, and makes sure it exits without an error
    return_code = subprocess.call("rift/visualize_log.py")
    assert return_code == 0
    # Check that a visualization file was indeed produced
    assert os.path.exists(html_file_name)
    # We can't really check that the visualization "looks good" So, instead we just check that there
    # is at least <svg ...> and </svg> tags, which is a decent indication that the tool ran to
    # completion.
    found_start = False
    found_end = False
    with open(html_file_name) as infile:
        for line in infile:
            if line.startswith("<svg"):
                found_start = True
            if line.startswith("</svg>"):
                found_end = True
    assert found_start
    assert found_end
예제 #2
0
def process_file():
    # pylint:disable=too-many-locals
    doc_file = "doc/command-line-interface.md"
    tmp_file = "doc/command-line-interface.md.new"
    backup_file = "doc/command-line-interface.md.bak"
    res = rift_expect_session.RiftExpectSession("two_by_two_by_two",
                                                log_debug=False)
    processed_commands = []
    all_commands = gather_output(res, "agg_101", "help")
    start_regex = re.compile(".*<!-- OUTPUT-START: (.*)> (.*) -->.*")
    end_regex = re.compile(".*<!-- OUTPUT-END -->.*")
    manual_regex = re.compile(".*<!-- OUTPUT-MANUAL: (.*)> (.*) -->.*")
    with open('doc/command-line-interface.md', 'rt') as in_file, \
        open('doc/command-line-interface.md.new', 'wt') as out_file:
        skipping = False
        for line in in_file:
            start_match = start_regex.match(line)
            end_match = end_regex.match(line)
            manual_match = manual_regex.match(line)
            if start_match:
                print(line, file=out_file, end='')
                node = start_match.group(1)
                command = start_match.group(2)
                insert_command_output(out_file, res, node, command)
                processed_commands.append(command)
                skipping = True
            elif end_match:
                print(line, file=out_file, end='')
                skipping = False
            elif manual_match:
                print(line, file=out_file, end='')
                node = manual_match.group(1)
                command = manual_match.group(2)
                if not ARGS.check_only:
                    print("Manual:", command)
                processed_commands.append(command)
            elif not skipping:
                print(line, file=out_file, end='')
    res.stop()
    if not ARGS.check_only:
        shutil.copyfile(doc_file, backup_file)
        shutil.copyfile(tmp_file, doc_file)
    os.remove(tmp_file)
    return check_missing_commands(all_commands, processed_commands)