Philipp Maier | 7124ad1 | 2023-08-01 16:00:28 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Philipp Maier | ec9cdb7 | 2023-07-27 14:43:08 +0200 | [diff] [blame] | 2 | |
Philipp Maier | a380e4e | 2023-08-01 15:29:13 +0200 | [diff] [blame] | 3 | # 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 Maier | ec9cdb7 | 2023-07-27 14:43:08 +0200 | [diff] [blame] | 23 | PYSIM_TRACE=../pySim-trace.py |
| 24 | GSMTAP_TRACE=pySim-trace_test_gsmtap.pcapng |
Philipp Maier | a380e4e | 2023-08-01 15:29:13 +0200 | [diff] [blame] | 25 | TEMPFILE=temp.tmp |
Philipp Maier | ec9cdb7 | 2023-07-27 14:43:08 +0200 | [diff] [blame] | 26 | |
Philipp Maier | 4af63dc | 2023-10-26 12:17:32 +0200 | [diff] [blame] | 27 | export PYSIM_INTEGRATION_TEST=1 |
Harald Welte | a4b9bdf | 2023-12-23 10:26:51 +0100 | [diff] [blame] | 28 | # to avoid termcolor.colored generating colors; https://github.com/termcolor/termcolor |
| 29 | export ANSI_COLORS_DISABLED=1 |
Philipp Maier | 4af63dc | 2023-10-26 12:17:32 +0200 | [diff] [blame] | 30 | |
Philipp Maier | ec9cdb7 | 2023-07-27 14:43:08 +0200 | [diff] [blame] | 31 | echo "pySim-trace_test - a test program to test pySim-trace.py" |
| 32 | echo "========================================================" |
| 33 | |
Philipp Maier | a380e4e | 2023-08-01 15:29:13 +0200 | [diff] [blame] | 34 | function usage { |
| 35 | echo "Options:" |
| 36 | echo "-o: generate .ok file" |
| 37 | } |
| 38 | |
| 39 | function gen_ok_file { |
| 40 | $PYSIM_TRACE gsmtap-pyshark-pcap -f $GSMTAP_TRACE > $GSMTAP_TRACE.ok |
| 41 | echo "Generated file: $GSMTAP_TRACE.ok" |
| 42 | echo "------------8<------------" |
| 43 | cat $GSMTAP_TRACE.ok |
| 44 | echo "------------8<------------" |
| 45 | } |
| 46 | |
| 47 | function run_test { |
| 48 | $PYSIM_TRACE gsmtap-pyshark-pcap -f $GSMTAP_TRACE | tee $TEMPFILE |
| 49 | if [ ${PIPESTATUS[0]} -ne 0 ]; then |
| 50 | echo "" |
| 51 | echo "========================================================" |
| 52 | echo "Testrun with $GSMTAP_TRACE failed (exception)." |
| 53 | rm -f $TEMPFILE |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | DIFF=`diff $GSMTAP_TRACE.ok $TEMPFILE` |
| 58 | if ! [ -z "$DIFF" ]; then |
| 59 | echo "Testrun with $GSMTAP_TRACE failed (unexpected output)." |
| 60 | echo "------------8<------------" |
| 61 | diff $GSMTAP_TRACE.ok $TEMPFILE |
| 62 | echo "------------8<------------" |
| 63 | rm -f $TEMPFILE |
| 64 | exit 1 |
| 65 | fi |
| 66 | |
| 67 | echo "" |
| 68 | echo "========================================================" |
| 69 | echo "trace parsed without problems -- everything ok!" |
| 70 | rm -f $TEMPFILE |
| 71 | } |
| 72 | |
| 73 | OPT_GEN_OK_FILE=0 |
| 74 | while getopts ":ho" OPT; do |
| 75 | case $OPT in |
| 76 | h) |
| 77 | usage |
| 78 | exit 0 |
| 79 | ;; |
| 80 | o) |
| 81 | OPT_GEN_OK_FILE=1 |
| 82 | ;; |
| 83 | \?) |
| 84 | echo "Invalid option: -$OPTARG" >&2 |
| 85 | exit 1 |
| 86 | ;; |
| 87 | esac |
| 88 | done |
| 89 | |
| 90 | if [ $OPT_GEN_OK_FILE -eq 1 ]; then |
| 91 | gen_ok_file |
| 92 | exit 0 |
| 93 | else |
| 94 | run_test |
| 95 | exit 0 |
Philipp Maier | ec9cdb7 | 2023-07-27 14:43:08 +0200 | [diff] [blame] | 96 | fi |