Skip to content

Commit

Permalink
Add regression tests into the meson test command and automatically …
Browse files Browse the repository at this point in the history
…start an NRF and DCAF when testing.
  • Loading branch information
davidjwbbc committed Nov 22, 2024
1 parent 7177856 commit 19c61c7
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ ninja -C build

**Note:** Errors during the `meson build` command are often caused by missing dependencies or a network issue while trying to retrieve the API files and `openapi-generator` JAR file. See the `~/rt-data-collection-application-function/build/meson-logs/meson-log.txt` log file for the errors in greater detail. Search for `generator-libspdc` to find the start of the API fetch sequence.

## Regression tests (optional)

There are some regression tests that can be run using:

```bash
cd ~/rt-data-collection-application-function
meson test -C build regression
```

This will build the Data Collection AF (if not already built) and then will start an Open5GS NRF and the Data Collection AF, run the regression tests and shutdown the Open5GS NRF and
Data Collection AF. The results of the testing are displayed.

## Installing

To install the built Application Function as a system process:
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ systemd_path_cmd = find_program('systemd-path', required: false)
if systemd_path_cmd.found()
subdir('systemd')
endif

subdir('tests')
11 changes: 11 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# License: 5G-MAG Public License (v1.0)
# Author: David Waring
# Copyright: (C) 2023 British Broadcasting Corporation
#
# For full license terms please see the LICENSE file distributed with this
# program. If this file is missing then the license can be retrieved from
# https://drive.google.com/file/d/1cinCiA778IErENZ3JN52VFW-1ffHpx7Z/view
#

regression_cmd = find_program(files('run_test_scripts.sh'))
test('regression', regression_cmd, verbose: true, timeout: 600, protocol: 'exitcode')
75 changes: 75 additions & 0 deletions tests/scripts/000_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
:
#
# 5G-MAG Reference Tools: DCAF regression test 0: Prepare the environment
# =======================================================================
#
# Author(s): David Waring <david.waring2@bbc.co.uk>
# Copyright: ©2024 British Broadcasting Corporation
# License: 5G-MAG Public License v1.0
#
# For full license terms please see the LICENSE file distributed with this
# program. If this file is missing then the license can be retrieved from
# https://drive.google.com/file/d/1cinCiA778IErENZ3JN52VFW-1ffHpx7Z/view
#
# ============================================================================
# This script prepares the system to run the regression tests.
#
# This will start an Open5GS NRF and the DCAF with the local `local-dcaf.yaml`
# configuration and will remember the started process ids.
#
# A function is provided to kill off the started NRF and DCAF processes.
#

start_network_functions() {
export DB_URI="mongodb://localhost/open5gs"
export http_proxy=
export https_proxy=
export HTTP_PROXY=
export HTTPS_PROXY=

inc total_count

local build_dir=
if [ -n "$MESON_BUILD_ROOT" ]; then
build_dir="$MESON_BUILD_ROOT"
else
build_dir="$script_dir/../build"
fi
build_dir="$(realpath -e "$build_dir")"

if [ -x "$build_dir/subprojects/open5gs/src/nrf/open5gs-nrfd" ]; then
"$build_dir/subprojects/open5gs/src/nrf/open5gs-nrfd" -c "$script_dir/local-dcaf.yaml" > "nrf.log" 2>&1 &
open5gs_nrf_pid=$!
else
log_error "Failed to find NRF executable, have the sources been built successfully?"
exit 1
fi

if [ -x "$build_dir/src/data-collection-af/open5gs-dcafd" ]; then
"$build_dir/src/data-collection-af/open5gs-dcafd" -c "$script_dir/local-dcaf.yaml" > "dcaf.log" 2>&1 &
dcaf_pid=$!
else
stop_network_functions
log_error "Failed to find DCAF executable, have the sources been built successfully?"
exit 1
fi

sleep 3

inc ok_count
}

stop_network_functions() {
inc total_count
if [ -n "$dcaf_pid" ]; then
kill "$dcaf_pid"
rm -f "dcaf.log"
fi
if [ -n "$open5gs_nrf_pid" ]; then
kill "$open5gs_nrf_pid"
rm -f "nrf.log"
fi
inc ok_count
}

start_network_functions
14 changes: 7 additions & 7 deletions tests/scripts/006_event_exposure_notification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ create_event_notification_report() {
wait_for_notification_since() {
local timestamp="$1"
local wait_timeout="${2:-5}"
(tail -fn0 "$notification_logfile" | head -n1 > /dev/null) &
local fileupdate_pid=$!
tail -fn0 "$notification_logfile" </dev/null 2>/dev/null | head -n1 >/dev/null 2>&1 &
local sincefileupdate_pid=$!
local current_timestamp=$(notification_logfile_modified_timestamp)
if [ "$timestamp" -lt "$current_timestamp" ]; then
kill -INT "$fileupdate_pid"
kill "$sincefileupdate_pid"
return 0
fi
waitpid -e -t "$wait_timeout" "$fileupdate_pid"
waitpid -e -t "$wait_timeout" "$sincefileupdate_pid"
if [ "$?" -eq 3 ]; then
log_error "Timeout waiting for notification event"
kill -INT "$fileupdate_pid"
kill "$sincefileupdate_pid"
return 1
fi
sleep 1
Expand All @@ -102,12 +102,12 @@ wait_for_notification_since() {

wait_for_notification_event() {
local timeout="${1:-5}"
(tail -fn0 "$notification_logfile" | head -n1 > /dev/null) &
tail -fn0 "$notification_logfile" </dev/null 2>/dev/null | head -n1 >/dev/null 2>&1 &
local fileupdate_pid=$!
waitpid -e -t "$timeout" "$fileupdate_pid"
if [ "$?" -eq 3 ]; then
log_error "Timeout waiting for notification event"
kill -INT "$fileupdate_pid"
kill "$fileupdate_pid"
return 1
fi
# wait for write to finish
Expand Down
19 changes: 19 additions & 0 deletions tests/scripts/999_shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
:
#
# 5G-MAG Reference Tools: DCAF regression test 999: Shutdown
# ============================================================
#
# Author(s): David Waring <david.waring2@bbc.co.uk>
# Copyright: ©2024 British Broadcasting Corporation
# License: 5G-MAG Public License v1.0
#
# For full license terms please see the LICENSE file distributed with this
# program. If this file is missing then the license can be retrieved from
# https://drive.google.com/file/d/1cinCiA778IErENZ3JN52VFW-1ffHpx7Z/view
#
# ============================================================================
# This script shuts down the network functions started by the 000_prepare.sh
# script.
#

stop_network_functions

0 comments on commit 19c61c7

Please sign in to comment.