cut: code shrink
[busybox-git.git] / scripts / randomtest
blobf6e0c9d8c28bfeac0fa5171b6cb4ec2bcadde646
1 #!/bin/sh
3 # If not specified in environment...
4 if ! test "$LIBC"; then
5 # Select which libc to build against
6 LIBC="glibc"
7 LIBC="uclibc"
8 fi
9 # x86 32-bit:
10 #CROSS_COMPILER_PREFIX="i486-linux-uclibc-"
11 # My system has strange prefix for x86 64-bit uclibc:
12 #CROSS_COMPILER_PREFIX="x86_64-pc-linux-gnu-"
14 if test $# -lt 2 || ! test -d "$1" || test -e "$2"; then
15 echo "Usage: $0 SRC_DIR TMP_DIR"
16 echo
17 echo "SRC_DIR will be copied to TMP_DIR directory."
18 echo "Then a random build will be performed."
19 echo
20 echo "Useful variables:"
21 echo "\$LIBC, \$CROSS_COMPILER_PREFIX, \$MAKEOPTS"
22 exit 1
25 cp -dpr -- "$1" "$2" || { echo "copy error"; exit 1; }
26 cd -- "$2" || { echo "cd $dir error"; exit 1; }
28 # Generate random config
29 make randconfig >/dev/null || { echo "randconfig error"; exit 1; }
31 # Tweak resulting config
32 cat .config \
33 | grep -v CONFIG_DEBUG_PESSIMIZE \
34 | grep -v CONFIG_WERROR \
35 | grep -v CONFIG_CROSS_COMPILER_PREFIX \
36 | grep -v CONFIG_SELINUX \
37 | grep -v CONFIG_EFENCE \
38 | grep -v CONFIG_DMALLOC \
40 | grep -v CONFIG_RFKILL \
41 >.config.new
42 mv .config.new .config
43 echo '# CONFIG_DEBUG_PESSIMIZE is not set' >>.config
44 echo '# CONFIG_WERROR is not set' >>.config
45 echo "CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILER_PREFIX}\"" >>.config
46 echo '# CONFIG_SELINUX is not set' >>.config
47 echo '# CONFIG_EFENCE is not set' >>.config
48 echo '# CONFIG_DMALLOC is not set' >>.config
49 echo '# CONFIG_RFKILL is not set' >>.config
51 # If glibc, don't build static
52 if test x"$LIBC" = x"glibc"; then
53 cat .config \
54 | grep -v CONFIG_STATIC \
55 | grep -v CONFIG_FEATURE_LIBBUSYBOX_STATIC \
57 | grep -v CONFIG_FEATURE_2_4_MODULES \
58 | grep -v CONFIG_FEATURE_USE_BSS_TAIL \
59 | grep -v CONFIG_DEBUG_SANITIZE \
60 | grep -v CONFIG_FEATURE_MOUNT_NFS \
61 | grep -v CONFIG_FEATURE_INETD_RPC \
62 >.config.new
63 mv .config.new .config
64 echo '# CONFIG_STATIC is not set' >>.config
65 echo '# CONFIG_FEATURE_LIBBUSYBOX_STATIC is not set' >>.config
66 # newer glibc (at least 2.23) no longer supply query_module() ABI.
67 # People who target 2.4 kernels would likely use older glibc (and older bbox).
68 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
69 echo '# CONFIG_FEATURE_USE_BSS_TAIL is not set' >>.config
70 echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
71 # 2018: current glibc versions no longer include rpc/rpc.h
72 echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
73 echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
76 # If uclibc, build static, and remove some things
77 # likely to not work on uclibc.
78 if test x"$LIBC" = x"uclibc"; then
79 cat .config \
80 | grep -v CONFIG_STATIC \
81 | grep -v CONFIG_BUILD_LIBBUSYBOX \
82 | grep -v CONFIG_PIE \
84 | grep -v CONFIG_FEATURE_2_4_MODULES \
85 | grep -v CONFIG_FEATURE_SYNC_FANCY \
86 | grep -v CONFIG_NANDWRITE \
87 | grep -v CONFIG_NANDDUMP \
88 | grep -v CONFIG_BLKDISCARD \
89 | grep -v CONFIG_NSENTER \
90 | grep -v CONFIG_UNSHARE \
91 | grep -v CONFIG_FALLOCATE \
92 | grep -v CONFIG_UDHCPC6 \
93 | grep -v CONFIG_NSLOOKUP \
94 | grep -v CONFIG_ASH_INTERNAL_GLOB \
95 >.config.new
96 mv .config.new .config
97 echo 'CONFIG_STATIC=y' >>.config
98 echo '# CONFIG_BUILD_LIBBUSYBOX is not set' >>.config
99 echo '# CONFIG_PIE is not set' >>.config
100 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
101 echo '# CONFIG_FEATURE_SYNC_FANCY is not set' >>.config
102 # My uclibc installation does not support some needed APIs...
103 echo '# CONFIG_NANDWRITE is not set' >>.config
104 echo '# CONFIG_NANDDUMP is not set' >>.config
105 echo '# CONFIG_BLKDISCARD is not set' >>.config
106 echo '# CONFIG_NSENTER is not set' >>.config
107 echo '# CONFIG_UNSHARE is not set' >>.config
108 echo '# CONFIG_FALLOCATE is not set' >>.config
109 echo '# CONFIG_UDHCPC6 is not set' >>.config
110 echo '# CONFIG_NSLOOKUP is not set' >>.config
111 echo 'CONFIG_ASH_INTERNAL_GLOB=y' >>.config
114 # If musl
115 if test x"$LIBC" = x"musl"; then
116 cat .config \
117 | grep -v CONFIG_STATIC \
118 | grep -v CONFIG_DEBUG_SANITIZE \
119 | grep -v CONFIG_LFS \
120 | grep -v CONFIG_EXTRA_COMPAT \
121 | grep -v CONFIG_FEATURE_2_4_MODULES \
122 | grep -v CONFIG_FEATURE_VI_REGEX_SEARCH \
123 | grep -v CONFIG_FEATURE_MOUNT_NFS \
124 | grep -v CONFIG_FEATURE_INETD_RPC \
125 >.config.new
126 mv .config.new .config
127 echo 'CONFIG_STATIC=y' >>.config
128 # "error: cannot specify -static with -fsanitize=address":
129 echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
130 # with LFS off, uoff_t will have wrong width:
131 echo 'CONFIG_LFS=y' >>.config
132 echo '# CONFIG_EXTRA_COMPAT is not set' >>.config
133 echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
134 echo '# CONFIG_FEATURE_VI_REGEX_SEARCH is not set' >>.config
135 echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
136 echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
139 # If STATIC, remove some things.
140 # PAM with static linking is probably pointless
141 # (but I need to try - now I don't have libpam.a on my system, only libpam.so)
142 if grep -q "^CONFIG_STATIC=y" .config; then
143 cat .config \
144 | grep -v CONFIG_PAM \
145 >.config.new
146 mv .config.new .config
147 echo '# CONFIG_PAM is not set' >>.config
150 # Regenerate .config with default answers for yanked-off options
151 # (most of default answers are "no").
152 { yes "" | make oldconfig >/dev/null; } || { echo "oldconfig error"; exit 1; }
154 # Build!
155 nice -n 10 make $MAKEOPTS 2>&1 | tee make.log
156 grep 'Rerun make' make.log \
157 && nice -n 10 make $MAKEOPTS 2>&1 | tee -a make.log
159 # Return exitcode 1 if busybox executable does not exist
160 test -x busybox