xref: /aosp_15_r20/external/libopus/tests/random_config.sh (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1#!/bin/bash
2
3dir="$1"
4mkdir "$dir"
5if [ $? -ne 0 ]
6then
7        exit 1
8fi
9
10cd "$dir"
11if [ $? -ne 0 ]
12then
13        exit 1
14fi
15
16
17configure_path="$2"
18config="random_config.txt"
19
20case `seq 3 | shuf -n1` in
211)
22approx=--enable-float-approx
23math=-ffast-math
24;;
252)
26approx=--enable-float-approx
27;;
28*)
29approx=
30math=
31;;
32esac
33
34CFLAGS='-g'
35
36opt=`echo -e "-O1\n-O2\n-O3" | shuf -n1`
37
38arch=`echo -e "\n-march=core2\n-march=sandybridge\n-march=broadwell\n-march=skylake" | shuf -n1`
39
40footprint=`echo -e "\n-DSMALL_FOOTPRINT" | shuf -n1`
41std=`echo -e "\n-std=c90\n-std=c99\n-std=c11\n-std=c17" | shuf -n1`
42sanitize=`echo -e "\n-fsanitize=address -fno-sanitize-recover=all\n-fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -DDISABLE_PTR_CHECK" | shuf -n1`
43
44
45CFLAGS="$CFLAGS $std $opt $arch $footprint $math $sanitize"
46
47echo "CFLAGS=$CFLAGS" > "$config"
48
49lib=`echo -e "\n--disable-static\n--disable-shared" | shuf -n1`
50
51arithmetic=`echo -e "\n--enable-deep-plc\n--enable-dred\n--enable-osce\n--enable-dred --enable-osce\n--enable-fixed-point\n--enable-fixed-point --enable-fixed-point-debug\n--enable-fixed-point --disable-float-api\n--enable-fixed-point --enable-fixed-point-debug --disable-float-api" | shuf -n1`
52
53custom=`echo -e "\n--enable-custom-modes" | shuf -n1`
54
55asm=`echo -e "\n--disable-asm\n--disable-rtcd\n--disable-intrinsics" | shuf -n1`
56#asm=`echo -e "\n--disable-asm\n--disable-intrinsics" | shuf -n1`
57
58assert=`echo -e "\n--enable-assertions" | shuf -n1`
59harden=`echo -e "\n--enable-hardening" | shuf -n1`
60fuzz=`echo -e "\n--enable-fuzzing" | shuf -n1`
61checkasm=`echo -e "\n--enable-check-asm" | shuf -n1`
62rfc8251=`echo -e "\n--disable-rfc8251" | shuf -n1`
63lossgen=`echo -e "\n--enable-lossgen" | shuf -n1`
64
65if [ "$rfc8251" = --disable-rfc8251 ]
66then
67        vectors="$3"
68else
69        vectors="$4"
70fi
71echo using testvectors at "$vectors" >> "$config"
72
73
74config_opt="$lib $arithmetic $custom $asm $assert $harden $fuzz $checkasm $rfc8251 $approx $lossgen"
75
76echo configure $config_opt >> "$config"
77
78export CFLAGS
79"$configure_path/configure" $config_opt > configure_output.txt 2>&1
80
81if [ $? -ne 0 ]
82then
83        echo configure FAIL >> "$config"
84        exit 1
85fi
86
87make > make_output.txt 2>&1
88
89if [ $? -ne 0 ]
90then
91        echo make FAIL >> "$config"
92        exit 1
93fi
94
95#Run valgrind 5% of the time (minus the asan cases)
96if [ "`seq 20 | shuf -n1`" -ne 1 -o "$sanitize" = "-fsanitize=address -fno-sanitize-recover=all" ]
97then
98        make check > makecheck_output.txt 2>&1
99else
100        echo valgrind enabled >> "$config"
101        valgrind --trace-children=yes --error-exitcode=128 make check > makecheck_output.txt 2>&1
102fi
103
104if [ $? -ne 0 ]
105then
106        echo check FAIL >> "$config"
107        exit 1
108fi
109
110
111rate=`echo -e "8000\n12000\n16000\n24000\n48000" | shuf -n1`
112echo testvectors for "$rate" Hz > testvectors_output.txt
113../../../run_vectors.sh . "$vectors" "$rate" >> testvectors_output.txt 2>&1
114
115if [ $? -ne 0 ]
116then
117        echo testvectors FAIL >> "$config"
118        exit 1
119fi
120
121echo all tests PASS >> "$config"
122
123#When everything's good, do some cleaning up to save space
124make distclean > /dev/null 2>&1
125rm -f tmp.out
126gzip make_output.txt
127