831be1a7397d9b8cc2e0710eb36bf2a0fd50c497
[com/asn1c.git] / tests / tests-asn1c-smoke / check-asn1c-smoke.sh
1 #!/usr/bin/env bash
2
3 set -x
4 set -e
5 set -o pipefail
6
7 top_builddir=${top_builddir:-../..}
8 top_srcdir=${top_srcdir:-../..}
9
10 cleanup() {
11     rm -rf *.[acho] Makefile.am.* *.mk *.txt *.asn
12     rm -f converter-example
13 }
14
15 print_state() {
16     local err=$?
17     set +x
18     set +e
19     trap "" EXIT ERR
20     echo "Error $err while processing:"
21     cat test.asn
22     cat status.txt
23     echo "FAILED"
24     exit $err
25 }
26
27 verify() {
28     local type="$1"
29     local flags="$2"
30
31     cleanup
32
33     asncmd="${top_builddir}/asn1c/asn1c -Wdebug-compiler -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
34
35     {
36     echo "$asncmd"
37     echo "${MAKE:-make} -f converter-example.mk"
38     } > status.txt
39
40     echo "Module DEFINITIONS::=BEGIN T::=$type END" > test.asn
41     $asncmd
42     CFLAGS=-O0 ${MAKE:-make} -f converter-example.mk | tail -10
43 }
44
45 verify_type_with_variants() {
46     local type="$1"
47     for flags in "-no-gen-PER" "-no-gen-OER" "-no-gen-PER -no-gen-OER" ""; do
48         for native in "" "-fwide-types"; do
49             verify "$type" "$flags $native"
50         done
51     done
52 }
53
54 verify_compile_and_link_variants() {
55     for type in INTEGER "INTEGER(0..1)" "ENUMERATED{foo}" NULL BOOLEAN \
56                 "BIT STRING" \
57                 "OBJECT IDENTIFIER" "RELATIVE-OID" \
58                 "SEQUENCE{f INTEGER}" \
59                 "CHOICE{f INTEGER}" \
60                 "OCTET STRING" IA5String "IA5String(SIZE(1))" UTF8String \
61                 REAL "SET OF INTEGER" "SEQUENCE OF INTEGER"; do
62         verify_type_with_variants "$type"
63     done
64 }
65
66 trap print_state EXIT ERR
67 if [ "x$*" = "x" ]; then
68     verify_compile_and_link_variants
69 else
70     for type in "$@"; do
71         verify_type_with_variants "$type"
72     done
73 fi
74 set +x
75 trap '' EXIT ERR
76
77 cleanup
78 echo "OK"