
set(ace3p_python_tests)

if (SMTK_ENABLE_VTK_SUPPORT)
  list(APPEND ace3p_python_tests
    omega3p_test1
  )
endif()

set(smtk_pythonpath ${smtk_DIR}/${SMTK_PYTHONPATH})
if(NOT IS_ABSOLUTE ${smtk_pythonpath})
  get_filename_component(smtk_pythonpath
    ${PROJECT_BINARY_DIR}/${smtk_DIR}/${SMTK_PYTHON_MODULEDIR} ABSOLUTE)
endif()

set(pyenv
  ${PROJECT_BINARY_DIR}
  ${smtk_pythonpath}
  $ENV{PYTHONPATH})
if (WIN32)
  string(REPLACE ";" "\;" pyenv "${pyenv}")
else ()
  string(REPLACE ";" ":" pyenv "${pyenv}")
endif()

set(pathenv)
if (WIN32)
  set(pathenv
    ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
    $ENV{PATH})
  string(REPLACE ";" "\;" pathenv "${pathenv}")
endif()

# Function to set test properties
function (config_test test_name)
  set_tests_properties("${test_name}"
    PROPERTIES
      ENVIRONMENT "PYTHONPATH=${pyenv}"
      LABELS "EndToEnd"
  )
  if (pathenv)
    set_property(TEST "${test_name}" APPEND
      PROPERTY
        ENVIRONMENT "PATH=${pathenv}"
    )
  endif ()
endfunction()

# Standard tests
foreach (test ${ace3p_python_tests})
  add_test(
    NAME ${test}_py
    COMMAND  "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/${test}.py"
    --data-dir=${PROJECT_SOURCE_DIR}/data
    --temp-dir=${CMAKE_BINARY_DIR}/Testing/Temporary
    --src-dir=${CMAKE_SOURCE_DIR}
    )
    config_test("${test}_py")
endforeach()

# End to end tests
# Create directory for test files
set(e2e_dir "${CMAKE_BINARY_DIR}/Testing/Temporary/end-to-end")
file(MAKE_DIRECTORY "${e2e_dir}")

# Baseline Omega3P
add_test (
  NAME omega3p_test2
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_SOURCE_DIR}/simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/omega3p_test2.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/genesis/pillbox4.gen"
    -o "${e2e_dir}/omega3p/test2"
)
config_test(omega3p_test2)

# Omega3P with periodic BC
add_test (
  NAME omega3p_test3
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_SOURCE_DIR}/simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/omega3p_test3.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/genesis/pillbox4.gen"
    -o "${e2e_dir}/omega3p/test3"
)
config_test(omega3p_test3)

# Omega3P with CORK eigensolver
add_test (
  NAME omega3p_cork1
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_SOURCE_DIR}/simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/omega3p_cork1.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/netcdf/pillbox+recWG+cirWG.ncdf"
    -o "${e2e_dir}/omega3p/cork1"
)
config_test(omega3p_cork1)

# S3P
add_test (
  NAME s3p_90DegreeBend
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_CURRENT_SOURCE_DIR}/../../simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/s3p_90DegreeBend.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/netcdf/90DegreeBend.ncdf"
    -o "${e2e_dir}/s3p/90DegreeBend"
  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing"
)
config_test(s3p_90DegreeBend)

# T3P
add_test (
  NAME t3p_cavity-quarter
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_CURRENT_SOURCE_DIR}/../../simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/t3p_cavity-quarter.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/netcdf/pillboxwg.ncdf"
    -o "${e2e_dir}/t3p/cavity-quarter"
  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing"
)
config_test(t3p_cavity-quarter)

# Track3P
add_test (
  NAME track3p_Window-SolidVacuumEmission
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_CURRENT_SOURCE_DIR}/../../simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/track3p_Window-SolidVacuumEmission.yml"
    -m "${CMAKE_SOURCE_DIR}/data/model/3d/netcdf/Window.ncdf"
    -o "${e2e_dir}/track3p/Window-SolidVacuumEmission"
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing"
)
config_test(track3p_Window-SolidVacuumEmission)

# RFPostProcess
add_test (
  NAME rfpostprocess
  COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/test-end-to-end.py"
    "${CMAKE_CURRENT_SOURCE_DIR}/../../simulation-workflows/ACE3P.sbt"
    "${CMAKE_CURRENT_SOURCE_DIR}/rfpostprocess.yml"
    -o "${e2e_dir}/rfpostprocess"
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Testing"
)
config_test(rfpostprocess)
