From 1b28cc88ffe3d07996c3433da9294898aeda1136 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 18 Jan 2019 14:41:04 +0100 Subject: [PATCH] step one project reorganization --- CMakeLists.txt | 21 +++++--- examples/remove_shm.sh | 10 ++++ slsDetectorSoftware/CMakeLists.txt | 16 +----- .../multiSlsDetector/multiSlsDetector.cpp | 2 +- .../slsDetector/slsDetector.cpp | 2 +- slsReceiverSoftware/CMakeLists.txt | 30 +++++------- .../include/slsReceiverImplementation.h | 3 +- slsSupportLib/CMakeLists.txt | 49 +++++++++++++++++++ .../include/{utilities.h => file_utils.h} | 0 .../src/{utilities.cpp => file_utils.cpp} | 2 +- slsSupportLib/tests/CMakeLists.txt | 26 ++++++++++ .../tests}/test-CmdLineParser.cpp | 0 slsSupportLib/tests/test-Timer.cpp | 23 +++++++++ .../tests}/test-container_utils.cpp | 0 .../tests}/test-string_utils.cpp | 1 - slsSupportLib/tests/test.cpp | 3 ++ 16 files changed, 141 insertions(+), 47 deletions(-) create mode 100755 examples/remove_shm.sh create mode 100644 slsSupportLib/CMakeLists.txt rename slsSupportLib/include/{utilities.h => file_utils.h} (100%) rename slsSupportLib/src/{utilities.cpp => file_utils.cpp} (98%) create mode 100644 slsSupportLib/tests/CMakeLists.txt rename {tests/src => slsSupportLib/tests}/test-CmdLineParser.cpp (100%) create mode 100644 slsSupportLib/tests/test-Timer.cpp rename {tests/src => slsSupportLib/tests}/test-container_utils.cpp (100%) rename {tests/src => slsSupportLib/tests}/test-string_utils.cpp (99%) create mode 100644 slsSupportLib/tests/test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 308de5a55..1bef1c26f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) - -#project(slsDetectorPackage LANGUAGES CXX) +# cmake_minimum_required(VERSION 3.5) +project(slsDetectorPackage) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set (CALIBRATE OFF) @@ -38,6 +38,14 @@ find_package(Qwt 6) find_package(CBF) find_package(Doxygen) +if (USE_TESTS) + enable_testing() +endif(USE_TESTS) + +# Support library containing functionallity common to +# detector and receiver +add_subdirectory(slsSupportLib) + if (USE_HDF5) find_package(HDF5 1.10 COMPONENTS CXX) endif (USE_HDF5) @@ -69,9 +77,9 @@ if (USE_GUI) endif() endif (USE_GUI) -if (USE_SUPPORT_LIB) - add_subdirectory(slsSupportLib) -endif(USE_SUPPORT_LIB) + + + if (CALIBRATE) if (DEFINED ENV{ROOTSYS}) @@ -82,9 +90,6 @@ if (CALIBRATE) endif() endif(CALIBRATE) -if (USE_TESTS) - add_subdirectory(tests) -endif(USE_TESTS) install(FILES ${ZMQ_STATIC_ARCHIVE} DESTINATION lib) diff --git a/examples/remove_shm.sh b/examples/remove_shm.sh new file mode 100755 index 000000000..439bc839c --- /dev/null +++ b/examples/remove_shm.sh @@ -0,0 +1,10 @@ +#!/bin/csh -f +#set l = `ipcs -m | grep "$USER"| cut -c12-19` +set l = `ipcs -m | cut -c0-10` +foreach s ( $l ) + echo $s + ipcrm -M $s +end +#if ($#l != 0 ) +echo $#l shared memory\(s\) for $user removed + diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 6d202cbd0..816bb433e 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -4,17 +4,12 @@ set(SOURCES slsDetector/slsDetectorUsers.cpp slsDetector/slsDetectorCommand.cpp slsDetector/slsDetector.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/src/ClientInterface.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/src/utilities.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/src/string_utils.cpp - ${PROJECT_SOURCE_DIR}/slsSupportLib/src/CmdLineParser.cpp ) set(HEADERS ) include_directories( - ${PROJECT_SOURCE_DIR}/slsSupportLib/include multiSlsDetector sharedMemory slsDetector @@ -26,25 +21,16 @@ add_library(slsDetectorShared SHARED ) target_link_libraries(slsDetectorShared + slsSupportLib zmq ) - set(PUBLICHEADERS - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/sls_detector_defs.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/sls_detector_funcs.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/error_defs.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/versionAPI.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/sls_detector_exceptions.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/utilities.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/container_utils.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/string_utils.h sharedMemory/SharedMemory.h slsDetector/slsDetector.h slsDetector/slsDetectorUsers.h slsDetector/detectorData.h multiSlsDetector/multiSlsDetector.h - ${PROJECT_SOURCE_DIR}/slsSupportLib/include/ClientInterface.h ) set_target_properties(slsDetectorShared PROPERTIES LIBRARY_OUTPUT_NAME SlsDetector diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index fa017a318..34261d7d0 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -7,7 +7,7 @@ #include "slsDetectorCommand.h" #include "slsDetector.h" #include "sls_detector_exceptions.h" -#include "utilities.h" +#include "file_utils.h" #include "string_utils.h" diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index f5c84f83d..b9a4baef0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -6,7 +6,7 @@ #include "gitInfoLib.h" #include "versionAPI.h" #include "slsDetectorCommand.h" -#include "utilities.h" +#include "file_utils.h" #include "string_utils.h" #include "MySocketTCP.h" diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index 612faee64..b84244089 100644 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -10,7 +10,6 @@ set(SOURCES src/DataProcessor.cpp src/DataStreamer.cpp src/Fifo.cpp - ../slsSupportLib/src/ClientInterface.cpp ) @@ -30,30 +29,22 @@ if (USE_HDF5) endif (USE_HDF5) -#add_definitions( -# -DVERBOSE -#) - -include_directories( - include - ../slsSupportLib/include -) - +# include_directories( +# ${SLS_SUPPORT_LIB_INCLUDE_DIRS} +# ) add_library(slsReceiverShared SHARED ${SOURCES} ${HEADERS} ) -set(PUBLICHEADERS - ../slsSupportLib/include/sls_detector_defs.h - ../slsSupportLib/include/ansi.h - ../slsSupportLib/include/sls_detector_funcs.h - ../slsSupportLib/include/MySocketTCP.h - ../slsSupportLib/include/genericSocket.h - ../slsSupportLib/include/logger.h - ../slsSupportLib/include/sls_detector_exceptions.h -) +target_link_libraries(slsReceiverShared slsSupportLib) +target_include_directories(slsReceiverShared PUBLIC include) + +#What is included in slsReceiverLib? +# set(PUBLICHEADERS + +# ) set_target_properties(slsReceiverShared PROPERTIES @@ -70,6 +61,7 @@ set_target_properties(slsReceiver PROPERTIES ) target_link_libraries(slsReceiver + slsSupportLib slsReceiverShared pthread zmq diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index 393b88bb9..642dc3026 100644 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -6,7 +6,7 @@ /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ -#include "sls_detector_defs.h" +// #include "sls_detector_defs.h" #include "receiver_defs.h" #include "logger.h" #include "container_utils.h" @@ -15,6 +15,7 @@ class Listener; class DataProcessor; class DataStreamer; class Fifo; +class slsDetectorDefs; #include #include diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt new file mode 100644 index 000000000..52eb65130 --- /dev/null +++ b/slsSupportLib/CMakeLists.txt @@ -0,0 +1,49 @@ +set(SOURCES + src/ClientInterface.cpp + src/CmdLineParser.cpp + src/string_utils.cpp + src/file_utils.cpp +) + + +set(HEADERS +) + +set(PUBLICHEADERS + include/ansi.h + include/sls_detector_defs.h + include/sls_detector_funcs.h + include/error_defs.h + include/versionAPI.h + include/sls_detector_exceptions.h + include/file_utils.h + include/container_utils.h + include/string_utils.h + include/ClientInterface.h + include/MySocketTCP.h + include/genericSocket.h + include/logger.h +) + +add_library(slsSupportLib SHARED + ${SOURCES} + ${HEADERS} +) + +target_include_directories(slsSupportLib PUBLIC include) + +set_target_properties(slsSupportLib PROPERTIES + LIBRARY_OUTPUT_NAME SlsSupport + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + PUBLIC_HEADER "${PUBLICHEADERS}" +) + +if (USE_TESTS) + add_subdirectory(tests) +endif(USE_TESTS) + +install(TARGETS slsSupportLib + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include + ARCHIVE DESTINATION lib +) diff --git a/slsSupportLib/include/utilities.h b/slsSupportLib/include/file_utils.h similarity index 100% rename from slsSupportLib/include/utilities.h rename to slsSupportLib/include/file_utils.h diff --git a/slsSupportLib/src/utilities.cpp b/slsSupportLib/src/file_utils.cpp similarity index 98% rename from slsSupportLib/src/utilities.cpp rename to slsSupportLib/src/file_utils.cpp index 9346a2db0..71897e5c0 100644 --- a/slsSupportLib/src/utilities.cpp +++ b/slsSupportLib/src/file_utils.cpp @@ -1,4 +1,4 @@ -#include "utilities.h" +#include "file_utils.h" #include "logger.h" #include diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt new file mode 100644 index 000000000..fb0739650 --- /dev/null +++ b/slsSupportLib/tests/CMakeLists.txt @@ -0,0 +1,26 @@ + + +include_directories( + ${PROJECT_SOURCE_DIR}/catch + ../include +) + +set(SOURCES + test.cpp + test-CmdLineParser.cpp + test-container_utils.cpp + test-string_utils.cpp + test-Timer.cpp +) + +add_executable(testSlsSupportLib ${SOURCES}) +target_link_libraries(testSlsSupportLib + slsSupportLib + pthread + rt +) +set_target_properties(testSlsSupportLib PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + ) +#TODO! Move to automatic test discovery +add_test(test-slsSupportLib ${CMAKE_BINARY_DIR}/bin/testSlsSupportLib) \ No newline at end of file diff --git a/tests/src/test-CmdLineParser.cpp b/slsSupportLib/tests/test-CmdLineParser.cpp similarity index 100% rename from tests/src/test-CmdLineParser.cpp rename to slsSupportLib/tests/test-CmdLineParser.cpp diff --git a/slsSupportLib/tests/test-Timer.cpp b/slsSupportLib/tests/test-Timer.cpp new file mode 100644 index 000000000..e382cc340 --- /dev/null +++ b/slsSupportLib/tests/test-Timer.cpp @@ -0,0 +1,23 @@ +#include "Timer.h" +#include "catch.hpp" + +#include +#include + +TEST_CASE("Time 1s restart then time 2s") { + auto sleep_duration = std::chrono::seconds(1); + auto t = sls::Timer(); + std::this_thread::sleep_for(sleep_duration); + REQUIRE(t.elapsed_s() == Approx(1).epsilon(0.01)); + + t.restart(); + std::this_thread::sleep_for(sleep_duration * 2); + REQUIRE(t.elapsed_s() == Approx(2).epsilon(0.01)); +} + +TEST_CASE("Return ms") { + auto sleep_duration = std::chrono::milliseconds(1300); + auto t = sls::Timer(); + std::this_thread::sleep_for(sleep_duration); + REQUIRE(t.elapsed_ms() == Approx(1300).epsilon(0.5)); +} \ No newline at end of file diff --git a/tests/src/test-container_utils.cpp b/slsSupportLib/tests/test-container_utils.cpp similarity index 100% rename from tests/src/test-container_utils.cpp rename to slsSupportLib/tests/test-container_utils.cpp diff --git a/tests/src/test-string_utils.cpp b/slsSupportLib/tests/test-string_utils.cpp similarity index 99% rename from tests/src/test-string_utils.cpp rename to slsSupportLib/tests/test-string_utils.cpp index cb03f1717..c4db9c61a 100644 --- a/tests/src/test-string_utils.cpp +++ b/slsSupportLib/tests/test-string_utils.cpp @@ -7,7 +7,6 @@ #include "string_utils.h" -#define VERBOSE TEST_CASE("copy a string") { diff --git a/slsSupportLib/tests/test.cpp b/slsSupportLib/tests/test.cpp new file mode 100644 index 000000000..8daed99c4 --- /dev/null +++ b/slsSupportLib/tests/test.cpp @@ -0,0 +1,3 @@ +// tests-main.cpp +#define CATCH_CONFIG_MAIN +#include "catch.hpp" \ No newline at end of file