From 62cb2e035b17eed11df15aa05cecd530709e0b3c Mon Sep 17 00:00:00 2001 From: ssugiura Date: Mon, 25 Jan 2021 05:22:48 +0000 Subject: Implemention of tests for the dlt-qnx-system module Following files are added to execute and verify the behavior of dlt-qnx-system module: - dlt-test-qnx-system: A test binary to send log messages to slogger2 with specific number of log messages, delay, and payload length. - start-qnx-system-test: A shell script to invoke the test execution and verify its result from received DLT log. Signed-Off By: Saya Sugiura --- doc/test/dlt-test-qnx-slogger.1.md | 60 ++++++++ src/tests/CMakeLists.txt | 10 ++ src/tests/dlt-test-qnx-slogger.c | 135 ++++++++++++++++++ tests/start_qnx_system_test.sh | 280 +++++++++++++++++++++++++++++++++++++ 4 files changed, 485 insertions(+) create mode 100644 doc/test/dlt-test-qnx-slogger.1.md create mode 100644 src/tests/dlt-test-qnx-slogger.c create mode 100755 tests/start_qnx_system_test.sh diff --git a/doc/test/dlt-test-qnx-slogger.1.md b/doc/test/dlt-test-qnx-slogger.1.md new file mode 100644 index 0000000..ec9eadb --- /dev/null +++ b/doc/test/dlt-test-qnx-slogger.1.md @@ -0,0 +1,60 @@ +% DLT-TEST-QNX-SLOGGER(1) + +# NAME + +**dlt-test-qnx-slogger** - Console based test application for sending messages +to QNX slogger + +# SYNOPSIS + +**dlt-test-qnx-slogger** \[**-h**\] \[**-n** count\] \[**-d** delay\] \[**-l** length\] + + +# DESCRIPTION + +The binary writes specific amount of messages to slogger2. This can be used to +test `dlt-qnx-system` ([dlt-qnx-system.md](dlt_qnx_system.md)). + +## OPTIONS + +-h + +: Display a short help text. + +-n + +: Number of messages to be generated (Default: 10). + +-d + +: Milliseconds to wait between sending messages (Default: 500). + +-l + +: Messages length (Default: 100 bytes). + +# Examples + +Send 100 messages every 1 second: + + dlt-test-qnx-slogger -n 100 -d 1000 + +# EXIT STATUS + +Non zero value is returned in case of failure. + +# AUTHOR + +Saya Sugiura (ssugiura@jp.adit-jv.com) + +# COPYRIGHT + +Copyright (C) 2021 ADIT GmbH. License MPL-2.0: Mozilla Public License version 2.0 . + +# BUGS + +See Github issue: + +# SEE ALSO + +**dlt-qnx-system.md(1)** diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 54151ea..9744fc0 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -46,5 +46,15 @@ foreach(target COMPONENT base) endforeach() +if(WITH_DLT_QNX_SYSTEM) + set(dlt-test-qnx-slogger_SRCS dlt-test-qnx-slogger.c) + add_executable(dlt-test-qnx-slogger ${dlt-test-qnx-slogger_SRCS}) + target_link_libraries(dlt-test-qnx-slogger dlt) + set_target_properties(dlt-test-qnx-slogger PROPERTIES LINKER_LANGUAGE C) + install(TARGETS dlt-test-qnx-slogger + RUNTIME DESTINATION bin + COMPONENT base) +endif() + install(FILES dlt-test-filetransfer-file dlt-test-filetransfer-image.png DESTINATION share/dlt-filetransfer) diff --git a/src/tests/dlt-test-qnx-slogger.c b/src/tests/dlt-test-qnx-slogger.c new file mode 100644 index 0000000..973fbe0 --- /dev/null +++ b/src/tests/dlt-test-qnx-slogger.c @@ -0,0 +1,135 @@ +/* + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2021 Advanced Driver Information Technology. + * This code is developed by Advanced Driver Information Technology. + * Copyright of Advanced Driver Information Technology, Bosch and DENSO. + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), v. 2.0. + * If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * For further information see http://www.genivi.org/. + */ + +#include +#include +#include +#include +#include + +#include "dlt.h" +#include "dlt_common.h" /* for dlt_get_version() */ + +#define COUNT 10 +#define DELAY 500 +#define LENGTH 100 + +void usage() +{ + char version[255]; + + dlt_get_version(version, 255); + + printf("Usage: dlt-test-qnx-slogger [options]\n"); + printf("Generate messages and send them to slogger2\n"); + printf("%s\n", version); + printf("Options:\n"); + printf(" -h Usage\n"); + printf(" -n count Number of messages to be generated (Default: %d)\n", COUNT); + printf(" -d delay Milliseconds to wait between sending messages (Default: %d)\n", DELAY); + printf(" -l length Message payload length (Default: %d bytes)\n", LENGTH); +} + +int main(int argc, char *argv[]) { + int i = 0; + int count = COUNT; + int delay = DELAY; + int length = LENGTH; + char *str = NULL; + struct timespec ts; + + int c; + + while ((c = getopt(argc, argv, "hn:d:l:")) != -1) + { + switch(c) + { + case 'n': + { + count = atoi(optarg); + break; + } + case 'd': + { + delay = atoi(optarg); + break; + } + case 'l': + { + length = atoi(optarg); + break; + } + case 'h': + { + usage(); + return -1; + } + case '?': + { + if ((optopt == 'n') || (optopt == 'd') || (optopt == 'l')) + fprintf(stderr, "Option -%c requires an argument\n", optopt); + else if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c`\n", optopt); + else + fprintf(stderr, "Unknown option character `\\x%x`\n", optopt); + + /* unknown or wrong option used, show usage information and terminate */ + usage(); + return -1; + } + default: + { + usage(); + return -1; + } + } + } + + /* Generate string */ + if (length > 0) + { + str = (char *) malloc((size_t) length + 1); + if (str == NULL) + { + fprintf(stderr, "Cannot allocate memory\n"); + return -1; + } + memset(str, 'X', (size_t) length); + str[length] = '\n'; + } + + /* Calculate delay */ + if (delay > 0) { + ts.tv_sec = delay / 1000; + ts.tv_nsec = (delay % 1000) * 1000000; + } + + + for (i = 0; i < count; i++) + { + slogf(_SLOG_SETCODE(_SLOGC_TEST, 0), _SLOG_INFO, "%s", str); + nanosleep(&ts, NULL); + } + + if (str != NULL) + { + free(str); + str = NULL; + } + + return 0; +} diff --git a/tests/start_qnx_system_test.sh b/tests/start_qnx_system_test.sh new file mode 100755 index 0000000..90478f7 --- /dev/null +++ b/tests/start_qnx_system_test.sh @@ -0,0 +1,280 @@ +#!/bin/sh + +################################################################################ +# This software has been developed by Advanced Driver Information Technology. +# Copyright(c) 2021 Advanced Driver Information Technology GmbH, +# Advanced Driver Information Technology Corporation, Robert Bosch GmbH, +# Robert Bosch Car Multimedia GmbH and DENSO Corporation. +# All rights reserved. +################################################################################ + +################################################################################ +# File: start_qnx_system_test.sh +# +# Description: Test script to verify dlt-qnx-system using dlt-test-qnx-slogger +################################################################################ + +usage() +{ + cat < "${DLT_RECEIVE_FILTER}" + + # Start dlt-receive + echo "Start dlt-receive" + "${DEV_AAP_DLT_PATH}"/dlt-receive -a -f "${DLT_RECEIVE_FILTER}" localhost > "${DLT_TEST_RESULT}" & + sleep "${SLEEP_TIME}" + + # Start dlt-qnx-system + echo "Start dlt-qnx-system" + "${DEV_AAP_DLT_PATH}"/dlt-qnx-system > /dev/null & + sleep "${SLEEP_TIME}" + + # Start dlt-test-qnx-slogger and wait until it's done + echo "Start dlt-test-qnx-slogger" + "${DEV_AAP_DLT_PATH}"/dlt-test-qnx-slogger -n "${COUNT}" -d "${DELAY}" -l "${LENGTH}" > /dev/null + sleep "${SLEEP_TIME}" +} + +################################################################################ +# Function: dlt_qnx_test_result +# +# Description: Verify result from dlt_run_app() function +################################################################################ +dlt_qnx_test_result() +{ + echo "" + echo "Verify test result" + + TEST_RESULT_1="PASS" + TEST_RESULT_2="PASS" + TEST_RESULT_3="PASS" + BUFFER_NAME="dlt_test_qnx_slogger" + + ######################################### + # 1. Verify if all messages are received + ######################################### + RESULT_COUNT=$(grep "${BUFFER_NAME}.*slog" -c "${DLT_TEST_RESULT}") + if [ "${RESULT_COUNT}" -ne "${COUNT}" ]; then + echo "Number of log messages are not matching (Expected: ${COUNT}, Actual: ${RESULT_COUNT})" + TEST_RESULT_1="FAIL" + fi + + #### + RESULT=$(grep "${BUFFER_NAME}.*slog" "${DLT_TEST_RESULT}") + RESULT_TIME_PREV=0 + echo "$RESULT"| while read LINE + do + pr_verbose "$0" "TEST : LINE=${LINE}" + + RESULT_TIME=$(echo "${LINE}" | awk -F " " '{print $3}') + RESULT_PAYLOAD=$(echo "${LINE}" | awk -F " " '{print $17}') + + ############################################################# + # 2. Verify if each log messages have expected time interval + # Allow diff between ${DELAY} and ${DELAY}+10 msec + ############################################################# + pr_verbose "$0" "TEST2: RESULT_TIME=${RESULT_TIME}, RESULT_TIME_PREV=${RESULT_TIME_PREV}" + + # Compare diff of timestamps from second log message + if [ "${RESULT_TIME_PREV}" -ne 0 ]; then + RESULT_TIME_DIFF=$((RESULT_TIME - RESULT_TIME_PREV)) + + RANGE_MIN=$((DELAY * 10)) + RANGE_MAX=$(((DELAY + 10) * 10)) + if [[ "${RANGE_MIN}" -gt "${RESULT_TIME_DIFF}" ]] | [[ "${RANGE_MAX}" -le "${RESULT_TIME_DIFF}" ]]; then + echo "Diff of timestamp is too big (Expected diff: ${RANGE_MIN}-${RANGE_MAX}, Actual diff: ${RESULT_TIME_DIFF}" + TEST_RESULT_2="FAIL" + fi + fi + RESULT_TIME_PREV=${RESULT_TIME} + + ################################################################# + # 3. Verify if each log messages receives expected string length + ################################################################# + pr_verbose "$0" "TEST2: RESULT_PAYLOAD=${RESULT_PAYLOAD}" + + RESULT_LENGTH=$(echo ${#RESULT_PAYLOAD}) + if [ "${RESULT_LENGTH}" -ne "${LENGTH}" ]; then + echo "Length is not matching (Excepted:${LENGTH}, Actual:${RESULT_LENGTH})" + TEST_RESULT_3="FAIL" + fi + done + + # Print test result + echo " 1. Verify if all messages are received : ${TEST_RESULT_1}" + echo " 2. Verify if each log messages have expected time interval : ${TEST_RESULT_2}" + echo " 3. Verify if each log messages receives expected string length: ${TEST_RESULT_3}" +} + +################################################################################ +# Function: dlt_qnx_verify_app +# +# Description: Verify if necessary binaries are existing on the target and have +# execute permission +################################################################################ +dlt_qnx_verify_app() +{ + APP=$1 + + pr_verbose "$0" "Verify ${APP} is existing on the target and have execute permission" + + if [ ! -e "${APP}" ]; then + echo "${APP} is missing!" + exit 1 + elif [ ! -x "${APP}" ]; then + echo "${APP} does not have execute permission!" + exit 1 + fi +} + +################################################################################ +# Main +################################################################################ + +VERBOSE=0 + +SLEEP_TIME=1 + +COUNT=10 +DELAY=500 +LENGTH=100 + +DLT_TEST_RESULT="dlt_qnx_system_test.txt" +DLT_RECEIVE_FILTER="dlt_receive_filter.txt" + +DEV_AAP_DLT_PATH="/usr/bin" + +# OS +if [ "$(uname)" != "QNX" ]; then + echo "This script can be only run under QNX system!" + exit 1 +fi + +# Options +while getopts "vn:d:l:h" optKey; do + case "${optKey}" in + v) + VERBOSE=1 + ;; + n) + COUNT=${OPTARG} + ;; + d) + DELAY=${OPTARG} + ;; + l) + LENGTH=${OPTARG} + ;; + '-h'|'--help'|*) + usage + ;; + esac +done + +echo "*******************************" +echo " Run dlt-test-qnx-system with:" +echo " Number of logs: ${COUNT}" +echo " Delay : ${DELAY} msec" +echo " Payload length: ${LENGTH} bytes" +echo "*******************************" +echo "" + +# Verify if rb-dltd is running +if [ ! "$(slay -p -Q rb-dltd)" ]; then + echo "Start rb-dltd before running this script!" + exit 1 +fi + +# Verify necessary binaries are available under the target +dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-receive +dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-qnx-system +dlt_qnx_verify_app ${DEV_AAP_DLT_PATH}/dlt-test-qnx-slogger + +#dlt_qnx_configure_setup + +dlt_qnx_clean_app +dlt_qnx_clean_log + +dlt_qnx_run_app +dlt_qnx_clean_app + +dlt_qnx_test_result +dlt_qnx_clean_log -- cgit v1.2.1