Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Dockerfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:22.04

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
g++ && rm -rf /var/lib/apt/lists/*

COPY . /src
WORKDIR /src

7 changes: 5 additions & 2 deletions mkconcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ def cleanup_script_files():
logging.info("assuming .m extension for Dockerfile")
with open(src_path) as fsource:
source_content = fsource.read()
except:
logging.error(f"{CONCOREPATH} is not correct path to concore")
except OSError as e:
logging.error(f"Cannot read Dockerfile template '{src_path}': {e}")
sys.exit(1)
dockerfile_parent = os.path.dirname(dockerfile_path)
if dockerfile_parent:
Expand All @@ -862,6 +862,9 @@ def cleanup_script_files():
if langext=="sh":
fcopy.write('CMD ["./'+sourcecode+'" ,"/opt/mcr/v910"]') # 5/19/21
#["./run_pmmat.sh", "/opt/mcr/MATLAB/MATLAB_Runtime/v910"]
if langext=="cpp":
fcopy.write('RUN g++ ./'+sourcecode+'\n')
fcopy.write('CMD ["./a.out"]\n')
if langext=="v":
fcopy.write('RUN iverilog ./'+sourcecode+'\n') # 7/02/21
fcopy.write('CMD ["./a.out"]\n') # 7/02/21
Expand Down
33 changes: 33 additions & 0 deletions tests/test_docker_cpp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess
import sys
from pathlib import Path

REPO = Path(__file__).resolve().parent.parent


def test_dockerfile_cpp_template_exists():
assert (REPO / "Dockerfile.cpp").is_file()


def test_docker_build_for_cpp_node(tmp_path):
out = tmp_path / "study"
result = subprocess.run(
[
sys.executable,
str(REPO / "mkconcore.py"),
str(REPO / "testsou" / "testSM1.graphml"),
str(REPO / "testsou"),
str(out),
"docker",
],
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stdout + result.stderr
dockerfiles = sorted((out / "src").glob("Dockerfile.*"))
assert dockerfiles
for df in dockerfiles:
text = df.read_text()
assert "g++" in text
assert "RUN g++ ./" in text
assert 'CMD ["./a.out"]' in text
43 changes: 43 additions & 0 deletions tests/test_docker_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re
import shutil
import subprocess
from pathlib import Path

import pytest

REPO = Path(__file__).resolve().parent.parent


def _templates_referenced_by_mkconcore():
"""Dockerfile.<ext> names that mkconcore.py can select in docker mode."""
text = (REPO / "mkconcore.py").read_text()
return sorted(set(re.findall(r'CONCOREPATH\s*\+\s*"/(Dockerfile\.\w+)"', text)))


def test_mkconcore_references_templates():
assert _templates_referenced_by_mkconcore()


@pytest.mark.parametrize("name", _templates_referenced_by_mkconcore())
def test_referenced_dockerfile_template_exists(name):
assert (REPO / name).is_file(), (
f"mkconcore.py selects {name} but it is not in the repo"
)


@pytest.mark.skipif(shutil.which("g++") is None, reason="g++ not installed")
@pytest.mark.parametrize("source", ["pmpymat.cpp", "ccpymat.cpp"])
def test_sample_cpp_node_compiles_like_docker_build(tmp_path, source):
# Mirrors the generated Dockerfile: the source plus the two headers
# that mkconcore copies into the build directory, compiled with plain g++.
for name in (source, "concore.hpp", "concore_base.hpp"):
shutil.copy(
REPO / "testsou" / name if name == source else REPO / name, tmp_path
)
result = subprocess.run(
["g++", f"./{source}", "-o", str(tmp_path / "a.out")],
cwd=tmp_path,
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
Loading