summaryrefslogtreecommitdiff
path: root/tests/start_qnx_system_test.sh
blob: 90478f74de00816736dfe5f1a24c94658931d724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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 <<EOM
Usage: ./start_qnx_system_test.sh [OPTION]...
  -h           Display help
  -v           Verbose mode
  -n count     Number of messages to be generated (Default: 10)
  -d delay     Milliseconds to wait between sending messages (Default: 500).
  -l length    Message payload length (Default: 100 bytes)
EOM

    exit 2
}

pr_verbose()
{
    VERBOSE_FUNC=$1
    VERBOSE_MSG=$2

    if [ "${VERBOSE}" -eq 1 ]; then
        echo ""
        echo "${VERBOSE_FUNC}: ${VERBOSE_MSG}"
    fi
}

################################################################################
# Function:    dlt_qnx_configure_setup
#
# Description: Setup configuration and json files for testing
################################################################################
#dlt_qnx_configure_setup()
#{
    # Replace parameter dlt-qnx-system.conf if necessary
    # Replace json value if necessary

    # Nothing to do as of now
#}

################################################################################
# Function:    dlt_qnx_clean_app
#
# Description: Clean up applications
################################################################################
dlt_qnx_clean_app()
{
    pr_verbose "$0" "Stop applications"

    slay -f dlt-test-qnx-slogger
    sleep "${SLEEP_TIME}"
    slay -f dlt-qnx-system
    sleep "${SLEEP_TIME}"
    slay -f dlt-receive
    sleep "${SLEEP_TIME}"
    rm -f "${DLT_RECEIVE_FILTER}"
    sleep "${SLEEP_TIME}"
}

################################################################################
# Function:    dlt_qnx_clean_log
#
# Description: Clean up logs
################################################################################
dlt_qnx_clean_log()
{
    pr_verbose "$0" "Delete logs"

    rm -f "${DLT_TEST_RESULT}"
}

################################################################################
# Function:    dlt_qnx_run_app
#
# Description: Start applications for testing
################################################################################
dlt_qnx_run_app()
{
    pr_verbose "$0" "Start dlt-qnx-system testing"

    export LD_LIBRARY_PATH=/opt/lib_tmp:$LD_LIBRARY_PATH

    # Prepare a text file to filter log messages by specific AppID and Ctx ID
    echo "QSYM QSLA" > "${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