Skip to content

Commit

Permalink
Add integration tests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW authored Nov 21, 2024
2 parents 9c58c1e + dbbd7ce commit 15c3a72
Show file tree
Hide file tree
Showing 38 changed files with 531 additions and 152 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: ci
on:
pull_request:
branches:
- dev
- master
push:
branches:
Expand All @@ -11,7 +12,7 @@ on:
permissions: write-all

jobs:
build:
ci-test:
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -43,6 +44,26 @@ jobs:
git config --global --add safe.directory $GITHUB_WORKSPACE
cmake --preset default
cmake --build ./build -- -j2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: test
run: |
cd build/bin
./srs_backend_test --gtest_output=xml
- name: publish test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Google test
path: 'build/bin/test_detail.xml'
fail-on-error: true
reporter: java-junit

- name: cache-delete
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
gh cache delete ${{ steps.cache-restore.outputs.cache-primary-key }} || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:

- name: clean old releases
continue-on-error: true
run: gh release delete ${{ env.TAG_NAME }} || true
run: gh release delete ${{ env.TAG_NAME }} --cleanup-tag || true

- name: create release
run: |
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ project(
LANGUAGES CXX C)

include(${CMAKE_SOURCE_DIR}/cmake/install_config.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/install_packages.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/project_config.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/check_compilers.cmake)

Expand All @@ -22,7 +21,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
list(APPEND CMAKE_CXX_FLAGS "-fexperimental-library")
endif()

include(${CMAKE_SOURCE_DIR}/cmake/import_packages.cmake)

