xref: /freebsd/tools/test/stress2/misc/wire_no_page.sh (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1#!/bin/sh
2
3#
4# Copyright (c) 2013 Peter Holm <pho@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Test scenario by kib@
30
31# "panic: vm_page_set_invalid: page 0xc3dfe8c0 is busy" seen.
32
33[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34
35. ../default.cfg
36
37dir=/tmp
38odir=`pwd`
39cd $dir
40sed '1,/^EOF/d' < $odir/$0 > $dir/wire_no_page.c
41mycc -o wire_no_page -Wall -Wextra wire_no_page.c -lpthread || exit 1
42rm -f wire_no_page.c
43cd $odir
44
45cp /tmp/wire_no_page /tmp/wire_no_page2
46start=`date '+%s'`
47while [ $((`date '+%s'` - start)) -lt 300 ]; do
48	for i in `jot 50`; do
49		/tmp/wire_no_page /tmp/wire_no_page2 &
50	done
51	wait
52done
53
54rm -f /tmp/wire_no_page /tmp/wire_no_page2
55exit
56
57EOF
58/* $Id: wire_no_page.c,v 1.1 2013/05/17 07:50:30 kostik Exp kostik $ */
59#include <sys/types.h>
60#include <sys/param.h>
61#include <sys/fcntl.h>
62#include <sys/mman.h>
63#include <sys/stat.h>
64#include <err.h>
65#include <unistd.h>
66
67int
68main(int argc, char *argv[])
69{
70	struct stat st;
71	char *p1, *p2;
72	size_t len;
73	pid_t child;
74	int error, fd;
75
76	if (argc < 2)
77		errx(1, "file name ?");
78	fd = open(argv[1], O_RDWR);
79	if (fd == -1)
80		err(1, "open %s", argv[1]);
81	error = fstat(fd, &st);
82	if (error == -1)
83		err(1, "stat");
84	len = round_page(st.st_size);
85	p1 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
86	if ((void *)p1 == MAP_FAILED)
87		err(1, "mmap");
88	error = mlock(p1, len);
89	if (error == -1)
90		err(1, "mlock");
91	p2 = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
92	if ((void *)p2 == MAP_FAILED)
93		err(1, "mmap");
94	error = msync(p2, len, MS_SYNC | MS_INVALIDATE);
95	if (error == -1)
96		err(1, "msync");
97	child = fork();
98	if (child == -1)
99		err(1, "fork");
100	else if (child == 0)
101		_exit(0);
102
103	return (0);
104}
105