1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-06-27 23:52:53 +00:00

Fix tests building

This commit is contained in:
Carles Fernandez 2024-06-23 11:10:40 +02:00
parent bac36b2df5
commit 8dfd341d2c
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
5 changed files with 322 additions and 403 deletions

View File

@ -1344,52 +1344,14 @@ else()
endif()
endif()
######################################################### gnss_crypto_test
if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA)
set(GNSS_CRYPTO_TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/single_test_main.cc
${CMAKE_CURRENT_SOURCE_DIR}/unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc)
if(USE_CMAKE_TARGET_SOURCES)
add_executable(gnss_crypto_test)
target_sources(gnss_crypto_test PRIVATE ${GNSS_CRYPTO_TEST_SOURCES})
else()
add_executable(gnss_crypto_test ${GNSS_CRYPTO_TEST_SOURCES})
endif()
target_link_libraries(gnss_crypto_test
PRIVATE
Boost::thread
GTest::GTest
GTest::Main
core_system_parameters
Pugixml::pugixml
)
if(ENABLE_GLOG_AND_GFLAGS)
target_link_libraries(gnss_crypto_test PRIVATE Gflags::gflags Glog::glog)
target_compile_definitions(gnss_crypto_test PRIVATE -DUSE_GLOG_AND_GFLAGS=1)
else()
target_link_libraries(gnss_crypto_test PRIVATE absl::flags absl::flags_parse absl::log $<LINK_LIBRARY:WHOLE_ARCHIVE,absl::log_flags> absl::log_initialize)
endif()
target_include_directories(gnss_crypto_test
PRIVATE
${GNSSSDR_SOURCE_DIR}/src/core/system_parameters)
xcode_remove_warning_duplicates(gnss_crypto_test) # TODO - unsure if needed
add_test(gnss_crypto_test gnss_crypto_test)
set_property(TEST gnss_crypto_test PROPERTY TIMEOUT 1)
endif()
######################################################### osnma_msg_receiver_test
if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA)
set(OSNMA_MSG_RECEIVER_TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/single_test_main.cc
${CMAKE_CURRENT_SOURCE_DIR}/unit-tests/signal-processing-blocks/osnma/osnma_msg_receiver_test.cc)
${CMAKE_CURRENT_SOURCE_DIR}/unit-tests/signal-processing-blocks/osnma/osnma_msg_receiver_test.cc
)
if(USE_CMAKE_TARGET_SOURCES)
add_executable(osnma_msg_receiver_test)
@ -1400,6 +1362,7 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA)
target_link_libraries(osnma_msg_receiver_test
PRIVATE
gnss_sdr_flags
Boost::thread
GTest::GTest
GTest::Main
@ -1416,11 +1379,12 @@ if(NOT ENABLE_PACKAGING AND NOT ENABLE_FPGA)
add_test(osnma_msg_receiver_test osnma_msg_receiver_test)
set_property(TEST osnma_msg_receiver_test PROPERTY TIMEOUT 1)
set_property(TEST osnma_msg_receiver_test PROPERTY TIMEOUT 30)
target_include_directories(osnma_msg_receiver_test
PRIVATE
${GNSSSDR_SOURCE_DIR}/src/core/system_parameters)
${GNSSSDR_SOURCE_DIR}/src/core/system_parameters
)
endif()
if(ENABLE_BENCHMARKS)

View File

