From 609077de0f0f567e29928ec8e67ea6d32028bf8b Mon Sep 17 00:00:00 2001 From: Oleksandr Suvorov Date: Thu, 26 Nov 2026 17:20:57 +0200 Subject: [PATCH] tests: add unit tests for single point positioning with many observations Cover the cases fixed in 08d3f5cb5: valsol() with more than MAXOBS satellites, valsol() with more than 100 degrees of freedom, and pntpos() with more than MAXOBS observations. Refs #1172 Refs #1173 Signed-off-by: Oleksandr Suvorov --- .../pvt/rtklib_pntpos_test.cc | 100 ++++++++++++++++++ tests/unit_tests_pvt.cc | 1 + 2 files changed, 101 insertions(+) create mode 100644 tests/unit-tests/signal-processing-blocks/pvt/rtklib_pntpos_test.cc diff --git a/tests/unit-tests/signal-processing-blocks/pvt/rtklib_pntpos_test.cc b/tests/unit-tests/signal-processing-blocks/pvt/rtklib_pntpos_test.cc new file mode 100644 index 000000000..4f2e100c3 --- /dev/null +++ b/tests/unit-tests/signal-processing-blocks/pvt/rtklib_pntpos_test.cc @@ -0,0 +1,100 @@ +/*! + * \file rtklib_pntpos_test.cc + * \brief Unit tests for the RTKLIB single point positioning with many observations + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2026 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "rtklib.h" +#include "rtklib_pntpos.h" +#include +#include +#include + + +TEST(RtklibPntposTest, ValsolChiSquareThresholdCoversManyDegreesOfFreedom) +{ + // The chi-square table has 300 entries, the threshold is approximated + // beyond it. The exact thresholds (alpha=0.001) for 120, 200 and 400 + // degrees of freedom are 173.6, 267.5 and 493.1. + constexpr int NS = 10; + constexpr int NX = 8; + std::vector azel(2 * NS); + std::vector vsat(NS, 1); + for (int i = 0; i < NS; i++) + { + azel[2 * i] = 2.0 * M_PI * i / NS; + azel[2 * i + 1] = (i % 2 == 0 ? 0.6 : 1.2); + } + prcopt_t opt{}; + opt.elmin = 5.0 * M_PI / 180.0; + opt.maxgdop = 30.0; + + const int dofs[] = {120, 200, 400}; + const double thresholds[] = {173.6, 267.5, 493.1}; + for (int k = 0; k < 3; k++) + { + SCOPED_TRACE(dofs[k]); + const int nv = dofs[k] + NX; + std::vector v(nv, 0.0); + char msg[128] = {0}; + + v[0] = std::sqrt(0.97 * thresholds[k]); + EXPECT_EQ(valsol(azel.data(), vsat.data(), NS, &opt, v.data(), nv, NX, msg), 1) << msg; + v[0] = std::sqrt(1.03 * thresholds[k]); + EXPECT_EQ(valsol(azel.data(), vsat.data(), NS, &opt, v.data(), nv, NX, msg), 0); + } +} + + +TEST(RtklibPntposTest, ValsolAcceptsMoreThanMaxobsSatellites) +{ + // More satellites than MAXOBS, as with all constellations tracked at once. + // The azimuth/elevation scratch array of valsol() used to hold MAXOBS entries. + constexpr int N = 2 * MAXOBS + 8; + std::vector azel(2 * N); + std::vector vsat(N, 1); + for (int i = 0; i < N; i++) + { + azel[2 * i] = 2.0 * M_PI * i / N; + azel[2 * i + 1] = (i % 2 == 0 ? 0.6 : 1.2); + } + prcopt_t opt{}; + opt.elmin = 5.0 * M_PI / 180.0; + opt.maxgdop = 30.0; + const std::vector v(N, 0.0); + char msg[128] = {0}; + + EXPECT_EQ(valsol(azel.data(), vsat.data(), N, &opt, v.data(), N, 8, msg), 1) << msg; +} + + +TEST(RtklibPntposTest, PntposHandlesMoreThanMaxobsObservations) +{ + // Without navigation data no satellite is usable: the call must fail + // gracefully and must not touch memory beyond its per-observation arrays. + constexpr int N = 2 * MAXOBS + 8; + std::vector obs(N); + for (int i = 0; i < N; i++) + { + obs[i] = obsd_t{}; + obs[i].sat = 1 + (i % 30); + obs[i].code[0] = CODE_L1C; + obs[i].P[0] = 22000000.0 + 1000.0 * i; + } + nav_t nav{}; + prcopt_t opt{}; + sol_t sol{}; + std::vector azel(2 * N, 0.0); + char msg[128] = {0}; + + EXPECT_EQ(pntpos(obs.data(), N, &nav, &opt, &sol, azel.data(), nullptr, msg), 0); +} diff --git a/tests/unit_tests_pvt.cc b/tests/unit_tests_pvt.cc index 418136ed7..0ef3591ec 100644 --- a/tests/unit_tests_pvt.cc +++ b/tests/unit_tests_pvt.cc @@ -39,6 +39,7 @@ #include "unit-tests/signal-processing-blocks/pvt/rtklib_detslp_dop_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtklib_detslp_gf_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtklib_fixed_base_test.cc" +#include "unit-tests/signal-processing-blocks/pvt/rtklib_pntpos_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtklib_pvt_ntrip_configuration_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtklib_tls_test.cc" #include "unit-tests/signal-processing-blocks/pvt/rtklib_udpos_test.cc"