コード例 #1
0
def generate_input(normal, coherent, output_dir=None):
    """Calls fault tree generator.

    The auto-generated input file is located in the run-time directory
    with the default name given by the fault tree generator.

    Args:
        normal: Flag for models with AND/OR gates only.
        coherent: Flag for generation of coherent models.
        output_dir: The directory to put the generated input file.

    Returns:
        The path to the input file.
    """
    input_file = NamedTemporaryFile(dir=output_dir,
                                    prefix="fault_tree_",
                                    suffix=".xml",
                                    delete=False)
    cmd = [
        "--num-basic", "100", "--common-b", "0.4", "--parents-b", "5",
        "--common-g", "0.2", "--parents-g", "3", "--num-args", "2.5", "--seed",
        str(random.randint(1, 1e8)), "--max-prob", "0.5", "--min-prob", "0.1",
        "-o", input_file.name
    ]
    weights = ["--weights-g", "1", "1"]
    if not normal:
        weights += ["1"]
        if not coherent and random.choice([True, False]):
            weights += ["0.01", "0.1"]  # Add non-coherence
    cmd += weights
    ft_gen.main(cmd)
    return input_file.name
コード例 #2
0
ファイル: fuzz_tester.py プロジェクト: kdm04/scram
def generate_input(normal, coherent, output_dir=None):
    """Calls fault tree generator.

    The auto-generated input file is located in the run-time directory
    with the default name given by the fault tree generator.

    Args:
        normal: Flag for models with AND/OR gates only.
        coherent: Flag for generation of coherent models.
        output_dir: The directory to put the generated input file.

    Returns:
        The path to the input file.
    """
    input_file = NamedTemporaryFile(dir=output_dir, prefix="fault_tree_",
                                    suffix=".xml", delete=False)
    cmd = ["--num-basic", "100", "--common-b", "0.4", "--parents-b", "5",
           "--common-g", "0.2", "--parents-g", "3", "--num-args", "2.5",
           "--seed", str(random.randint(1, 1e8)),
           "--max-prob", "0.5", "--min-prob", "0.1",
           "-o", input_file.name]
    weights = ["--weights-g", "1", "1"]
    if not normal:
        weights += ["1"]
        if not coherent and random.choice([True, False]):
            weights += ["0.01", "0.1"]  # Add non-coherence
    cmd += weights
    ft_gen.main(cmd)
    return input_file.name
コード例 #3
0
def test_main():
    """Tests the main() of the generator."""
    tmp = NamedTemporaryFile()
    main(["-b", "200", "-g", "200", "-o", tmp.name])
    relaxng_doc = etree.parse("../share/input.rng")
    relaxng = etree.RelaxNG(relaxng_doc)
    with open(tmp.name, "r") as test_file:
        doc = etree.parse(test_file)
        assert_true(relaxng.validate(doc))

    main(["-b", "200", "-g", "200", "-o", tmp.name, "--shorthand"])
    cmd = ["./shorthand_to_xml.py", tmp.name, "-o", NamedTemporaryFile().name]
    assert_equal(0, call(cmd))
コード例 #4
0
def test_main():
    """Tests the main() of the generator."""
    tmp = NamedTemporaryFile(mode="w+")
    main(["-b", "200", "-g", "200", "-o", tmp.name])
    relaxng_doc = etree.parse("../share/input.rng")
    relaxng = etree.RelaxNG(relaxng_doc)
    with open(tmp.name, "r") as test_file:
        doc = etree.parse(test_file)
        assert relaxng.validate(doc)

    main(["-b", "200", "-g", "200", "-o", tmp.name, "--aralia"])
    cmd = [
        "./translators/aralia.py", tmp.name, "-o",
        NamedTemporaryFile(mode="w+").name
    ]
    assert call(cmd) == 0
コード例 #5
0
def test_main():
    """Tests the main() of the generator."""
    tmp = NamedTemporaryFile(mode="w+")
    main(["-b", "200", "-g", "200", "-o", tmp.name])
    relaxng_doc = etree.parse("../share/input.rng")
    relaxng = etree.RelaxNG(relaxng_doc)
    with open(tmp.name, "r") as test_file:
        doc = etree.parse(test_file)
        assert relaxng.validate(doc)

    main(["-b", "200", "-g", "200", "-o", tmp.name, "--aralia"])
    cmd = [
        "./translators/aralia.py", tmp.name, "-o",
        NamedTemporaryFile(mode="w+").name
    ]
    assert call(cmd) == 0