Skip to content

Commit

Permalink
add test data and test report
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW committed Nov 20, 2024
1 parent b475f1d commit 992dd13
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 25 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ 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: mikepenz/action-junit-report@v5
if: success() || failure()
with:
report_paths: 'build/bin/test_detail.xml'

- 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
27 changes: 17 additions & 10 deletions backend/srs/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ namespace srs
{
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");
};
Expand Down
3 changes: 3 additions & 0 deletions backend/srs/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ namespace srs
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;
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 };
Expand Down
4 changes: 3 additions & 1 deletion backend/srs/analysis/DataProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ namespace srs
catch (tbb::user_abort& ex)
{
spdlog::debug("Data processing: {}", ex.what());
app_->set_error_string(ex.what());
}
catch (std::exception& ex)
{
spdlog::critical("Exception occured: {}", ex.what());
app_->exit();
app_->set_error_string(ex.what());
// app_->exit();
}
spdlog::debug("Analysis loop is stopped");
}
Expand Down
4 changes: 4 additions & 0 deletions backend/srs/converters/DataConvertOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <print>
#include <string_view>

namespace srs
Expand Down Expand Up @@ -69,6 +70,9 @@ namespace srs

constexpr auto convert_option_has_dependency(DataConvertOptions dependee, DataConvertOptions depender) -> bool
{
std::println("-----------dependee: {}, depender: {}",
convert_option_to_string(dependee),
convert_option_to_string(dependee));
if (dependee == depender)
{
return true;
Expand Down
1 change: 1 addition & 0 deletions backend/srs/utils/AppStatus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace srs
std::atomic<bool> is_reading = false;
std::atomic<bool> is_acq_off = false;
std::atomic<bool> is_on_exit = false;
// std::atomic<bool> is_already_exit = false;
std::condition_variable status_change;

void wait_for_status(auto&& condition, std::chrono::seconds time_duration = DEFAULT_STATUS_WAITING_TIME_SECONDS)
Expand Down
11 changes: 7 additions & 4 deletions backend/srs/utils/ConnectionBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace srs
udp::endpoint remote_endpoint_;
SerializableMsgBuffer write_msg_buffer_;
std::span<const char> continuous_send_msg_;
std::unique_ptr<asio::signal_set> signal_set_;
ReadBufferType<buffer_size> read_msg_buffer_{};
int timeout_seconds_ = DEFAULT_TIMEOUT_SECONDS;

Expand Down Expand Up @@ -130,10 +131,8 @@ namespace srs
co_return;
}

spdlog::trace("reading messages ...");
auto receive_data_size = co_await connection->socket_->async_receive(
asio::buffer(connection->read_msg_buffer_), asio::use_awaitable);
spdlog::trace("Messages received");
auto read_msg = std::span{ connection->read_msg_buffer_.data(), receive_data_size };
connection->read_data_handle(read_msg);
// spdlog::info("Connection {}: received {} bytes data", connection->get_name(), read_msg.size());
Expand Down Expand Up @@ -169,9 +168,9 @@ namespace srs
template <int size>
auto ConnectionBase<size>::signal_handling(auto* connection) -> asio::awaitable<void>
{
auto interrupt_signal = asio::signal_set(co_await asio::this_coro::executor, SIGINT);
connection->signal_set_ = std::make_unique<asio::signal_set>(co_await asio::this_coro::executor, SIGINT);
spdlog::trace("Connection {}: waiting for signals", connection->get_name());
auto [error, sig_num] = co_await interrupt_signal.async_wait(asio::as_tuple(asio::use_awaitable));
auto [error, sig_num] = co_await connection->signal_set_->async_wait(asio::as_tuple(asio::use_awaitable));
if (error == asio::error::operation_aborted)
{
spdlog::trace("Connection {}: Signal ended with {}", connection->get_name(), error.message());
Expand Down Expand Up @@ -244,6 +243,10 @@ namespace srs
spdlog::trace("Connection {}: Closing the socket ...", name_);
socket_->cancel();
socket_->close();
if (signal_set_ != nullptr)
{
signal_set_->cancel();
}
spdlog::trace("Connection {}: Socket is closed and cancelled.", name_);
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
if(ENABLE_TEST)
add_subdirectory(backend)
endif()
add_subdirectory(backend)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/test_data.bin
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_data.bin COPYONLY USE_SOURCE_PERMISSIONS)
23 changes: 16 additions & 7 deletions test/backend/srs/TestOutputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace srs::test
{
namespace
{
void run_application(const std::string& output_filename)
void run_application(const std::string& output_filename, std::string& error_msg)
{
try
{
Expand All @@ -28,10 +28,11 @@ namespace srs::test
emulator.start_send_data();
app.exit();
app.wait_for_finish();
error_msg = app.get_error_string();
}
catch (const std::runtime_error& err)
catch (std::exception& ex)
{
spdlog::critical("Exception occurred: {}", err.what());
spdlog::critical("Exception occured: {}", ex.what());
}
}

Expand All @@ -55,15 +56,19 @@ namespace
TEST(check_outputs, binary_output)
{
const auto filename = std::string{ "test_output.bin" };
srs::test::run_application(filename);
auto error_msg = std::string{};
ASSERT_NO_THROW(srs::test::run_application(filename, error_msg));
EXPECT_EQ(error_msg, "");
auto res = check_if_file_exist(filename);
ASSERT_TRUE(res);
}

TEST(check_outputs, root_output)
{
const auto filename = std::string{ "test_output.root" };
srs::test::run_application(filename);
auto error_msg = std::string{};
ASSERT_NO_THROW(srs::test::run_application(filename, error_msg));
EXPECT_EQ(error_msg, "");
auto res = check_if_file_exist(filename);
#ifdef HAS_ROOT
ASSERT_TRUE(res);
Expand All @@ -75,15 +80,19 @@ TEST(check_outputs, root_output)
TEST(check_outputs, proto_binary)
{
const auto filename = std::string{ "test_output.binpb" };
srs::test::run_application(filename);
auto error_msg = std::string{};
ASSERT_NO_THROW(srs::test::run_application(filename, error_msg));
EXPECT_EQ(error_msg, "");
auto res = check_if_file_exist(filename);
ASSERT_TRUE(res);
}

TEST(check_outputs, json_output)

Check failure on line 90 in test/backend/srs/TestOutputs.cpp

View workflow job for this annotation

GitHub Actions / JUnit Test Report

/__w/srs-daq/srs-daq/test/backend/srs/TestOutputs.cpp.json_output

/__w/srs-daq/srs-daq/test/backend/srs/TestOutputs.cpp:95 Expected equality of these values: error_msg Which is: "Operation not permitted on an object without an associated state." ""
Raw output
/__w/srs-daq/srs-daq/test/backend/srs/TestOutputs.cpp:95
Expected equality of these values:
  error_msg
    Which is: "Operation not permitted on an object without an associated state."
  ""
{
const auto filename = std::string{ "test_output.json" };
srs::test::run_application(filename);
auto error_msg = std::string{};
ASSERT_NO_THROW(srs::test::run_application(filename, error_msg));
EXPECT_EQ(error_msg, "");
auto res = check_if_file_exist(filename);
#ifdef HAS_ROOT
ASSERT_TRUE(res);
Expand Down
Binary file added test/data/test_data.bin
Binary file not shown.

0 comments on commit 992dd13

Please sign in to comment.