blob: 4ccb2aa82cab3c353259f05964464d60647f4e30 [file] [log] [blame]
Philipp Maier7124ad12023-08-01 16:00:28 +02001#!/bin/bash
Philipp Maierec9cdb72023-07-27 14:43:08 +02002
Philipp Maiera380e4e2023-08-01 15:29:13 +02003# Utility to verify the functionality of pySim-trace.py
4#
5# (C) 2023 by Sysmocom s.f.m.c. GmbH
6# All Rights Reserved
7#
8# Author: Philipp Maier
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
Philipp Maierec9cdb72023-07-27 14:43:08 +020023PYSIM_TRACE=../pySim-trace.py
24GSMTAP_TRACE=pySim-trace_test_gsmtap.pcapng
Philipp Maiera380e4e2023-08-01 15:29:13 +020025TEMPFILE=temp.tmp
Philipp Maierec9cdb72023-07-27 14:43:08 +020026
27echo "pySim-trace_test - a test program to test pySim-trace.py"
28echo "========================================================"
29
Philipp Maiera380e4e2023-08-01 15:29:13 +020030function usage {
31 echo "Options:"
32 echo "-o: generate .ok file"
33}
34
35function gen_ok_file {
36 $PYSIM_TRACE gsmtap-pyshark-pcap -f $GSMTAP_TRACE > $GSMTAP_TRACE.ok
37 echo "Generated file: $GSMTAP_TRACE.ok"
38 echo "------------8<------------"
39 cat $GSMTAP_TRACE.ok
40 echo "------------8<------------"
41}
42
43function run_test {
44 $PYSIM_TRACE gsmtap-pyshark-pcap -f $GSMTAP_TRACE | tee $TEMPFILE
45 if [ ${PIPESTATUS[0]} -ne 0 ]; then
46 echo ""
47 echo "========================================================"
48 echo "Testrun with $GSMTAP_TRACE failed (exception)."
49 rm -f $TEMPFILE
50 exit 1
51 fi
52
53 DIFF=`diff $GSMTAP_TRACE.ok $TEMPFILE`
54 if ! [ -z "$DIFF" ]; then
55 echo "Testrun with $GSMTAP_TRACE failed (unexpected output)."
56 echo "------------8<------------"
57 diff $GSMTAP_TRACE.ok $TEMPFILE
58 echo "------------8<------------"
59 rm -f $TEMPFILE
60 exit 1
61 fi
62
63 echo ""
64 echo "========================================================"
65 echo "trace parsed without problems -- everything ok!"
66 rm -f $TEMPFILE
67}
68
69OPT_GEN_OK_FILE=0
70while getopts ":ho" OPT; do
71 case $OPT in
72 h)
73 usage
74 exit 0
75 ;;
76 o)
77 OPT_GEN_OK_FILE=1
78 ;;
79 \?)
80 echo "Invalid option: -$OPTARG" >&2
81 exit 1
82 ;;
83 esac
84done
85
86if [ $OPT_GEN_OK_FILE -eq 1 ]; then
87 gen_ok_file
88 exit 0
89else
90 run_test
91 exit 0
Philipp Maierec9cdb72023-07-27 14:43:08 +020092fi