add_subdirectory(frontend)
add_subdirectory(backend)
add_subdirectory(test)
add_subdirectory(examples)
if(ENABLE_TEST)
add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# srs-daq - A data acquisition program for SRS FEC & VMM3

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/7e8c956af1bc46c7836524f1ace32c11)](https://app.codacy.com/gh/YanzhaoW/srs-daq/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![CI pipeline](https://github.com/YanzhaoW/srs-daq/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/YanzhaoW/srs-daq/actions?query=branch%3Amaster)
[![CI pipeline](https://github.com/YanzhaoW/srs-daq/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/YanzhaoW/srs-daq/actions?query=branch%3Adev)
[![Github Releases](https://img.shields.io/github/release/YanzhaoW/srs-daq.svg)](https://github.com/YanzhaoW/srs-daq/releases)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Expand Down
31 changes: 0 additions & 31 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,6 @@ if(BUILD_STATIC)
set(CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++")
endif()

find_package(Boost REQUIRED CONFIG COMPONENTS thread)
find_package(fmt REQUIRED)
find_package(zpp_bits REQUIRED)
find_package(gsl-lite REQUIRED)
find_package(spdlog REQUIRED)
find_package(CLI11 REQUIRED)
find_package(TBB REQUIRED)
find_package(Protobuf CONFIG COMPONENTS libprotobuf)
if(NOT Protobuf_FOUND)
find_package(Protobuf MODULE COMPONENTS libprotobuf)
endif()

if(NOT NO_ROOT)
if(USE_ROOT)
message(STATUS "Force to use ROOT depenedency!")
set(CMAKE_MESSAGE_LOG_LEVEL ERROR) # turn off annoying root warnings
find_package(ROOT QUIET REQUIRED COMPONENTS RIO Tree Hist Gpad)
set(CMAKE_MESSAGE_LOG_LEVEL STATUS)
else()
set(CMAKE_MESSAGE_LOG_LEVEL ERROR)
find_package(ROOT QUIET COMPONENTS RIO Tree Hist Gpad)
set(CMAKE_MESSAGE_LOG_LEVEL STATUS)
endif()
endif()

if(ROOT_FOUND)
message(STATUS "ROOT depenedency is enabled!")
else()
message(STATUS "ROOT depenedency is disabled!")
endif()

add_subdirectory(srs)

add_executable(srs_control main.cpp)
Expand Down
3 changes: 2 additions & 1 deletion backend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ auto main(int argc, char** argv) -> int

app.read_data();
app.switch_on();
app.run();
app.start_analysis();
app.wait_for_finish();
}
catch (const CLI::ParseError& e)
{
Expand Down
70 changes: 45 additions & 25 deletions backend/srs/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,43 @@ namespace srs
start_work();
}

App::~App() = default;
App::~App() noexcept
{
if (working_thread_.joinable())
{
spdlog::debug("Application: Working thread is still running. Trying to stop the io context ...");
io_context_.stop();
spdlog::debug("io context is stoped");
}
}

void App::start_work()
{
auto monitoring_action = [this]()
{
signal_set_.async_wait(
[this](const boost::system::error_code& error, auto)
{
if (error == asio::error::operation_aborted)
try
{
signal_set_.async_wait(
[this](const boost::system::error_code& error, auto)
{
return;
}
if (error == asio::error::operation_aborted)
{
return;
}

spdlog::trace("calling SIGINT from monitoring thread");
exit();
});
io_context_.join();
spdlog::trace("calling SIGINT from monitoring thread");
exit();
});
io_context_.join();
}
catch (const std::exception& ex)
{
spdlog::critical("Exception on working thread occured: {}", ex.what());
}
end_of_work();
spdlog::debug("Application: working thread is finished");
};
working_thread_ = std::thread{ monitoring_action };
working_thread_ = std::jthread{ monitoring_action };
}

void App::end_of_work() const
Expand All @@ -51,10 +67,16 @@ namespace srs
void App::exit()
{
signal_set_.cancel();
status_.is_on_exit.store(true);
data_processor_->stop();
data_reader_->close();
spdlog::debug("Shutting down application ...");
status_.is_on_exit.store(true);
status_.wait_for_status([](const auto& status) { return not status.is_reading.load(); });
status_.wait_for_status(
[](const auto& status)
{
spdlog::debug("Waiting for reading status false");
return not status.is_reading.load();
});

if (status_.is_acq_on.load())
{
Expand All @@ -65,8 +87,9 @@ namespace srs
{
set_status_acq_off(true);
}
set_status_acq_on(false);
io_work_guard_.reset();
set_status_acq_on(false);
spdlog::debug("Application is exited");
}

void App::set_print_mode(DataPrintMode mode) { data_processor_->set_print_mode(mode); }
Expand All @@ -86,7 +109,7 @@ namespace srs
void App::switch_on()
{
auto connection_info = ConnectionInfo{ this };
connection_info.local_port_number = FEC_CONTROL_LOCAL_PORT;
connection_info.local_port_number = configurations_.fec_control_local_port;
auto connection = std::make_shared<Starter>(connection_info);
connection->set_remote_endpoint(remote_endpoint_);
connection->acq_on();
Expand All @@ -95,7 +118,7 @@ namespace srs
void App::switch_off()
{
auto connection_info = ConnectionInfo{ this };
connection_info.local_port_number = FEC_CONTROL_LOCAL_PORT;
connection_info.local_port_number = configurations_.fec_control_local_port;
auto connection = std::make_shared<Stopper>(connection_info);
connection->set_remote_endpoint(remote_endpoint_);
connection->acq_off();
Expand All @@ -104,14 +127,11 @@ namespace srs
void App::read_data()
{
auto connection_info = ConnectionInfo{ this };
connection_info.local_port_number = FEC_DAQ_RECEIVE_PORT;
auto data_reader = std::make_shared<DataReader>(connection_info, data_processor_.get());
data_reader->start();
connection_info.local_port_number = configurations_.fec_data_receive_port;
data_reader_ = std::make_shared<DataReader>(connection_info, data_processor_.get());
data_reader_->start();
}

void App::run()
{
data_processor_->start();
working_thread_.join();
}
void App::start_analysis() { data_processor_->start(); }
void App::wait_for_finish() { working_thread_.join(); }
} // namespace srs
22 changes: 16 additions & 6 deletions backend/srs/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include <boost/asio/signal_set.hpp>
#include <boost/asio/thread_pool.hpp>
// #include <srs/devices/Fec.hpp>
#include <srs/devices/Configuration.hpp>
#include <srs/utils/AppStatus.hpp>
#include <thread>
#include <srs/utils/CommonAlias.hpp>
#include <thread>

namespace srs
{
class DataProcessor;
class DataReader;

class App
{
Expand All @@ -21,47 +23,55 @@ namespace srs
App(App&&) = delete;
App& operator=(const App&) = delete;
App& operator=(App&&) = delete;
~App();
~App() noexcept;

// public APIs
void configure_fec() {}
void switch_on();
void switch_off();
void read_data();

void notify_status_change() { status_.status_change.notify_all(); }
void run();
void start_analysis();
void exit();
void wait_for_finish();
void wait_for_status(auto&& condition, std::chrono::seconds time_duration = DEFAULT_STATUS_WAITING_TIME_SECONDS)
{
status_.wait_for_status(std::forward<decltype(condition)>(condition), time_duration);
}

// setters:
void set_remote_endpoint(std::string_view remote_ip, int port_number);
void set_fec_data_receiv_port(int port_num) { configurations_.fec_data_receive_port = port_num; }
void set_status_acq_on(bool val = true) { status_.is_acq_on.store(val); }
void set_status_acq_off(bool val = true) { status_.is_acq_off.store(val); }
void set_status_is_reading(bool val = true) { status_.is_reading.store(val); }
void set_print_mode(DataPrintMode mode);
void set_output_filenames(const std::vector<std::string>& filenames);
void set_error_string(std::string_view err_msg) { error_string_ = err_msg; }

// getters:
[[nodiscard]] auto get_channel_address() const -> uint16_t { return channel_address_; }
// [[nodiscard]] auto get_fec_config() const -> const auto& { return fec_config_; }
[[nodiscard]] auto get_status() const -> const auto& { return status_; }
[[nodiscard]] auto get_io_context() -> auto& { return io_context_; }
auto get_data_reader() -> DataReader* { return data_reader_.get(); }
[[nodiscard]] auto get_error_string() const -> const std::string& { return error_string_; }

private:
using udp = asio::ip::udp;

Status status_;
uint16_t channel_address_ = DEFAULT_CHANNEL_ADDRE;
// fec::Config fec_config_;
std::unique_ptr<DataProcessor> data_processor_;
Config configurations_;
std::string error_string_;
io_context_type io_context_{ 4 };
asio::executor_work_guard<io_context_type::executor_type> io_work_guard_;
asio::signal_set signal_set_{ io_context_, SIGINT, SIGTERM };
std::thread working_thread_;
std::jthread working_thread_;
udp::endpoint remote_endpoint_;
std::unique_ptr<DataProcessor> data_processor_;
std::shared_ptr<DataReader> data_reader_;

void start_work();
void end_of_work() const;
Expand Down
1 change: 1 addition & 0 deletions backend/srs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_subdirectory(data)
add_subdirectory(converters)
add_subdirectory(writers)
add_subdirectory(readers)
add_subdirectory(devices)
add_subdirectory(analysis)

target_sources(
Expand Down
4 changes: 2 additions & 2 deletions backend/srs/analysis/DataProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace srs

if (is_stopped)
{
spdlog::info("Shutting down all data writers...");
spdlog::debug("Shutting down all data writers...");
}

auto make_writer_future = [&](auto& writer)
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace srs
writers_.wait_for_finished();
if (is_stopped)
{
spdlog::debug("All data writers are shutdown.");
spdlog::info("All data writers are shutdown.");
}
}

Expand Down
Loading

0 comments on commit 15c3a72

Please sign in to comment.