@ -19,6 +19,7 @@
#include "concurrent_map.h"
#include "concurrent_queue.h"
#include "gps_acq_assist.h"
#include "gnss_sdr_flags.h"
#include <gtest/gtest.h>
#include <fstream>
#include <iostream>
@ -36,7 +37,6 @@ using namespace google;
DECLARE_string(log_dir);
#endif
#else
#include "gnss_sdr_flags.h"
#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/log/flags.h>
@ -44,7 +44,6 @@ DECLARE_string(log_dir);
#include <absl/log/log.h>
#include <absl/log/log_sink.h>
#include <absl/log/log_sink_registry.h>
class TestLogSink : public absl::LogSink
{
public:

View File

@ -113,7 +113,7 @@ private:
#include "unit-tests/signal-processing-blocks/adapter/pass_through_test.cc"
#include "unit-tests/signal-processing-blocks/libs/item_type_helpers_test.cc"
#include "unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc"
#include "unit-tests/signal-processing-blocks/osnma/osnma_msg_receiver_test.cc"
// #include "unit-tests/signal-processing-blocks/osnma/osnma_msg_receiver_test.cc"
#include "unit-tests/signal-processing-blocks/pvt/geohash_test.cc"
#include "unit-tests/signal-processing-blocks/pvt/nmea_printer_test.cc"
#include "unit-tests/signal-processing-blocks/pvt/rinex_printer_test.cc"

View File

@ -1,23 +1,24 @@
#include <gtest/gtest.h>
#include "gnss_crypto.h"
#include <gtest/gtest.h>
class GnssCryptoTest : public ::testing::Test
{
};
TEST(GnssCryptoTest, VerifySignature) {
TEST(GnssCryptoTest, VerifySignature)
{
// "../data/OSNMA_PublicKey_20240115100000_newPKID_1.pem"
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>();
const std::string fake("fake");
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>(fake, fake);
// RG example - import crt certificate - result: FAIL
std::vector<uint8_t> message = {0x82, 0x10, 0x49, 0x22, 0x04, 0xE0, 0x60, 0x61, 0x0B, 0xDF, 0x26, 0xD7, 0x7B, 0x5B, 0xF8, 0xC9, 0xCB, 0xFC, 0xF7, 0x04, 0x22, 0x08, 0x14, 0x75, 0xFD, 0x44, 0x5D, 0xF0, 0xFF};
std::vector<uint8_t> signature = {0xF8, 0xCD, 0x88, 0x29, 0x9F, 0xA4, 0x60, 0x58, 0x00, 0x20, 0x7B, 0xFE, 0xBE, 0xAC, 0x55, 0x02, 0x40, 0x53, 0xF3, 0x0F, 0x7C, 0x69, 0xB3, 0x5C, 0x15, 0xE6, 0x08, 0x00, 0xAC, 0x3B, 0x6F, 0xE3, 0xED, 0x06, 0x39, 0x95, 0x2F, 0x7B, 0x02, 0x8D, 0x86, 0x86, 0x74, 0x45, 0x96, 0x1F, 0xFE, 0x94, 0xFB, 0x22, 0x6B, 0xFF, 0x70, 0x06, 0xE0, 0xC4, 0x51, 0xEE, 0x3F, 0x87, 0x28, 0xC1, 0x77, 0xFB};
std::vector<uint8_t> publicKey{// PEM format - 1000 bits
0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A,
0x4D, 0x46, 0x6B, 0x77, 0x45, 0x77, 0x59, 0x48, 0x4B, 0x6F, 0x5A, 0x49, 0x7A, 0x6A, 0x30, 0x43, 0x41, 0x51, 0x59, 0x49, 0x4B, 0x6F, 0x5A, 0x49,
0x7A, 0x6A, 0x30, 0x44, 0x41, 0x51, 0x63, 0x44, 0x51, 0x67, 0x41, 0x45, 0x41, 0x37, 0x4C, 0x4F, 0x5A, 0x4C, 0x77, 0x67, 0x65, 0x39, 0x32, 0x4C, 0x78, 0x4E, 0x2B, 0x46, 0x6B, 0x59, 0x66, 0x38, 0x74, 0x6F, 0x59, 0x79, 0x44, 0x57, 0x50, 0x2F, 0x0A, 0x6F, 0x4A, 0x46, 0x42, 0x44, 0x38, 0x46, 0x59, 0x2B, 0x37,
0x64, 0x35, 0x67, 0x4F, 0x71, 0x49, 0x61, 0x45, 0x32, 0x52, 0x6A, 0x50, 0x41, 0x6E, 0x4B, 0x49, 0x36, 0x38, 0x73, 0x2F, 0x4F, 0x4B, 0x2F, 0x48, 0x50, 0x67, 0x6F, 0x4C, 0x6B, 0x4F, 0x32, 0x69, 0x6A, 0x51, 0x38, 0x78, 0x41, 0x5A, 0x79, 0x44, 0x64, 0x50, 0x42, 0x31, 0x64, 0x48, 0x53, 0x51, 0x3D, 0x3D,
0x0A,
0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A};
@ -63,13 +64,11 @@ std::vector<uint8_t> publicKey { // PEM format - 1000 bits
// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x45, 0x43, 0x20, 0x50, 0x41, 0x52, 0x41, 0x4D, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x42, 0x67, 0x67, 0x71, 0x68, 0x6B, 0x6A, 0x4F, 0x50, 0x51, 0x4D, 0x42, 0x41, 0x67, 0x3D, 0x3D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D,
// 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x45, 0x43, 0x20, 0x50, 0x41, 0x52, 0x41, 0x4D, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A };
d_crypto->set_public_key(publicKey);
bool result = d_crypto->verify_signature(message, signature);
ASSERT_TRUE(result);
}
// TEST(GnssCryptoTest, sha256Test)
//{
// std::unique_ptr<Gnss_Crypto> d_crypto;
@ -83,13 +82,13 @@ std::vector<uint8_t> publicKey { // PEM format - 1000 bits
// std::vector<uint8_t> computedOutput = d_crypto->computeSHA256(input);
//
// ASSERT_TRUE(computedOutput == expectedOutput
}
TEST(GnssCryptoTest, VerifyPubKeyImport)
{
// "../data/OSNMA_PublicKey_20240115100000_newPKID_1.pem"
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>();
const std::string fake("fake");
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>(fake, fake);
// RG example - key is raw 520 bits example shown
// std::vector<uint8_t> publicKey = { // base64 decoding error
@ -113,14 +112,12 @@ TEST(GnssCryptoTest,VerifyPubKeyImport)
// own ECDSA P 256 public key and own message generated (2024-02-19-Own-Key-ECDSA-openssl)
std::vector<uint8_t> publicKey{// PEM
0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A,
0x4D, 0x46,
0x6B, 0x77, 0x45, 0x77, 0x59, 0x48, 0x4B, 0x6F, 0x5A, 0x49, 0x7A, 0x6A, 0x30, 0x43, 0x41, 0x51, 0x59, 0x49, 0x4B, 0x6F, 0x5A, 0x49, 0x7A, 0x6A, 0x30, 0x44, 0x41, 0x51, 0x63,
0x44, 0x51, 0x67, 0x41, 0x45, 0x53, 0x76, 0x50, 0x75, 0x4F, 0x70, 0x51, 0x6C, 0x4A, 0x54, 0x31, 0x56, 0x77, 0x6C, 0x72, 0x43, 0x4C, 0x63, 0x38, 0x55, 0x54, 0x54, 0x6B, 0x4E,
0x73, 0x66, 0x78, 0x2F, 0x0A, 0x4D, 0x56, 0x6F, 0x71, 0x47, 0x61, 0x35, 0x4F, 0x31, 0x73, 0x75, 0x6D, 0x57, 0x64, 0x61, 0x5A, 0x66, 0x4F, 0x69, 0x39, 0x48, 0x30, 0x4D, 0x30,
0x48, 0x46, 0x6E, 0x5A, 0x32, 0x63, 0x72, 0x44, 0x37, 0x6C, 0x6A, 0x6C, 0x36, 0x74, 0x4E, 0x56, 0x52, 0x4F, 0x71, 0x4A, 0x63, 0x57, 0x58, 0x51, 0x6B, 0x6E, 0x4B, 0x69, 0x79,
0x44, 0x79, 0x48, 0x58, 0x51, 0x3D, 0x3D, 0x0A,
0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D,
0x2D, 0x2D, 0x2D, 0x0A};
@ -128,12 +125,6 @@ TEST(GnssCryptoTest,VerifyPubKeyImport)
ASSERT_TRUE(d_crypto->have_public_key());
// std::vector<uint8_t> publicKey = { // DER format
// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x46, 0x6B, 0x77, 0x45, 0x77, 0x59, 0x48, 0x4B, 0x6F, 0x5A, 0x49, 0x7A, 0x6A, 0x30, 0x43, 0x41, 0x51, 0x59, 0x49, 0x4B, 0x6F, 0x5A, 0x49,
// 0x7A, 0x6A, 0x30, 0x44, 0x41, 0x51, 0x63, 0x44, 0x51, 0x67, 0x41, 0x45, 0x41, 0x37, 0x4C, 0x4F, 0x5A, 0x4C, 0x77, 0x67, 0x65, 0x39, 0x32, 0x4C, 0x78, 0x4E, 0x2B, 0x46, 0x6B, 0x59, 0x66, 0x38, 0x74, 0x6F, 0x59, 0x79, 0x44, 0x57, 0x50, 0x2F, 0x0A, 0x6F, 0x4A, 0x46, 0x42, 0x44, 0x38, 0x46, 0x59, 0x2B, 0x37,
@ -157,12 +148,15 @@ TEST(GnssCryptoTest,VerifyPubKeyImport)
// 0x7A, 0x6A, 0x30, 0x44, 0x41, 0x51, 0x63, 0x44, 0x51, 0x67, 0x41, 0x45, 0x41, 0x37, 0x4C, 0x4F, 0x5A, 0x4C, 0x77, 0x67, 0x65, 0x39, 0x32, 0x4C, 0x78, 0x4E, 0x2B, 0x46, 0x6B, 0x59, 0x66, 0x38, 0x74, 0x6F, 0x59, 0x79, 0x44, 0x57, 0x50, 0x2F, 0x0A, 0x6F, 0x4A, 0x46, 0x42, 0x44, 0x38, 0x46, 0x59, 0x2B, 0x37,
// 0x64, 0x35, 0x67, 0x4F, 0x71, 0x49, 0x61, 0x45, 0x32, 0x52, 0x6A, 0x50, 0x41, 0x6E, 0x4B, 0x49, 0x36, 0x38, 0x73, 0x2F, 0x4F, 0x4B, 0x2F, 0x48, 0x50, 0x67, 0x6F, 0x4C, 0x6B, 0x4F, 0x32, 0x69, 0x6A, 0x51, 0x38, 0x78, 0x41, 0x5A, 0x79, 0x44, 0x64, 0x50, 0x42, 0x31, 0x64, 0x48, 0x53, 0x51, 0x3D, 0x3D, 0x0A,
// 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A };
}
// Unit test for computeHMAC_SHA_256 function.
TEST(GnssCryptoTest, TestComputeHMACSHA256) { // key and message generated with openssl
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>();
TEST(GnssCryptoTest, TestComputeHMACSHA256)
{
// key and message generated with openssl
const std::string fake("fake");
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>(fake, fake);
std::vector<uint8_t> key = {
0x24, 0x24, 0x3B, 0x76, 0xF9, 0x14, 0xB1, 0xA7,
0x7D, 0x48, 0xE7, 0xF1, 0x48, 0x0C, 0xC2, 0x98,
@ -176,16 +170,16 @@ TEST(GnssCryptoTest, TestComputeHMACSHA256) { // key and message generated with
0xB2, 0x7A, 0xCC, 0x22, 0x00, 0xAA, 0xD2, 0x37,
0xD0, 0x79, 0x06, 0x12, 0x83, 0x40, 0xB7, 0xA6};
std::vector<uint8_t> output = d_crypto->computeHMAC_SHA_256(key, message);
ASSERT_EQ(expected_output, output);
}
TEST(GnssCryptoTest, TestComputeHMACSHA256_m0) { // key and message generated from RG A.6.5.1
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>();
TEST(GnssCryptoTest, TestComputeHMACSHA256_m0)
{ // key and message generated from RG A.6.5.1
const std::string fake("fake");
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>(fake, fake);
std::vector<uint8_t> key = {// RG K4 @ 345690
0x69, 0xC0, 0x0A, 0xA7, 0x36, 0x42, 0x37, 0xA6,
0x5E, 0xBF, 0x00, 0x6A, 0xD8, 0xDD, 0xBC, 0x73};
@ -207,8 +201,11 @@ TEST(GnssCryptoTest, TestComputeHMACSHA256_m0) { // key and message generated fr
ASSERT_EQ(expected_output, output);
}
TEST(GnssCryptoTest, TestComputeHMACSHA256_adkd4) { // key and message generated from RG A.6.5.2
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>();
TEST(GnssCryptoTest, TestComputeHMACSHA256_adkd4)
{ // key and message generated from RG A.6.5.2
const std::string fake("fake");
std::unique_ptr<Gnss_Crypto> d_crypto = std::make_unique<Gnss_Crypto>(fake, fake);
std::vector<uint8_t> key = {// RG K4 @ 345690
0x69, 0xC0, 0x0A, 0xA7, 0x36, 0x42, 0x37, 0xA6,
0x5E, 0xBF, 0x00, 0x6A, 0xD8, 0xDD, 0xBC, 0x73};
@ -223,7 +220,6 @@ TEST(GnssCryptoTest, TestComputeHMACSHA256_adkd4) { // key and message generated
0xE6, 0x3F, 0xB7, 0xF4, 0xF5, 0x4D, 0x44, 0xAB, 0xEE, 0x4D,
0xCE, 0xB9, 0x3D, 0xCF, 0x65, 0xCB, 0x3A, 0x5B, 0x81, 0x4A, 0x34, 0xE9};
std::vector<uint8_t> output = d_crypto->computeHMAC_SHA_256(key, message);
ASSERT_EQ(expected_output, output);

View File

@ -2,7 +2,6 @@
#include <bitset>
#include <filesystem>
#include <fstream>
#include <logging.h>
#include <osnma_msg_receiver.h>
#include <vector>
@ -33,7 +32,7 @@ protected:
void set_time(std::tm& input);
// std::string log_name {"CONFIG1-2023-08-23-PKID1-OSNMA"};
std::string log_name{"CONFIG2-2023-07-27-PKID2-MT2-OSNMA"};
void initializeGoogleLog();
// void initializeGoogleLog();
void SetUp() override
{
@ -58,7 +57,8 @@ public:
};
TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification) {
TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification)
{
// Arrange
// ----------
osnma->d_tesla_key_verified = false;
@ -74,31 +74,25 @@ TEST_F(OsnmaMsgReceiverTest, TeslaKeyVerification) {
std::vector<uint8_t> key = {0x2D, 0xC3, 0xA3, 0xCD, 0xB1, 0x17, 0xFA, 0xAD, 0xB8, 0x3B, 0x5F, 0x0B, 0x6F, 0xEA, 0x88, 0xEB}; // K2
uint32_t TOW = 345630;
// Act
// ----------
bool result = osnma->verify_tesla_key(key, TOW);
// Assert
// ----------
ASSERT_TRUE(result);
}
TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
{
initializeGoogleLog();
// initializeGoogleLog();
// Arrange
// ----------
// std::vector<TestVector> testVectors = readTestVectorsFromFile("/home/cgm/CLionProjects/osnma/data/16_AUG_2023_GST_05_00_01.csv");
std::vector<TestVector> testVectors = readTestVectorsFromFile("/home/cgm/CLionProjects/osnma/data/27_JUL_2023_GST_00_00_01.csv");
if (testVectors.empty()){
if (testVectors.empty())
{
ASSERT_TRUE(false);
}
@ -112,21 +106,21 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
const int DUMMY_PAGE{63};
bool flag_dummy_page{false};
std::cout << "OsnmaTestVectorsSimulation:" << " d_GST_SIS= " << d_GST_SIS
std::cout << "OsnmaTestVectorsSimulation:"
<< " d_GST_SIS= " << d_GST_SIS
<< ", TOW=" << TOW
<< ", WN=" << WN << std::endl;
// Act
// ----------
// loop over all bytes of data. Note: all TestVectors have same amount of data.
while (end_of_hex_stream == false){
while (end_of_hex_stream == false)
{
// loop over all SVs, extract a subframe
for(const TestVector& tv : testVectors) { // loop over all SVs, extract a subframe
for (const TestVector& tv : testVectors)
{ // loop over all SVs, extract a subframe
std::cout << "OsnmaTestVectorsSimulation: SVID (PRN_a) " << tv.svId << std::endl;
auto osnmaMsg_sptr = std::make_shared<OSNMA_msg>();
std::array<uint8_t, 15> hkroot{};
@ -138,17 +132,21 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
{
// extract bytes of complete page (odd+even) -- extract SIZE_PAGE from tv.navBits, starting from byte_index
std::vector<uint8_t> page_bytes = extract_page_bytes(tv, byte_index, SIZE_PAGE_BYTES);
if(page_bytes.empty()){
std::cout<< "OsnmaTestVectorsSimulation: end of TestVectors \n" << "byte_index="<<byte_index<< " expected= " << 432000/8 << std::endl;
if (page_bytes.empty())
{
std::cout << "OsnmaTestVectorsSimulation: end of TestVectors \n"
<< "byte_index=" << byte_index << " expected= " << 432000 / 8 << std::endl;
end_of_hex_stream = true;
break;
}
// convert them to bitset representation using bytes_to_string
std::string page_bits = bytes_to_str(page_bytes);
// Extract the 40 OSNMA bits starting from the 18th bit
std::string even_page = page_bits.substr(0, page_bits.size() / 2);;
std::string even_page = page_bits.substr(0, page_bits.size() / 2);
;
std::string odd_page = page_bits.substr(page_bits.size() / 2);
if(even_page.size() < 120 || odd_page.size() < 120 ){
if (even_page.size() < 120 || odd_page.size() < 120)
{
std::cout << "OsnmaTestVectorsSimulation: error parsing pages" << std::endl;
}
bool even_odd_OK = even_page[0] == '0' && odd_page[0] == '1';
@ -188,7 +186,8 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
std::cout << "----------" << std::endl;
if (end_of_hex_stream)
break;
if(flag_dummy_page){
if (flag_dummy_page)
{
flag_dummy_page = false;
continue; // skip this SV
}
@ -211,13 +210,13 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
{
ephClockStatusWordsReceived = false;
std::cerr << "OsnmaTestVectorsSimulation: error parsing words 1->5. "
"Word "<< i << " should be received for each subframe but was not." << std::endl;
"Word "
<< i << " should be received for each subframe but was not." << std::endl;
}
}
// extract bits as needed by osnma block
if (ephClockStatusWordsReceived)
{
// Define the starting position and length of bits to extract for each word
std::map<uint8_t, std::pair<uint8_t, uint8_t>> extractionParams = {
{1, {6, 120}},
@ -229,14 +228,14 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
};
// Fill NavData bits -- Iterate over the extraction parameters
for (const auto& param : extractionParams) {
for (const auto& param : extractionParams)
{
uint8_t wordKey = param.first;
uint8_t start = param.second.first;
uint8_t length = param.second.second;
// Extract the required bits and fill osnma block
osnmaMsg_sptr->EphemerisClockAndStatusData_2 += words[wordKey].
to_string().substr(
osnmaMsg_sptr->EphemerisClockAndStatusData_2 += words[wordKey].to_string().substr(
start, length);
}
}
@ -245,12 +244,12 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
bool timingWordsReceived = words.find(6) != words.end() &&
words.find(10) != words.end();
// extract bits as needed by osnma block
if(timingWordsReceived){
if (timingWordsReceived)
{
// Define the starting position and length of bits to extract for each word
std::map<uint8_t, std::pair<uint8_t, uint8_t>> extractionParams = {
{6, {6, 99}},
{10, {86, 42}}
};
{10, {86, 42}}};
// Fill NavData bits -- Iterate over the extraction parameters
for (const auto& param : extractionParams)
@ -263,7 +262,6 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
osnmaMsg_sptr->TimingData_2 += words[wordKey].to_string().substr(
start, length);
}
}
// Call the handler, as if it came from telemetry decoder block
@ -273,17 +271,17 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
}
if(!end_of_hex_stream){
if (!end_of_hex_stream)
{
offset_byte = byte_index; // update offset for the next subframe
d_GST_SIS += DURATION_SUBFRAME;
TOW = d_GST_SIS & 0x000FFFFF;
WN = (d_GST_SIS & 0xFFF00000) >> 20;
std::cout << "OsnmaTestVectorsSimulation:" << " d_GST_SIS= " << d_GST_SIS
std::cout << "OsnmaTestVectorsSimulation:"
<< " d_GST_SIS= " << d_GST_SIS
<< ", TOW=" << TOW
<< ", WN=" << WN << std::endl;
}
}
@ -293,19 +291,23 @@ TEST_F(OsnmaMsgReceiverTest, OsnmaTestVectorsSimulation)
// TODO - create global vars with failed tags and compare to total tags (Tag Id for example)
}
std::vector<TestVector> OsnmaMsgReceiverTest::readTestVectorsFromFile(const std::string& filename)
{
std::ifstream file(filename);
std::vector<TestVector> testVectors;
if (!file.is_open()) {
if (!file.is_open())
{
std::cerr << "Error reading the file \"" << filename << "\" \n";
return testVectors;
}
std::string line;
std::getline(file, line);
if (line != "SVID,NumNavBits,NavBitsHEX\r" ){
std::cerr<<"Error parsing first line" <<"\n";
if (line != "SVID,NumNavBits,NavBitsHEX\r")
{
std::cerr << "Error parsing first line"
<< "\n";
}
while (std::getline(file, line))
@ -329,6 +331,8 @@ std::vector<TestVector> OsnmaMsgReceiverTest::readTestVectorsFromFile(const std:
return testVectors;
}
std::vector<uint8_t> OsnmaMsgReceiverTest::parseNavBits(const std::string& hex)
{
std::vector<uint8_t> bytes;
@ -341,6 +345,8 @@ std::vector<uint8_t> OsnmaMsgReceiverTest::parseNavBits(const std::string& hex)
}
return bytes;
}
std::string OsnmaMsgReceiverTest::bytes_to_str(const std::vector<uint8_t>& bytes)
{
std::string bit_string;
@ -353,6 +359,7 @@ std::string OsnmaMsgReceiverTest::bytes_to_str(const std::vector<uint8_t>& bytes
return bit_string;
}
/**
* @brief Extracts a range of bytes from a TestVector's navBits vector.
*
@ -381,6 +388,8 @@ std::vector<uint8_t> OsnmaMsgReceiverTest::extract_page_bytes(const TestVector&
return extracted_bytes;
}
/**
* @brief Sets the time based on the given input.
*
@ -411,50 +420,6 @@ void OsnmaMsgReceiverTest::set_time(std::tm& input)
// TODO: d_GST_SIS or d_receiver_time? doubt
// I am assuming that local realisation of receiver is identical to SIS GST time coming from W5 or W0
this->d_GST_SIS = (this->WN & 0x00000FFF) << 20 | (this->TOW & 0x000FFFFF);
}
void OsnmaMsgReceiverTest::initializeGoogleLog()
{
google::InitGoogleLogging(log_name.c_str());
FLAGS_minloglevel = 0; // INFO
FLAGS_logtostderr = 0; // add this line
FLAGS_log_dir = "/home/cgm/CLionProjects/osnma/build/src/tests/logs";
if (FLAGS_log_dir.empty())
{
std::cout << "Logging will be written at "
<< std::filesystem::temp_directory_path()
<< '\n'
<< "Use gnss-sdr --log_dir=/path/to/log to change that.\n";
}
else
{
try
{
const std::filesystem::path p(FLAGS_log_dir);
if (!std::filesystem::exists(p))
{
std::cout << "The path "
<< FLAGS_log_dir
<< " does not exist, attempting to create it.\n";
std::error_code ec;
if (!std::filesystem::create_directory(p, ec))
{
std::cout << "Could not create the " << FLAGS_log_dir << " folder.\n";
gflags::ShutDownCommandLineFlags();
throw std::runtime_error("Could not create folder for logs");
}
}
std::cout << "Logging will be written at " << FLAGS_log_dir << '\n';
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
std::cerr << "Could not create the " << FLAGS_log_dir << " folder.\n";
gflags::ShutDownCommandLineFlags();
throw;
}
}
}
@ -468,8 +433,7 @@ TEST_F(OsnmaMsgReceiverTest, BuildTagMessageM0)
0x3E, 0xEA, 0x81, 0x41, 0xBF, 0x03, 0xAD, 0xCB, 0x5A, 0xAD, 0xB2, 0x77, 0xAF, 0x6F, 0xCF, 0x21,
0xFB, 0x98, 0xFF, 0x7E, 0x83, 0xAF, 0xFC, 0x37, 0x02, 0x03, 0xB0, 0xD8, 0xE1, 0x0E, 0xB1, 0x4D,
0x11, 0x18, 0xE6, 0xB0, 0xE8, 0x20, 0x01, 0xA0, 0x00, 0xE5, 0x91, 0x00, 0x06, 0xD3, 0x1F, 0x00,
0x02, 0x68, 0x05, 0x4A, 0x02, 0xC2, 0x26, 0x07, 0xF7, 0xFC, 0x00
};
0x02, 0x68, 0x05, 0x4A, 0x02, 0xC2, 0x26, 0x07, 0xF7, 0xFC, 0x00};
uint32_t TOW_Tag0 = 345660;
uint32_t TOW_NavData = TOW_Tag0 - 30;
@ -492,7 +456,6 @@ TEST_F(OsnmaMsgReceiverTest, BuildTagMessageM0)
Tag t0(MTI, TOW_Tag0, WN, PRNa, CTR);
// Act
// ----------
auto computed_message = osnma->build_message(t0);
@ -501,9 +464,11 @@ TEST_F(OsnmaMsgReceiverTest, BuildTagMessageM0)
// Assert
// ----------
ASSERT_TRUE(computed_message == expected_message);
}
TEST_F(OsnmaMsgReceiverTest, TagVerification) {
TEST_F(OsnmaMsgReceiverTest, TagVerification)
{
// Arrange
// ----------
// Tag0
@ -528,15 +493,11 @@ TEST_F(OsnmaMsgReceiverTest, TagVerification) {
Tag t0(MTI, TOW_Tag0, WN, PRNa, CTR);
// Act
// ----------
bool result_tag0 = osnma->verify_tag(t0);
// Assert
// ----------
// ASSERT_TRUE(result_tag0);
@ -566,5 +527,4 @@ TEST_F(OsnmaMsgReceiverTest, TagVerification) {
bool result_tag3 = osnma->verify_tag(t3);
ASSERT_TRUE(result_tag0 && result_tag3);
}