treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / rcutorture / bin / mkinitrd.sh
blob38e424d2392cc2766fdb5c3ddd7f4bddacf04649
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
4 # Create an initrd directory if one does not already exist.
6 # Copyright (C) IBM Corporation, 2013
8 # Author: Connor Shu <Connor.Shu@ibm.com>
10 D=tools/testing/selftests/rcutorture
12 # Prerequisite checks
13 [ -z "$D" ] && echo >&2 "No argument supplied" && exit 1
14 if [ ! -d "$D" ]; then
15 echo >&2 "$D does not exist: Malformed kernel source tree?"
16 exit 1
18 if [ -s "$D/initrd/init" ]; then
19 echo "$D/initrd/init already exists, no need to create it"
20 exit 0
23 # Create a C-language initrd/init infinite-loop program and statically
24 # link it. This results in a very small initrd.
25 echo "Creating a statically linked C-language initrd"
26 cd $D
27 mkdir -p initrd
28 cd initrd
29 cat > init.c << '___EOF___'
30 #ifndef NOLIBC
31 #include <unistd.h>
32 #include <sys/time.h>
33 #endif
35 volatile unsigned long delaycount;
37 int main(int argc, int argv[])
39 int i;
40 struct timeval tv;
41 struct timeval tvb;
43 for (;;) {
44 sleep(1);
45 /* Need some userspace time. */
46 if (gettimeofday(&tvb, NULL))
47 continue;
48 do {
49 for (i = 0; i < 1000 * 100; i++)
50 delaycount = i * i;
51 if (gettimeofday(&tv, NULL))
52 break;
53 tv.tv_sec -= tvb.tv_sec;
54 if (tv.tv_sec > 1)
55 break;
56 tv.tv_usec += tv.tv_sec * 1000 * 1000;
57 tv.tv_usec -= tvb.tv_usec;
58 } while (tv.tv_usec < 1000);
60 return 0;
62 ___EOF___
64 # build using nolibc on supported archs (smaller executable) and fall
65 # back to regular glibc on other ones.
66 if echo -e "#if __x86_64__||__i386__||__i486__||__i586__||__i686__" \
67 "||__ARM_EABI__||__aarch64__\nyes\n#endif" \
68 | ${CROSS_COMPILE}gcc -E -nostdlib -xc - \
69 | grep -q '^yes'; then
70 # architecture supported by nolibc
71 ${CROSS_COMPILE}gcc -fno-asynchronous-unwind-tables -fno-ident \
72 -nostdlib -include ../../../../include/nolibc/nolibc.h \
73 -lgcc -s -static -Os -o init init.c
74 else
75 ${CROSS_COMPILE}gcc -s -static -Os -o init init.c
78 rm init.c
79 echo "Done creating a statically linked C-language initrd"
81 exit 0