tests: gnss: add some tests for gnss_dump

Add a testsuite for gnss_dump, testing that various values are printed
correctly.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2023-11-26 15:51:31 +00:00 committed by Fabio Baltieri
parent f9ab050306
commit 35de07a528
4 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(gnss_dump)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y
CONFIG_GNSS=y
CONFIG_GNSS_SATELLITES=y
CONFIG_GNSS_DUMP_TO_LOG=y

View file

@ -0,0 +1,85 @@
/*
* Copyright 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/drivers/gnss.h>
#include <zephyr/drivers/gnss/gnss_publish.h>
#include <zephyr/device.h>
DEVICE_DEFINE(gnss_dev, "gnss_dev", NULL, NULL, NULL, NULL,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
static const struct device *gnss_dev = &DEVICE_NAME_GET(gnss_dev);
static struct gnss_data test_data;
static struct gnss_satellite test_satellite;
static void test_gnss_data(void)
{
gnss_publish_data(gnss_dev, &test_data);
/* positive values */
test_data.nav_data.latitude = 10000000001;
test_data.nav_data.longitude = 20000000002;
test_data.nav_data.bearing = 3003;
test_data.nav_data.speed = 4004;
test_data.nav_data.altitude = 5005;
test_data.info.satellites_cnt = 6;
test_data.info.hdop = 7;
test_data.info.fix_status = GNSS_FIX_STATUS_GNSS_FIX;
test_data.info.fix_quality = GNSS_FIX_QUALITY_GNSS_PPS;
test_data.utc.hour = 1;
test_data.utc.minute = 2;
test_data.utc.millisecond = 3;
test_data.utc.month_day = 4;
test_data.utc.month = 5;
test_data.utc.century_year = 6;
gnss_publish_data(gnss_dev, &test_data);
/* small positive values */
test_data.nav_data.latitude = 1;
test_data.nav_data.longitude = 2;
test_data.nav_data.bearing = 3;
test_data.nav_data.speed = 4;
test_data.nav_data.altitude = 5;
gnss_publish_data(gnss_dev, &test_data);
/* negative values */
test_data.nav_data.latitude = -10000000001;
test_data.nav_data.longitude = -20000000002;
test_data.nav_data.altitude = -5005;
gnss_publish_data(gnss_dev, &test_data);
/* small negative values */
test_data.nav_data.latitude = -1;
test_data.nav_data.longitude = -2;
test_data.nav_data.altitude = -5;
gnss_publish_data(gnss_dev, &test_data);
}
static void test_satellites_data(void)
{
gnss_publish_satellites(gnss_dev, &test_satellite, 1);
test_satellite.prn = 1;
test_satellite.snr = 2;
test_satellite.azimuth = 3;
test_satellite.system = GNSS_SYSTEM_GALILEO;
test_satellite.is_tracked = 1;
gnss_publish_satellites(gnss_dev, &test_satellite, 1);
}
int main(void)
{
test_gnss_data();
test_satellites_data();
return 0;
}

View file

@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0
tests:
gnss.gnss_dump:
tags: gnss
platform_allow:
- native_posix
- native_posix_64
- native_sim
- native_sim_64
integration_platforms:
- native_sim
harness: console
harness_config:
type: multi_line
regex:
- "gnss_dev: gnss_info: {satellites_cnt: 0, hdop: 0.0, \
fix_status: NO_FIX, fix_quality: INVALID}"
- "gnss_dev: navigation_data: {latitude: 0.000000000, longitude : 0.000000000, \
bearing 0.000, speed 0.000, altitude: 0.000}"
- "gnss_dev: gnss_time: {hour: 0, minute: 0, millisecond 0, month_day 0, month: 0, \
century_year: 0}"
- "gnss_dev: gnss_info: {satellites_cnt: 6, hdop: 0.7, \
fix_status: GNSS_FIX, fix_quality: GNSS_PPS}"
- "gnss_dev: navigation_data: {latitude: 10.000000001, longitude : 20.000000002, \
bearing 3.003, speed 4.004, altitude: 5.005}"
- "gnss_dev: gnss_time: {hour: 1, minute: 2, millisecond 3, month_day 4, month: 5, \
century_year: 6}"
- "gnss_dev: navigation_data: {latitude: 0.000000001, longitude : 0.000000002, \
bearing 0.003, speed 0.004, altitude: 0.005}"
- "gnss_dev: navigation_data: {latitude: -10.000000001, longitude : -20.000000002, \
bearing 0.003, speed 0.004, altitude: -5.005}"
- "gnss_dev: navigation_data: {latitude: -0.000000001, longitude : -0.000000002, \
bearing 0.003, speed 0.004, altitude: -0.005}"
- "gnss_dev: gnss_satellite: {prn: 0, snr: 0, elevation 0, azimuth 0, system: unknown, \
is_tracked: 0}"
- "gnss_dev: gnss_satellite: {prn: 1, snr: 2, elevation 0, azimuth 3, system: GALILEO, \
is_tracked: 1}"