xref: /freebsd/tools/test/stress2/misc/split.sh (revision 4d846d26)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
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# No problems seen
31
32# fsync: giving up on dirty 0xc9659438: tag devfs, type VCHR
33#     usecount 1, writecount 0, refcount 41 mountedhere 0xc96a2000
34#     flags (VI_ACTIVE)
35#     v_object 0xc9824aa0 ref 0 pages 355 cleanbuf 37 dirtybuf 2
36#     lock type devfs: EXCL by thread 0xccbca6a0 (pid 42225, dd, tid 100234)
37# #0 0xc0c26533 at __lockmgr_args+0xae3
38# #1 0xc0d06cc3 at vop_stdlock+0x53
39# #2 0xc1212cc0 at VOP_LOCK1_APV+0xe0
40# #3 0xc0d2b24a at _vn_lock+0xba
41# #4 0xc0f3f22b at ffs_sync+0x34b
42# #5 0xc0f22343 at softdep_ast_cleanup_proc+0x213
43# #6 0xc0ca7fbb at userret+0x1ab
44# #7 0xc11e0618 at syscall+0x5e8
45# #8 0xc11cb09e at Xint0x80_syscall+0x2e
46#         dev label/tmp
47
48. ../default.cfg
49
50[ -d $RUNDIR ] || mkdir -p $RUNDIR &&
51	find $RUNDIR -name "split.*" -delete
52export LANG=C
53s=0
54kfree=`df -k $RUNDIR | tail -1 | awk '{print $4}'`
55[ $kfree -gt 100 ] && kfree=$((kfree - 100))
56parallel=$((`sysctl -n hw.ncpu` + 1))
57parallel=2
58cap=$((9 * 1024 * 1024))	# 9GB
59mx=$((kfree / parallel / 2))
60[ $mx -gt $cap ] && mx=$cap
61
62run() {
63	local blocks md5 md5a orig s spmax spmin
64
65	s=0
66	cd $RUNDIR
67	blocks=`jot -r 1 1 $mx`
68	dd if=/dev/random of=file.$1 bs=1023 count=$blocks status=none
69	orig=`ls -l file.$1 | tail -1`
70	md5=`md5 -q file.$1`
71	spmin=$((1023 * 4))
72	spmax=$((1023 * blocks / 2))
73	rm -f split.$1.*
74	split -a 4 -b `jot -r 1 $spmin $spmax` file.$1 split.$1.
75	rm file.$1
76	cat split.$1.* > file.$1
77	rm split.$1.*
78	md5a=`md5 -q file.$1`
79	if [ $md5 != $md5a ]; then
80		echo FAIL
81		echo "orig $orig $md5"
82		orig=`ls -l file.$1 | tail -1`
83		echo "new  $orig $md5a"
84		s=1
85	fi
86	rm file.$1
87	return $s
88
89}
90
91for i in `jot $parallel`; do
92	run $i &
93	pids="$pids $!"
94done
95for pid in $pids; do
96	wait $pid
97	[ $? -ne 0 ] && s=1
98done
99exit $s
100