#
# LDASTools Frame Utilities - A library to extend manipulation of LIGO/Virgo Frame
# Files
#
# Copyright (C) 2018 California Institute of Technology
#
# LDASTools Frame Utilities is free software; you may redistribute it and/or
# modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 (GPLv2) of the
# License or at your discretion, any later version.
#
# LDASTools Frame Utilities is distributed in the hope that it will be useful, but
# without any warranty or even the implied warranty of merchantability
# or fitness for a particular purpose. See the GNU General Public
# License (GPLv2) for more details.
#
# Neither the names of the California Institute of Technology (Caltech),
# The Massachusetts Institute of Technology (M.I.T), The Laser
# Interferometer Gravitational-Wave Observatory (LIGO), nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# You should have received a copy of the licensing terms for this
# software included in the file LICENSE located in the top-level
# directory of this package. If you did not, you can view a copy at
# http://dcc.ligo.org/M1500244/LICENSE
#

find_program( MEMORYCHECK_COMMAND valgrind )
set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" )

#------------------------------------------------------------------------
# Variable definitions
#------------------------------------------------------------------------

set( LDADD
  ldasframe
  ${Boost_LIBRARIES}
)

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Testing of C++ routines
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

cx_target_executable(
  test_createRDS
  NOINST
  SOURCES test_createRDS.cc
  LDADD ${LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
  )

cx_target_test(
  test_createRDS
  COMMAND test_createRDS
  )

cx_target_executable(
  test_createRDS_frame_generation
  NOINST
  SOURCES
  test_createRDS_frame_generation.cc
  frame_generator.cc
  LDADD ${LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
  )


#cx_target_test(
#  test_createRDS_frame_generation
#  COMMAND test_createRDS_frame_generation
#  )
# set_tests_properties( test_createRDS_frame_generation PROPERTIES TIMEOUT 300)

cx_target_executable(
  test_createRDS_cpp
  NOINST
  SOURCES test_createRDS_cpp.cc
  LDADD ${LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/include
    ${CMAKE_BINARY_DIR}
    ${LDASTOOLS_INCLUDE_DIRS}
  )

if ( EXISTS /ifocache/llcache )
  cx_target_test(
    test_createRDS_cpp
    COMMAND test_createRDS_cpp --log_level=message
    SETUP_COMMAND
      ${CMAKE_COMMAND} -E remove -f --
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResample-1268056448-64.gwf
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResample-1268056512-64.gwf
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResample-1268056576-64.gwf
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResampleRename-1268056448-64.gwf
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResampleRename-1268056512-64.gwf
      ${CMAKE_CURRENT_BINARY_DIR}/L-testCreateRDSResampleRename-1268056576-64.gwf
    ENVIRONMENT
    SRCDIR=${CMAKE_CURRENT_SOURCE_DIR}
    LDAS_TOP_BUILD_DIR=${CMAKE_BINARY_DIR}
    )
endif( )

cx_target_executable(
  test_intervals
  NOINST
  SOURCES
  test_intervals.cc
  LDADD ${LDADD}
  INCLUDE_DIRECTORIES BEFORE PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_BINARY_DIR}
  ${LDASTOOLS_INCLUDE_DIRS}
  )

cx_target_test(
  test_intervals
  COMMAND test_intervals
  )
# set_tests_properties( test_createRDS_frame_generation PROPERTIES TIMEOUT 300)

if ( false )
  #----------------------------------------------------------------------------
  # this test currently doesn't run for frameCPP version 3.x as the library
  #  doe not properly read version 8 frames.
  #----------------------------------------------------------------------------
if( EXISTS /ifocache/llcache/kafka/H1/H-H1_llhoft-137162/H-H1_llhoft-1371620572-1.gwf )
  add_test( NAME test_ldas_analysis_ready
    COMMAND $<TARGET_FILE:ldas_analysis_ready>
      --frame-file-pattern H-H1_llhoft-1371620572-1.gwf
    WORKING_DIRECTORY /ifocache/llcache/kafka/H1/H-H1_llhoft-137162
    )
endif( )
endif( )

#------------------------------------------------------------------------

cx_scheme_sanitizer_set_environment( )
