From 8bbe4edc6429bf2150e883d025d30a54c34a309b Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 24 Aug 2017 18:09:04 +0200 Subject: [PATCH] Replace library by and also replace C-style casts by C++ casts. Added/removed some blank lines here and there to match coding style of other tests. --- ...ss_l1_ca_pcps_acquisition_gsoc2017_test.cc | 76 +++++++++++-------- .../glonass_l1_ca_pcps_acquisition_test.cc | 35 ++++----- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_gsoc2017_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_gsoc2017_test.cc index a346cf12f..434e37d23 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_gsoc2017_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_gsoc2017_test.cc @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -72,6 +72,7 @@ GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx::GlonassL1CaPcpsAcquisitionGSoC201 rx_message = 0; } + GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx::~GlonassL1CaPcpsAcquisitionGSoC2017Test_msg_rx() {} @@ -138,6 +139,7 @@ protected: double Pfa_a; }; + void GlonassL1CaPcpsAcquisitionGSoC2017Test::init() { message = 0; @@ -153,6 +155,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::init() Pfa_a = 0; } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_1() { gnss_synchro.Channel_ID = 0; @@ -222,6 +225,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_1() config->set_property("Acquisition.dump", "false"); } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_2() { gnss_synchro.Channel_ID = 0; @@ -309,12 +313,14 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::config_2() config->set_property("Acquisition.dump", "false"); } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::start_queue() { stop = false; ch_thread = boost::thread(&GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message, this); } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message() { struct timeval tv; @@ -339,6 +345,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::wait_message() } } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message() { if (message == 1) @@ -347,7 +354,7 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message() // The term -5 is here to correct the additional delay introduced by the FIR filter // The value 511.0 must be a variable, chips/length - double delay_error_chips = std::abs((double)expected_delay_chips - (double)(gnss_synchro.Acq_delay_samples-5)*511.0/((double)fs_in*1e-3)); + double delay_error_chips = std::abs(static_cast(expected_delay_chips) - (static_cast(gnss_synchro.Acq_delay_samples) - 5.0 ) * 511.0 / (static_cast(fs_in) * 1e-3)); double doppler_error_hz = std::abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); mse_delay += std::pow(delay_error_chips, 2); @@ -361,16 +368,16 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message() realization_counter++; - std::cout << "Progress: " << round((float)realization_counter/num_of_realizations*100) << "% \r" << std::flush; + std::cout << "Progress: " << round(static_cast(realization_counter) / static_cast(num_of_realizations) * 100.0) << "% \r" << std::flush; if (realization_counter == num_of_realizations) { mse_delay /= num_of_realizations; mse_doppler /= num_of_realizations; - Pd = (double)correct_estimation_counter / (double)num_of_realizations; - Pfa_a = (double)detection_counter / (double)num_of_realizations; - Pfa_p = (double)(detection_counter - correct_estimation_counter) / (double)num_of_realizations; + Pd = static_cast(correct_estimation_counter) / static_cast(num_of_realizations); + Pfa_a = static_cast(detection_counter) / static_cast(num_of_realizations); + Pfa_p = (static_cast(detection_counter) - static_cast( correct_estimation_counter)) / static_cast(num_of_realizations); mean_acq_time_us /= num_of_realizations; @@ -379,11 +386,13 @@ void GlonassL1CaPcpsAcquisitionGSoC2017Test::process_message() } } + void GlonassL1CaPcpsAcquisitionGSoC2017Test::stop_queue() { stop = true; } + TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, Instantiate) { config_1(); @@ -391,12 +400,12 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, Instantiate) delete acquisition; } + TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ConnectAndRun) { - int nsamples = floor(fs_in*integration_time_ms*1e-3); - struct timeval tv; - long long int begin = 0; - long long int end = 0; + int nsamples = floor(fs_in * integration_time_ms * 1e-3); + std::chrono::time_point begin, end; + std::chrono::duration elapsed_seconds(0); queue = gr::msg_queue::make(0); top_block = gr::make_top_block("Acquisition test"); @@ -414,18 +423,18 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ConnectAndRun) }) << "Failure connecting the blocks of acquisition test."<< std::endl; EXPECT_NO_THROW( { - gettimeofday(&tv, NULL); - begin = tv.tv_sec *1e6 + tv.tv_usec; + begin = std::chrono::system_clock::now(); top_block->run(); // Start threads and wait - gettimeofday(&tv, NULL); - end = tv.tv_sec *1e6 + tv.tv_usec; + end = std::chrono::system_clock::now(); + elapsed_seconds = end - begin; }) << "Failure running the top_block."<< std::endl; - std::cout << "Processed " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; + std::cout << "Processed " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; delete acquisition; } + TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults) { config_1(); @@ -495,18 +504,18 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults) }) << "Failure running the top_block."<< std::endl; if (i == 0) - { - EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; - if (message == 1) - { - EXPECT_EQ((unsigned int) 1, correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; - } + { + EXPECT_EQ(1, message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; + if (message == 1) + { + EXPECT_EQ(static_cast(1), correct_estimation_counter) << "Acquisition failure. Incorrect parameters estimation."; + } - } + } else if (i == 1) - { - EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; - } + { + EXPECT_EQ(2, message) << "Acquisition failure. Expected message: 2=ACQ FAIL."; + } #ifdef OLD_BOOST ASSERT_NO_THROW( { ch_thread.timed_join(boost::posix_time::seconds(1)); @@ -522,6 +531,7 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResults) delete acquisition; } + TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResultsProbabilities) { config_2(); @@ -592,15 +602,15 @@ TEST_F(GlonassL1CaPcpsAcquisitionGSoC2017Test, ValidationOfResultsProbabilities) }) << "Failure running the top_block."<< std::endl; if (i == 0) - { - std::cout << "Estimated probability of detection = " << Pd << std::endl; - std::cout << "Estimated probability of false alarm (satellite present) = " << Pfa_p << std::endl; - std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; } + { + std::cout << "Estimated probability of detection = " << Pd << std::endl; + std::cout << "Estimated probability of false alarm (satellite present) = " << Pfa_p << std::endl; + std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; } else if (i == 1) - { - std::cout << "Estimated probability of false alarm (satellite absent) = " << Pfa_a << std::endl; - std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; - } + { + std::cout << "Estimated probability of false alarm (satellite absent) = " << Pfa_a << std::endl; + std::cout << "Mean acq time = " << mean_acq_time_us << " microseconds." << std::endl; + } #ifdef OLD_BOOST ASSERT_NO_THROW( { ch_thread.timed_join(boost::posix_time::seconds(1)); diff --git a/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_test.cc b/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_test.cc index 1a29bda80..902fcdf00 100644 --- a/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/acquisition/glonass_l1_ca_pcps_acquisition_test.cc @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -119,20 +119,19 @@ void GlonassL1CaPcpsAcquisitionTest::init() } - TEST_F(GlonassL1CaPcpsAcquisitionTest, Instantiate) { init(); boost::shared_ptr acquisition = boost::make_shared(config.get(), "Acquisition", 1, 1); } + TEST_F(GlonassL1CaPcpsAcquisitionTest, ConnectAndRun) { int fs_in = 62314000; int nsamples = 62314; - struct timeval tv; - long long int begin = 0; - long long int end = 0; + std::chrono::time_point begin, end; + std::chrono::duration elapsed_seconds(0); gr::msg_queue::sptr queue = gr::msg_queue::make(0); top_block = gr::make_top_block("Acquisition test"); @@ -151,21 +150,20 @@ TEST_F(GlonassL1CaPcpsAcquisitionTest, ConnectAndRun) }) << "Failure connecting the blocks of acquisition test." << std::endl; EXPECT_NO_THROW( { - gettimeofday(&tv, NULL); - begin = tv.tv_sec * 1000000 + tv.tv_usec; + begin = std::chrono::system_clock::now(); top_block->run(); // Start threads and wait - gettimeofday(&tv, NULL); - end = tv.tv_sec * 1000000 + tv.tv_usec; + end = std::chrono::system_clock::now(); + elapsed_seconds = end - begin; }) << "Failure running the top_block." << std::endl; - std::cout << "Processed " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; + std::cout << "Processed " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; } + TEST_F(GlonassL1CaPcpsAcquisitionTest, ValidationOfResults) { - struct timeval tv; - long long int begin = 0; - long long int end = 0; + std::chrono::time_point begin, end; + std::chrono::duration elapsed_seconds(0); top_block = gr::make_top_block("Acquisition test"); double expected_delay_samples = 31874; @@ -213,21 +211,20 @@ TEST_F(GlonassL1CaPcpsAcquisitionTest, ValidationOfResults) acquisition->init(); EXPECT_NO_THROW( { - gettimeofday(&tv, NULL); - begin = tv.tv_sec * 1000000 + tv.tv_usec; + begin = std::chrono::system_clock::now(); top_block->run(); // Start threads and wait - gettimeofday(&tv, NULL); - end = tv.tv_sec * 1000000 + tv.tv_usec; + end = std::chrono::system_clock::now(); + elapsed_seconds = end - begin; }) << "Failure running the top_block." << std::endl; unsigned long int nsamples = gnss_synchro.Acq_samplestamp_samples; - std::cout << "Acquired " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl; + std::cout << "Acquired " << nsamples << " samples in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; ASSERT_EQ(1, msg_rx->rx_message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS."; double delay_error_samples = std::abs(expected_delay_samples - gnss_synchro.Acq_delay_samples); - float delay_error_chips = (float)(delay_error_samples * 511 / 62316); + float delay_error_chips = static_cast(delay_error_samples) * 511.0 / 62316.0; double doppler_error_hz = std::abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz); EXPECT_LE(doppler_error_hz, 666) << "Doppler error exceeds the expected value: 666 Hz = 2/(3*integration period)";