feat: implement 3d euler beam fortran kernel
This commit is contained in:
@@ -72,10 +72,23 @@ def quote_path(path: str | Path) -> str:
|
||||
return shell_join([path])
|
||||
|
||||
|
||||
def cmd_executable(env: dict[str, str] | None = None) -> str:
|
||||
env = env or os.environ
|
||||
return env.get("ComSpec") or shutil.which("cmd.exe") or shutil.which("cmd") or "cmd"
|
||||
|
||||
|
||||
def cmd_minimal_path(env: dict[str, str] | None = None) -> str:
|
||||
env = env or os.environ
|
||||
system_root = env.get("SystemRoot") or r"C:\Windows"
|
||||
return f"{system_root}\\System32;{system_root}"
|
||||
|
||||
|
||||
def wrap_command(toolchain: FortranToolchain, args: list[str | Path]) -> str:
|
||||
command = shell_join(args)
|
||||
if toolchain.env_script is None:
|
||||
return command
|
||||
|
||||
env_script = quote_path(toolchain.env_script)
|
||||
return f'cmd /d /s /c "call {env_script} intel64 >nul && {command}"'
|
||||
cmd = quote_path(cmd_executable())
|
||||
path = cmd_minimal_path()
|
||||
return f'{cmd} /d /s /c "set "PATH={path}" && call {env_script} intel64 >nul && {command}"'
|
||||
|
||||
@@ -65,9 +65,15 @@ class FortranToolchainTests(unittest.TestCase):
|
||||
env_script=Path(r"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"),
|
||||
)
|
||||
|
||||
command = fortran_toolchain.wrap_command(toolchain, ["ifx", "/nologo", "test.f90"])
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{"ComSpec": r"C:\Windows\System32\cmd.exe", "SystemRoot": r"C:\Windows"},
|
||||
clear=True,
|
||||
):
|
||||
command = fortran_toolchain.wrap_command(toolchain, ["ifx", "/nologo", "test.f90"])
|
||||
|
||||
self.assertIn("cmd /d /s /c", command)
|
||||
self.assertIn(r"C:\Windows\System32\cmd.exe /d /s /c", command)
|
||||
self.assertIn('set "PATH=C:\\Windows\\System32;C:\\Windows"', command)
|
||||
self.assertIn('call "C:\\Program Files (x86)\\Intel\\oneAPI\\setvars.bat" intel64', command)
|
||||
self.assertIn("ifx /nologo test.f90", command)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -19,7 +20,7 @@ class ValidateFortranTests(unittest.TestCase):
|
||||
validate_fortran = load_validate_fortran()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
with unittest.mock.patch.dict(os.environ, {}, clear=True):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
commands = validate_fortran.discover_commands(root)
|
||||
|
||||
self.assertEqual(commands, [])
|
||||
@@ -31,7 +32,7 @@ class ValidateFortranTests(unittest.TestCase):
|
||||
manifest = root / "tests" / "fortran" / "manifest.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_text(json.dumps({"tests": []}), encoding="utf-8")
|
||||
with unittest.mock.patch.dict(os.environ, {"HARNESS_FORTRAN_VALIDATION": "off"}, clear=True):
|
||||
with mock.patch.dict(os.environ, {"HARNESS_FORTRAN_VALIDATION": "off"}, clear=True):
|
||||
commands = validate_fortran.discover_commands(root)
|
||||
|
||||
self.assertEqual(commands, [])
|
||||
@@ -43,8 +44,8 @@ class ValidateFortranTests(unittest.TestCase):
|
||||
manifest = root / "tests" / "fortran" / "manifest.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_text(json.dumps({"tests": [{"name": "case", "sources": ["a.f90"]}]}), encoding="utf-8")
|
||||
with unittest.mock.patch.dict(os.environ, {}, clear=True):
|
||||
with unittest.mock.patch.object(validate_fortran, "resolve_toolchain", return_value=None):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
with mock.patch.object(validate_fortran, "resolve_toolchain", return_value=None):
|
||||
with self.assertRaises(validate_fortran.FortranValidationError):
|
||||
validate_fortran.discover_commands(root)
|
||||
|
||||
@@ -71,8 +72,8 @@ class ValidateFortranTests(unittest.TestCase):
|
||||
encoding="utf-8",
|
||||
)
|
||||
toolchain = validate_fortran.FortranToolchain(name="ifx", executable="ifx", env_script=None)
|
||||
with unittest.mock.patch.dict(os.environ, {}, clear=True):
|
||||
with unittest.mock.patch.object(validate_fortran, "resolve_toolchain", return_value=toolchain):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
with mock.patch.object(validate_fortran, "resolve_toolchain", return_value=toolchain):
|
||||
commands = validate_fortran.discover_commands(root)
|
||||
|
||||
self.assertEqual(len(commands), 2)
|
||||
@@ -81,6 +82,36 @@ class ValidateFortranTests(unittest.TestCase):
|
||||
self.assertIn("/exe:", commands[0])
|
||||
self.assertTrue(commands[1].endswith("umat_linear_elastic_kernel.exe"))
|
||||
|
||||
def test_manifest_build_commands_create_test_build_directories(self):
|
||||
validate_fortran = load_validate_fortran()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
manifest = root / "tests" / "fortran" / "manifest.json"
|
||||
manifest.parent.mkdir(parents=True)
|
||||
manifest.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"tests": [
|
||||
{
|
||||
"name": "uel_3d_euler_beam_kernel_stiffness",
|
||||
"sources": [
|
||||
"src/fortran/uel_3d_euler_beam_kernel.f90",
|
||||
"tests/fortran/test_uel_3d_euler_beam_kernel.f90",
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
toolchain = validate_fortran.FortranToolchain(name="ifx", executable="ifx", env_script=None)
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
with mock.patch.object(validate_fortran, "resolve_toolchain", return_value=toolchain):
|
||||
validate_fortran.discover_commands(root)
|
||||
|
||||
build_dir = root / "build" / "fortran-tests" / "uel_3d_euler_beam_kernel_stiffness"
|
||||
self.assertTrue(build_dir.is_dir())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -62,6 +62,7 @@ def build_test_commands(root: Path, manifest: dict, toolchain: FortranToolchain)
|
||||
for record in manifest.get("tests", []):
|
||||
name, sources = _validate_test_record(record)
|
||||
build_dir = root / BUILD_ROOT / name
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
exe_path = build_dir / f"{name}.exe"
|
||||
source_paths = [root / source for source in sources]
|
||||
compile_args: list[str | Path] = [
|
||||
|
||||
Reference in New Issue
Block a user