Ejemplo n.º 1
0
def test_make_benchmark_from_command_line(env: LlvmEnv, cmd):
    with temporary_working_directory() as cwd:
        with open("in.c", "w") as f:
            f.write("int main() { return 0; }")

        bm = env.make_benchmark_from_command_line(cmd)
        assert not (cwd / "foo").is_file()

        env.reset(benchmark=bm)
        assert "main()" in env.ir

        assert (cwd / "foo").is_file()

        (cwd / "foo").unlink()
        bm.compile(env)
        assert (cwd / "foo").is_file()
Ejemplo n.º 2
0
def test_make_benchmark_from_command_line_mixed_source_and_object_files(
        env: LlvmEnv, retcode: int):
    """Test a command line that contains both source files and precompiled
    object files. The object files should be filtered from compilation but
    used for the final link.
    """
    with temporary_working_directory():
        with open("a.c", "w") as f:
            f.write("""
#include "b.h"

int A() {
    return B();
}

int main() {
    return A();
}
""")

        with open("b.c", "w") as f:
            f.write(f"int B() {{ return {retcode}; }}")

        with open("b.h", "w") as f:
            f.write("int B();")

        # Compile b.c to object file:
        subprocess.check_call([str(llvm_paths.clang_path()), "b.c", "-c"],
                              timeout=60)
        assert (Path("b.o")).is_file()

        bm = env.make_benchmark_from_command_line(
            ["gcc", "a.c", "b.o", "-o", "foo"])
        env.reset(benchmark=bm)

        bm.compile(env)
        assert Path("foo").is_file()

        p = subprocess.Popen(["./foo"])
        p.communicate(timeout=60)
        assert p.returncode == retcode
Ejemplo n.º 3
0
def test_make_benchmark_from_command_line_multiple_input_sources(
        env: LlvmEnv, retcode: int):
    """Test that command lines with multiple source files are linked together."""
    with temporary_working_directory() as cwd:
        with open("a.c", "w") as f:
            f.write("int main() { return B(); }")

        with open("b.c", "w") as f:
            f.write(f"int B() {{ return {retcode}; }}")

        bm = env.make_benchmark_from_command_line(
            ["gcc", "a.c", "b.c", "-o", "foo"])
        assert not (cwd / "foo").is_file()

        env.reset(benchmark=bm)
        assert "main()" in env.ir

        bm.compile(env)
        assert (cwd / "foo").is_file()

        p = subprocess.Popen(["./foo"])
        p.communicate(timeout=60)
        assert p.returncode == retcode
Ejemplo n.º 4
0
def test_make_benchmark_from_command_line_stdin(env: LlvmEnv):
    with pytest.raises(ValueError,
                       match="Input command line reads from stdin"):
        env.make_benchmark_from_command_line(["gcc", "-xc", "-"])
Ejemplo n.º 5
0
def test_make_benchmark_from_command_line_insufficient_args(env: LlvmEnv, cmd):
    with pytest.raises(ValueError,
                       match="Input command line 'gcc' is too short"):
        env.make_benchmark_from_command_line(cmd)
Ejemplo n.º 6
0
def test_make_benchmark_from_command_line_empty_input(env: LlvmEnv):
    with pytest.raises(ValueError, match="Input command line is empty"):
        env.make_benchmark_from_command_line("")
    with pytest.raises(ValueError, match="Input command line is empty"):
        env.make_benchmark_from_command_line([])