2013-02-17 09:54:41 +00:00
|
|
|
/*!
|
|
|
|
* \file control_thread_test.cc
|
|
|
|
* \brief This file implements tests for the ControlThread.
|
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
* Carles Fernandez-Prades, 2013. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 16:57:15 +02:00
|
|
|
* -----------------------------------------------------------------------------
|
2013-02-17 09:54:41 +00:00
|
|
|
*
|
2020-12-30 13:35:06 +01:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2013-02-17 09:54:41 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 13:35:06 +01:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 01:20:02 +01:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2013-02-17 09:54:41 +00:00
|
|
|
*
|
2020-07-28 16:57:15 +02:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-23 09:45:03 +00:00
|
|
|
|
2019-07-17 15:56:30 +02:00
|
|
|
#include "channel_event.h"
|
|
|
|
#include "command_event.h"
|
2019-07-16 17:41:12 +02:00
|
|
|
#include "concurrent_queue.h"
|
2019-07-26 12:38:20 +02:00
|
|
|
#include "control_thread.h"
|
2024-12-19 09:26:19 +01:00
|
|
|
#include "gnss_sdr_filesystem.h"
|
2020-06-18 11:49:28 +02:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2018-12-09 22:00:09 +01:00
|
|
|
#include "in_memory_configuration.h"
|
|
|
|
#include <boost/exception/diagnostic_information.hpp>
|
|
|
|
#include <boost/exception_ptr.hpp>
|
2024-12-21 13:20:00 +01:00
|
|
|
#include <boost/interprocess/ipc/message_queue.hpp>
|
2018-12-09 22:00:09 +01:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
2019-07-17 15:56:30 +02:00
|
|
|
#include <pmt/pmt.h>
|
2016-10-16 10:40:07 +02:00
|
|
|
#include <chrono>
|
2014-03-23 09:45:03 +00:00
|
|
|
#include <exception>
|
2014-04-03 21:59:14 +00:00
|
|
|
#include <memory>
|
2016-10-16 10:40:07 +02:00
|
|
|
#include <thread>
|
2018-12-09 22:00:09 +01:00
|
|
|
#include <unistd.h>
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2024-04-29 08:27:33 +02:00
|
|
|
#if USE_GLOG_AND_GFLAGS
|
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
#else
|
|
|
|
#include <absl/log/log.h>
|
|
|
|
#endif
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2018-03-03 02:03:39 +01:00
|
|
|
class ControlThreadTest : public ::testing::Test
|
2016-10-16 10:40:07 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int stop_receiver();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-06-25 22:53:11 +02:00
|
|
|
int ControlThreadTest::stop_receiver()
|
2016-10-16 10:40:07 +02:00
|
|
|
{
|
2024-12-21 13:20:00 +01:00
|
|
|
const std::string queue_name = "receiver_control_queue";
|
|
|
|
std::unique_ptr<boost::interprocess::message_queue> d_mq;
|
|
|
|
try
|
2018-03-03 02:03:39 +01:00
|
|
|
{
|
2024-12-21 13:20:00 +01:00
|
|
|
bool queue_found = false;
|
|
|
|
|
|
|
|
while (!queue_found)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Attempt to open the message queue
|
|
|
|
d_mq = std::make_unique<boost::interprocess::message_queue>(boost::interprocess::open_only, queue_name.c_str());
|
|
|
|
queue_found = true; // Queue found
|
|
|
|
}
|
|
|
|
catch (const boost::interprocess::interprocess_exception&)
|
|
|
|
{
|
|
|
|
// Queue not found, wait and retry
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
}
|
|
|
|
}
|
2016-10-16 10:40:07 +02:00
|
|
|
|
|
|
|
|
2024-12-21 13:20:00 +01:00
|
|
|
double stop_message = -200.0;
|
2016-10-16 10:40:07 +02:00
|
|
|
|
2024-12-21 13:20:00 +01:00
|
|
|
// Wait for a couple of seconds before sending
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
|
// Send the double value
|
|
|
|
d_mq->send(&stop_message, sizeof(stop_message), 0); // Priority 0
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (const boost::interprocess::interprocess_exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to send stop message: " << e.what() << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-16 10:40:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-09 22:00:09 +01:00
|
|
|
TEST_F(ControlThreadTest /*unused*/, InstantiateRunControlMessages /*unused*/)
|
2013-02-17 09:54:41 +00:00
|
|
|
{
|
2014-04-03 21:59:14 +00:00
|
|
|
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
|
|
|
|
config->set_property("SignalSource.implementation", "File_Signal_Source");
|
2014-04-03 21:59:14 +00:00
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string file = path + "signal_samples/GSoC_CTTC_capture_2012_07_26_4Msps_4ms.dat";
|
2018-03-03 02:03:39 +01:00
|
|
|
const char* file_name = file.c_str();
|
2014-04-03 21:59:14 +00:00
|
|
|
config->set_property("SignalSource.filename", file_name);
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("SignalSource.item_type", "gr_complex");
|
|
|
|
config->set_property("SignalSource.sampling_frequency", "4000000");
|
|
|
|
config->set_property("SignalSource.repeat", "true");
|
|
|
|
config->set_property("SignalConditioner.implementation", "Pass_Through");
|
|
|
|
config->set_property("SignalConditioner.item_type", "gr_complex");
|
2016-04-25 16:03:57 +02:00
|
|
|
config->set_property("Channels_1C.count", "2");
|
|
|
|
config->set_property("Channels_1E.count", "0");
|
2014-12-21 22:46:57 +01:00
|
|
|
config->set_property("Channels.in_acquisition", "1");
|
2016-04-25 16:03:57 +02:00
|
|
|
config->set_property("Acquisition_1C.implementation", "GPS_L1_CA_PCPS_Acquisition");
|
|
|
|
config->set_property("Acquisition_1C.threshold", "1");
|
|
|
|
config->set_property("Acquisition_1C.doppler_max", "5000");
|
|
|
|
config->set_property("Acquisition_1C.doppler_min", "-5000");
|
|
|
|
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
|
|
|
|
config->set_property("Tracking_1C.item_type", "gr_complex");
|
|
|
|
config->set_property("TelemetryDecoder_1C.implementation", "GPS_L1_CA_Telemetry_Decoder");
|
|
|
|
config->set_property("TelemetryDecoder_1C.item_type", "gr_complex");
|
2017-04-12 17:04:51 +02:00
|
|
|
config->set_property("Observables.implementation", "Hybrid_Observables");
|
2013-07-04 13:47:40 +00:00
|
|
|
config->set_property("Observables.item_type", "gr_complex");
|
2017-07-12 21:25:15 +02:00
|
|
|
config->set_property("PVT.implementation", "RTKLIB_PVT");
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("PVT.item_type", "gr_complex");
|
2018-02-20 15:44:45 +01:00
|
|
|
config->set_property("GNSS-SDR.internal_fs_sps", "4000000");
|
2013-02-17 09:54:41 +00:00
|
|
|
|
2024-12-19 09:26:19 +01:00
|
|
|
ASSERT_TRUE(fs::exists(file));
|
|
|
|
|
2014-12-21 22:46:57 +01:00
|
|
|
std::shared_ptr<ControlThread> control_thread = std::make_shared<ControlThread>(config);
|
2013-02-17 09:54:41 +00:00
|
|
|
|
2019-07-17 15:56:30 +02:00
|
|
|
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
|
|
|
|
control_queue->push(pmt::make_any(channel_event_make(0, 0)));
|
|
|
|
control_queue->push(pmt::make_any(channel_event_make(1, 0)));
|
|
|
|
control_queue->push(pmt::make_any(command_event_make(200, 0)));
|
2013-02-17 09:54:41 +00:00
|
|
|
|
|
|
|
control_thread->set_control_queue(control_queue);
|
2014-03-23 09:45:03 +00:00
|
|
|
try
|
2018-03-03 02:03:39 +01:00
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
control_thread->run();
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const boost::exception& e)
|
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
std::cout << "Boost exception: " << boost::diagnostic_information(e);
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cout << "STD exception: " << ex.what();
|
|
|
|
}
|
2014-03-23 09:45:03 +00:00
|
|
|
|
2014-12-24 11:22:01 +01:00
|
|
|
unsigned int expected3 = 3;
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int expected1 = 1;
|
2014-12-24 11:22:01 +01:00
|
|
|
EXPECT_EQ(expected3, control_thread->processed_control_messages());
|
|
|
|
EXPECT_EQ(expected1, control_thread->applied_actions());
|
2020-06-27 09:52:59 +02:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 00:52:05 +00:00
|
|
|
|
2018-12-09 22:00:09 +01:00
|
|
|
TEST_F(ControlThreadTest /*unused*/, InstantiateRunControlMessages2 /*unused*/)
|
2013-02-17 09:54:41 +00:00
|
|
|
{
|
2014-04-03 21:59:14 +00:00
|
|
|
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("SignalSource.implementation", "File_Signal_Source");
|
2014-04-03 21:59:14 +00:00
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string file = path + "signal_samples/GSoC_CTTC_capture_2012_07_26_4Msps_4ms.dat";
|
2018-03-03 02:03:39 +01:00
|
|
|
const char* file_name = file.c_str();
|
2014-04-03 21:59:14 +00:00
|
|
|
config->set_property("SignalSource.filename", file_name);
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("SignalSource.item_type", "gr_complex");
|
|
|
|
config->set_property("SignalSource.sampling_frequency", "4000000");
|
2014-03-23 09:45:03 +00:00
|
|
|
config->set_property("SignalSource.repeat", "true");
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("SignalConditioner.implementation", "Pass_Through");
|
|
|
|
config->set_property("SignalConditioner.item_type", "gr_complex");
|
2016-04-25 16:03:57 +02:00
|
|
|
config->set_property("Channels_1C.count", "4");
|
|
|
|
config->set_property("Channels_1E.count", "0");
|
2014-12-24 11:22:01 +01:00
|
|
|
config->set_property("Channels.in_acquisition", "1");
|
2016-04-25 16:03:57 +02:00
|
|
|
config->set_property("Acquisition_1C.implementation", "GPS_L1_CA_PCPS_Acquisition");
|
|
|
|
config->set_property("Acquisition_1C.threshold", "1");
|
|
|
|
config->set_property("Acquisition_1C.doppler_max", "5000");
|
|
|
|
config->set_property("Acquisition_1C.doppler_min", "-5000");
|
2019-06-11 10:11:20 +02:00
|
|
|
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
|
2016-04-25 16:03:57 +02:00
|
|
|
config->set_property("Tracking_1C.item_type", "gr_complex");
|
|
|
|
config->set_property("TelemetryDecoder_1C.implementation", "GPS_L1_CA_Telemetry_Decoder");
|
|
|
|
config->set_property("TelemetryDecoder_1C.item_type", "gr_complex");
|
2017-04-12 17:04:51 +02:00
|
|
|
config->set_property("Observables.implementation", "Hybrid_Observables");
|
2013-07-04 13:47:40 +00:00
|
|
|
config->set_property("Observables.item_type", "gr_complex");
|
2017-07-12 21:25:15 +02:00
|
|
|
config->set_property("PVT.implementation", "RTKLIB_PVT");
|
2013-02-17 09:54:41 +00:00
|
|
|
config->set_property("PVT.item_type", "gr_complex");
|
2018-02-20 15:44:45 +01:00
|
|
|
config->set_property("GNSS-SDR.internal_fs_sps", "4000000");
|
2013-02-17 09:54:41 +00:00
|
|
|
|
2024-12-19 09:26:19 +01:00
|
|
|
ASSERT_TRUE(fs::exists(file));
|
|
|
|
|
2020-06-18 11:49:28 +02:00
|
|
|
auto control_thread2 = std::make_unique<ControlThread>(config);
|
2019-07-17 15:56:30 +02:00
|
|
|
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue2 = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
|
2014-03-23 09:45:03 +00:00
|
|
|
|
2019-07-17 15:56:30 +02:00
|
|
|
control_queue2->push(pmt::make_any(channel_event_make(0, 0)));
|
|
|
|
control_queue2->push(pmt::make_any(channel_event_make(2, 0)));
|
|
|
|
control_queue2->push(pmt::make_any(channel_event_make(1, 0)));
|
|
|
|
control_queue2->push(pmt::make_any(channel_event_make(3, 0)));
|
|
|
|
control_queue2->push(pmt::make_any(command_event_make(200, 0)));
|
2014-03-23 09:45:03 +00:00
|
|
|
|
|
|
|
control_thread2->set_control_queue(control_queue2);
|
|
|
|
|
|
|
|
try
|
2018-03-03 02:03:39 +01:00
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
control_thread2->run();
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const boost::exception& e)
|
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
std::cout << "Boost exception: " << boost::diagnostic_information(e);
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cout << "STD exception: " << ex.what();
|
|
|
|
}
|
2013-02-17 09:54:41 +00:00
|
|
|
|
2014-12-24 11:22:01 +01:00
|
|
|
unsigned int expected5 = 5;
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int expected1 = 1;
|
2014-12-24 11:22:01 +01:00
|
|
|
EXPECT_EQ(expected5, control_thread2->processed_control_messages());
|
|
|
|
EXPECT_EQ(expected1, control_thread2->applied_actions());
|
2020-06-27 09:52:59 +02:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
2016-10-16 10:40:07 +02:00
|
|
|
|
|
|
|
|
2018-12-09 22:00:09 +01:00
|
|
|
TEST_F(ControlThreadTest /*unused*/, StopReceiverProgrammatically /*unused*/)
|
2016-10-16 10:40:07 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
|
|
|
|
config->set_property("SignalSource.implementation", "File_Signal_Source");
|
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string file = path + "signal_samples/GSoC_CTTC_capture_2012_07_26_4Msps_4ms.dat";
|
2018-03-03 02:03:39 +01:00
|
|
|
const char* file_name = file.c_str();
|
2016-10-16 10:40:07 +02:00
|
|
|
config->set_property("SignalSource.filename", file_name);
|
|
|
|
config->set_property("SignalSource.item_type", "gr_complex");
|
|
|
|
config->set_property("SignalSource.sampling_frequency", "4000000");
|
|
|
|
config->set_property("SignalSource.repeat", "true");
|
|
|
|
config->set_property("SignalConditioner.implementation", "Pass_Through");
|
|
|
|
config->set_property("SignalConditioner.item_type", "gr_complex");
|
|
|
|
config->set_property("Channels_1C.count", "4");
|
|
|
|
config->set_property("Channels_1E.count", "0");
|
|
|
|
config->set_property("Channels.in_acquisition", "1");
|
|
|
|
config->set_property("Acquisition_1C.implementation", "GPS_L1_CA_PCPS_Acquisition");
|
|
|
|
config->set_property("Acquisition_1C.threshold", "1");
|
|
|
|
config->set_property("Acquisition_1C.doppler_max", "5000");
|
|
|
|
config->set_property("Acquisition_1C.doppler_min", "-5000");
|
2019-06-11 10:11:20 +02:00
|
|
|
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
|
2016-10-16 10:40:07 +02:00
|
|
|
config->set_property("Tracking_1C.item_type", "gr_complex");
|
|
|
|
config->set_property("TelemetryDecoder_1C.implementation", "GPS_L1_CA_Telemetry_Decoder");
|
|
|
|
config->set_property("TelemetryDecoder_1C.item_type", "gr_complex");
|
2017-04-12 17:04:51 +02:00
|
|
|
config->set_property("Observables.implementation", "Hybrid_Observables");
|
2016-10-16 10:40:07 +02:00
|
|
|
config->set_property("Observables.item_type", "gr_complex");
|
2017-07-12 21:25:15 +02:00
|
|
|
config->set_property("PVT.implementation", "RTKLIB_PVT");
|
2016-10-16 10:40:07 +02:00
|
|
|
config->set_property("PVT.item_type", "gr_complex");
|
2018-02-20 15:44:45 +01:00
|
|
|
config->set_property("GNSS-SDR.internal_fs_sps", "4000000");
|
2016-10-16 10:40:07 +02:00
|
|
|
|
2024-12-19 09:26:19 +01:00
|
|
|
ASSERT_TRUE(fs::exists(file));
|
|
|
|
|
2017-07-12 10:01:20 +02:00
|
|
|
std::shared_ptr<ControlThread> control_thread = std::make_shared<ControlThread>(config);
|
2019-07-17 15:56:30 +02:00
|
|
|
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> control_queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
|
2016-10-16 10:40:07 +02:00
|
|
|
control_thread->set_control_queue(control_queue);
|
|
|
|
|
|
|
|
std::thread stop_receiver_thread(stop_receiver);
|
|
|
|
|
|
|
|
try
|
2018-03-03 02:03:39 +01:00
|
|
|
{
|
2016-10-16 10:40:07 +02:00
|
|
|
control_thread->run();
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const boost::exception& e)
|
|
|
|
{
|
2016-10-16 10:40:07 +02:00
|
|
|
std::cout << "Boost exception: " << boost::diagnostic_information(e);
|
2018-03-03 02:03:39 +01:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cout << "STD exception: " << ex.what();
|
|
|
|
}
|
2016-10-16 10:40:07 +02:00
|
|
|
|
|
|
|
stop_receiver_thread.join();
|
2020-07-05 20:20:02 +02:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
2016-10-16 10:40:07 +02:00
|
|
|
}
|