Skip to content

Commit

Permalink
switch NFSim_test1 to python script for portability
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Jul 26, 2024
1 parent 3f7fbd3 commit a6e1dfe
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 61 deletions.
7 changes: 6 additions & 1 deletion NFsim_v1.11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ enable_testing()
add_executable(${exe_target} ${SRC_FILES})
target_link_libraries(${exe_target} vcommons vcellmessaging)

add_test(NAME ${exe_target}_test1 COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test1/test1.sh ${CMAKE_BINARY_DIR}/bin/${exe_target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/test1)
# if windows then command is py test1.py, else it is test1.py
set(test_command test1.py)
if (WIN32)
set(test_command py test1.py)
endif (WIN32)
add_test(NAME ${exe_target}_test1 COMMAND ${test_command} ${CMAKE_BINARY_DIR}/bin/${exe_target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/test1)

install(TARGETS ${exe_target} RUNTIME DESTINATION ${OPTION_EXE_DIRECTORY})

62 changes: 62 additions & 0 deletions NFsim_v1.11/tests/test1/test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3

import os
import subprocess
import sys

# get the directory of this script
test_dir = os.path.dirname(os.path.realpath(__file__))

exe = sys.argv[1]

input_file = os.path.join(test_dir, "SimID_273069657_0_.nfsimInput")
output = os.path.join(test_dir, "SimID_273069657_0_.gdat")
expected_output = os.path.join(test_dir, "SimID_273069657_0_.gdat.expected")
species = os.path.join(test_dir, "SimID_273069657_0_.species")
expected_species = os.path.join(test_dir, "SimID_273069657_0_.species.expected")

if not os.path.isfile(exe):
print(f"NFsim executable {exe} not found. Exiting...")
sys.exit(1)

if not os.path.isfile(input_file):
print(f"Input file {input_file} not found. Exiting...")
sys.exit(1)

if not os.path.isfile(expected_output):
print(f"Expected output file {expected_output} not found. Exiting...")
sys.exit(1)

if not os.path.isfile(expected_species):
print(f"Expected species file {expected_species} not found. Exiting...")
sys.exit(1)

command = [exe, "-seed", "505790288", "-vcell", "-xml", input_file, "-o", output, "-sim", "1.0", "-ss", species, "-oStep", "20", "-notf", "-utl", "1000", "-cb", "-pcmatch", "-tid", "0"]
print(" ".join(command))

try:
subprocess.check_call(command)
except subprocess.CalledProcessError:
print("NFsim failed to run. Exiting...")
sys.exit(1)

# verify that the output files exist
if not os.path.isfile(output):
print(f"Output file {output} not found. Exiting...")
sys.exit(1)

if not os.path.isfile(species):
print(f"Species file {species} not found. Exiting...")
sys.exit(1)

# verify that the output files match the expected output files
if open(output).read() != open(expected_output).read():
print(f"Output file {output} does not match expected output {expected_output}. Exiting...")
sys.exit(1)

if open(species).read() != open(expected_species).read():
print(f"Species file {species} does not match expected species {expected_species}. Exiting...")
sys.exit(1)

print("NFsim solver completed and solution matched expected output. Exiting...")
sys.exit(0)
60 changes: 0 additions & 60 deletions NFsim_v1.11/tests/test1/test1.sh

This file was deleted.

0 comments on commit a6e1dfe

Please sign in to comment.