diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 4bf0c8979..21ff8e9bb 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -125,6 +125,8 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-rrlp ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-supl ${CMAKE_SOURCE_DIR}/src/algorithms/libs + ${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/adapters + ${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/gnuradio_blocks ${CMAKE_SOURCE_DIR}/src/algorithms/resampler/gnuradio_blocks ${CMAKE_SOURCE_DIR}/src/algorithms/channel/adapters ${CMAKE_SOURCE_DIR}/src/algorithms/channel/libs diff --git a/src/tests/gnss_block/fir_filter_test.cc b/src/tests/gnss_block/fir_filter_test.cc index 5f3747bc0..25b365d16 100644 --- a/src/tests/gnss_block/fir_filter_test.cc +++ b/src/tests/gnss_block/fir_filter_test.cc @@ -28,12 +28,15 @@ * ------------------------------------------------------------------------- */ +#include #include #include +#include #include #include #include #include +#include #include #include #include @@ -41,8 +44,11 @@ #include "gnss_block_interface.h" #include "in_memory_configuration.h" #include "gnss_sdr_valve.h" +#include "interleaved_byte_to_complex_byte.h" +#include "interleaved_short_to_complex_short.h" #include "fir_filter.h" + DEFINE_string(filter_test_output_filename, std::string(TEST_PATH) + "data/fir_filter_test_output.dat", "Dump filename"); class Fir_Filter_Test: public ::testing::Test @@ -51,24 +57,27 @@ protected: Fir_Filter_Test() { queue = gr::msg_queue::make(0); - top_block = gr::make_top_block("Fir filter test"); config = std::make_shared(); - item_size = sizeof(gr_complex); } ~Fir_Filter_Test() {} void init(); + void configure_cbyte_cbyte(); + void configure_cbyte_gr_complex(); + void configure_gr_complex_gr_complex(); + void configure_cshort_cshort(); boost::shared_ptr queue; gr::top_block_sptr top_block; std::shared_ptr config; size_t item_size; + int nsamples = 10000000; }; void Fir_Filter_Test::init() { - - config->set_property("InputFilter.number_of_taps", "4"); + config->set_property("InputFilter.taps_item_type", "float"); + config->set_property("InputFilter.number_of_taps", "5"); config->set_property("InputFilter.number_of_bands", "2"); config->set_property("InputFilter.band1_begin", "0.0"); @@ -89,29 +98,83 @@ void Fir_Filter_Test::init() //config->set_property("InputFilter.dump", "true"); } +void Fir_Filter_Test::configure_cbyte_cbyte() +{ + config->set_property("InputFilter.input_item_type", "cbyte"); + config->set_property("InputFilter.output_item_type", "cbyte"); +} -TEST_F(Fir_Filter_Test, Instantiate) +void Fir_Filter_Test::configure_gr_complex_gr_complex() +{ + config->set_property("InputFilter.input_item_type", "gr_complex"); + config->set_property("InputFilter.output_item_type", "gr_complex"); +} + +void Fir_Filter_Test::configure_cshort_cshort() +{ + config->set_property("InputFilter.input_item_type", "cshort"); + config->set_property("InputFilter.output_item_type", "cshort"); +} + +void Fir_Filter_Test::configure_cbyte_gr_complex() +{ + config->set_property("InputFilter.input_item_type", "cbyte"); + config->set_property("InputFilter.output_item_type", "gr_complex"); +} + + +TEST_F(Fir_Filter_Test, Instantiate_gr_complex_gr_complex) { init(); + configure_gr_complex_gr_complex(); std::unique_ptr filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue)); int res = 0; if (filter) res = 1; ASSERT_EQ(1, res); } +TEST_F(Fir_Filter_Test, Instantiate_cshort_cshort) +{ + init(); + configure_cshort_cshort(); + std::unique_ptr filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue)); + int res = 0; + if (filter) res = 1; + ASSERT_EQ(1, res); +} + +TEST_F(Fir_Filter_Test, Instantiate_cbyte_cbyte) +{ + init(); + configure_cbyte_cbyte(); + std::unique_ptr filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue)); + int res = 0; + if (filter) res = 1; + ASSERT_EQ(1, res); +} + +TEST_F(Fir_Filter_Test, Instantiate_cbyte_gr_complex) +{ + init(); + configure_cbyte_gr_complex(); + std::unique_ptr filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue)); + int res = 0; + if (filter) res = 1; + ASSERT_EQ(1, res); +} TEST_F(Fir_Filter_Test, ConnectAndRun) { - int fs_in = 8000000; - int nsamples = 10000000; + int fs_in = 4000000; struct timeval tv; long long int begin = 0; long long int end = 0; + top_block = gr::make_top_block("Fir filter test"); init(); - + configure_gr_complex_gr_complex(); std::shared_ptr filter = std::make_shared(config.get(), "InputFilter", 1, 1, queue); - + item_size = sizeof(gr_complex); ASSERT_NO_THROW( { filter->connect(top_block); boost::shared_ptr source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); @@ -132,3 +195,142 @@ TEST_F(Fir_Filter_Test, ConnectAndRun) }) << "Failure running the top_block." << std::endl; std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; } + + +TEST_F(Fir_Filter_Test, ConnectAndRunCshorts) +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + top_block = gr::make_top_block("Fir filter test"); + + init(); + configure_cshort_cshort(); + std::shared_ptr filter = std::make_shared(config.get(), "InputFilter", 1, 1, queue); + std::shared_ptr config2 = std::make_shared(); + + config2->set_property("Test_Source.samples", "1000000"); + config2->set_property("Test_Source.sampling_frequency", "4000000"); + std::string path = std::string(TEST_PATH); + std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; + config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.item_type", "ishort"); + config2->set_property("Test_Source.repeat", "true"); + + item_size = sizeof(std::complex); + ASSERT_NO_THROW( { + filter->connect(top_block); + + boost::shared_ptr source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue)); + source->connect(top_block); + + interleaved_short_to_complex_short_sptr ishort_to_cshort_ = make_interleaved_short_to_complex_short(); + boost::shared_ptr null_sink = gr::blocks::null_sink::make(item_size); + + top_block->connect(source->get_right_block(), 0, ishort_to_cshort_, 0); + top_block->connect(ishort_to_cshort_, 0, filter->get_left_block(), 0); + top_block->connect(filter->get_right_block(), 0, null_sink, 0); + }) << "Failure connecting the top_block."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1000000 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1000000 + tv.tv_usec; + }) << "Failure running the top_block." << std::endl; + std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; +} + + + +TEST_F(Fir_Filter_Test, ConnectAndRunCbytes) +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + top_block = gr::make_top_block("Fir filter test"); + + init(); + configure_cbyte_cbyte(); + std::shared_ptr filter = std::make_shared(config.get(), "InputFilter", 1, 1, queue); + std::shared_ptr config2 = std::make_shared(); + + config2->set_property("Test_Source.samples", "1000000"); + config2->set_property("Test_Source.sampling_frequency", "4000000"); + std::string path = std::string(TEST_PATH); + std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; + config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.item_type", "ibyte"); + config2->set_property("Test_Source.repeat", "true"); + + item_size = sizeof(std::complex); + ASSERT_NO_THROW( { + filter->connect(top_block); + + boost::shared_ptr source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue)); + source->connect(top_block); + + interleaved_byte_to_complex_byte_sptr ibyte_to_cbyte_ = make_interleaved_byte_to_complex_byte(); + boost::shared_ptr null_sink = gr::blocks::null_sink::make(item_size); + + top_block->connect(source->get_right_block(), 0, ibyte_to_cbyte_, 0); + top_block->connect(ibyte_to_cbyte_, 0, filter->get_left_block(), 0); + top_block->connect(filter->get_right_block(), 0, null_sink, 0); + }) << "Failure connecting the top_block."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1000000 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1000000 + tv.tv_usec; + }) << "Failure running the top_block." << std::endl; + std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; +} + + +TEST_F(Fir_Filter_Test, ConnectAndRunCbyteGrcomplex) +{ + struct timeval tv; + long long int begin = 0; + long long int end = 0; + top_block = gr::make_top_block("Fir filter test"); + + init(); + configure_cbyte_gr_complex(); + std::shared_ptr filter = std::make_shared(config.get(), "InputFilter", 1, 1, queue); + std::shared_ptr config2 = std::make_shared(); + + config2->set_property("Test_Source.samples", "1000000"); + config2->set_property("Test_Source.sampling_frequency", "4000000"); + std::string path = std::string(TEST_PATH); + std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat"; + config2->set_property("Test_Source.filename", filename); + config2->set_property("Test_Source.item_type", "ibyte"); + config2->set_property("Test_Source.repeat", "true"); + + item_size = sizeof(gr_complex); + ASSERT_NO_THROW( { + filter->connect(top_block); + + boost::shared_ptr source(new FileSignalSource(config2.get(), "Test_Source", 1, 1, queue)); + source->connect(top_block); + + interleaved_byte_to_complex_byte_sptr ibyte_to_cbyte_ = make_interleaved_byte_to_complex_byte(); + boost::shared_ptr null_sink = gr::blocks::null_sink::make(item_size); + + top_block->connect(source->get_right_block(), 0, ibyte_to_cbyte_, 0); + top_block->connect(ibyte_to_cbyte_, 0, filter->get_left_block(), 0); + top_block->connect(filter->get_right_block(), 0, null_sink, 0); + }) << "Failure connecting the top_block."<< std::endl; + + EXPECT_NO_THROW( { + gettimeofday(&tv, NULL); + begin = tv.tv_sec *1000000 + tv.tv_usec; + top_block->run(); // Start threads and wait + gettimeofday(&tv, NULL); + end = tv.tv_sec *1000000 + tv.tv_usec; + }) << "Failure running the top_block." << std::endl; + std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl; +}