xref: /freebsd/tools/test/stress2/misc/buildworld3.sh (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2018 Dell EMC Isilon
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# Buildworld / quota test scenario.
31
32# "panic: chkdquot: missing dquot" seen
33# https://people.freebsd.org/~pho/stress/log/kostik1113.txt
34# Fixed in r338798 + r338799
35
36. ../default.cfg
37
38[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
39
40[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0
41[ -d /usr/src/sys ] || exit 0
42mount | grep -q "on $mntpoint " && umount $mntpoint
43mdconfig -a -t swap -s 2g -u $mdstart
44newfs $newfs_flags md$mdstart > /dev/null
45
46export PATH_FSTAB=/tmp/fstab
47trap "rm -f $PATH_FSTAB" EXIT INT
48echo "/dev/md$mdstart $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB
49mount $mntpoint
50set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'`
51export QK=$(($1 / 2))
52export QI=$(($2 / 2))
53edquota -u -f $mntpoint -e \
54    ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser
55quotaon $mntpoint
56mount | grep $mntpoint
57
58cd /usr/src
59export MAKEOBJDIRPREFIX=$mntpoint/obj
60export TMPDIR=$mntpoint/tmp
61mkdir $TMPDIR $MAKEOBJDIRPREFIX
62chmod 0777 $TMPDIR $MAKEOBJDIRPREFIX
63
64p=$((`sysctl -n hw.ncpu`+ 1))
65su $testuser -c \
66    "make -i -j $p buildworld  DESTDIR=$mntpoint TARGET=amd64 \
67    TARGET_ARCH=amd64 > /dev/null" &
68sleep 2
69start=`date +%s`
70while [ $((`date +%s` - start)) -lt 1200 ]; do
71	kill -0 $! > /dev/null 2>&1 || break
72	sleep 2
73done
74kill $! > /dev/null 2>&1
75# Let make run 50% of the time so quotaoff runs on an active FS
76[ `jot -r 1 0 1` -eq 1 ] &&
77	pkill -U$testuser make
78wait
79
80while ! quotaoff $mntpoint; do
81	sync
82	sleep 5
83done
84pgrep -q -U$testuser make && pkill -U$testuser make
85export tmp=/tmp/$(basename $0).$$
86quotacheck -v $mntpoint > $tmp 2>&1
87grep -q failed $tmp && { cat $tmp; s=1; }
88while mount | grep -q "on $mntpoint "; do
89	umount $mntpoint || sleep 1
90done
91checkfs /dev/md$mdstart || s=$?
92mdconfig -d -u $mdstart
93rm -f $PATH_FSTAB
94exit $s
95