xref: /freebsd/tools/test/stress2/misc/mmap29.sh (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1#!/bin/sh
2
3# Test scenario by: David Cross <dcrosstech@gmail.com>
4
5# "panic: softdep_deallocate_dependencies: dangling deps" seen.
6# https://people.freebsd.org/~pho/stress/log/mmap29.txt
7# Fixed by: r302567.
8
9. ../default.cfg
10[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
11
12[ -z "`which timeout`" ] && exit 0
13mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint
14mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
15mdconfig -a -t swap -s 2g -u $mdstart || exit 1
16newfs -U md$mdstart > /dev/null
17mount /dev/md$mdstart $mntpoint
18
19mkdir $mntpoint/mmap29
20cd /tmp
21cat > mmap29.c <<EOFHERE
22#include <sys/param.h>
23#include <sys/mman.h>
24#include <sys/stat.h>
25
26#include <err.h>
27#include <fcntl.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <unistd.h>
31
32int
33main(int argc, char **argv)
34{
35        int fd;
36        unsigned char *memrange;
37
38	if (argc != 2) {
39		fprintf(stderr, "Usage: %s <file>\n", argv[0]);
40		exit(1);
41	}
42        unlink(argv[1]);
43        if ((fd = open(argv[1], O_RDWR | O_CREAT, DEFFILEMODE)) == -1)
44		err(1, "open(%s)", argv[1]);
45        lseek(fd, 0xbfff, SEEK_SET);
46        write(fd, "\0", 1);
47        if ((memrange = mmap(0, 0x2b6000, PROT_READ | PROT_WRITE, MAP_SHARED |
48	    MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0)) == MAP_FAILED)
49		err(1, "mmap");
50        memrange[0] = 5;
51        munmap(memrange, 0x2b6000);
52        close(fd);
53
54        return (0);
55}
56EOFHERE
57
58cc -o mmap29 -Wall -Wextra -O0 -g mmap29.c || exit 1
59rm mmap29.c
60./mmap29 $mntpoint/mmap29/mmap291
61old=`sysctl -n kern.maxvnodes`
62trap "sysctl kern.maxvnodes=$old" EXIT INT
63sysctl kern.maxvnodes=2000
64timeout 60 find / -xdev -print >/dev/null
65while mount | grep "on $mntpoint " | grep -q /dev/md; do
66	umount $mntpoint || sleep 1
67done
68mdconfig -d -u $mdstart
69rm mmap29
70exit 0
71