xref: /freebsd/tools/test/stress2/misc/vm_fault.sh (revision 8296d2f9a3bf8e68de2f8e3f98f911b9b9542dad)
1*8296d2f9SPeter Holm#!/bin/sh
2*8296d2f9SPeter Holm
3*8296d2f9SPeter Holm# Regression test for D33416 vm_fault: Fix vm_fault_populate()'s handling of VM_FAULT_WIRE
4*8296d2f9SPeter Holm# Bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260347
5*8296d2f9SPeter Holm
6*8296d2f9SPeter Holm# Test scenario by: martin
7*8296d2f9SPeter Holm
8*8296d2f9SPeter Holm# Fixed by 88642d978a99
9*8296d2f9SPeter Holm
10*8296d2f9SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
11*8296d2f9SPeter Holm[ -d /usr/src/sys ] || exit 0
12*8296d2f9SPeter Holmbuilddir=`sysctl kern.version | grep @ | sed 's/.*://'`
13*8296d2f9SPeter Holm[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0
14*8296d2f9SPeter Holmexport SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'`
15*8296d2f9SPeter Holm
16*8296d2f9SPeter Holm. ../default.cfg
17*8296d2f9SPeter Holm
18*8296d2f9SPeter Holmodir=`pwd`
19*8296d2f9SPeter Holmdir=$RUNDIR/skeleton
20*8296d2f9SPeter Holmmkdir -p $dir
21*8296d2f9SPeter Holm
22*8296d2f9SPeter Holmcd $dir
23*8296d2f9SPeter Holmcat > skeleton.c <<EOF
24*8296d2f9SPeter Holm/*
25*8296d2f9SPeter Holm * KLD Skeleton
26*8296d2f9SPeter Holm * Inspired by Andrew Reiter's Daemonnews article
27*8296d2f9SPeter Holm */
28*8296d2f9SPeter Holm
29*8296d2f9SPeter Holm#include <sys/param.h>
30*8296d2f9SPeter Holm#include <sys/module.h>
31*8296d2f9SPeter Holm#include <sys/systm.h>  /* uprintf */
32*8296d2f9SPeter Holm#include <sys/errno.h>
33*8296d2f9SPeter Holm#include <sys/param.h>  /* defines used in kernel.h */
34*8296d2f9SPeter Holm#include <sys/kernel.h> /* types used in module initialization */
35*8296d2f9SPeter Holm
36*8296d2f9SPeter Holm#define BUFFER_SIZE 10*1000*1024 // 10 MB
37*8296d2f9SPeter Holmstatic char gBuffer[BUFFER_SIZE];
38*8296d2f9SPeter Holm
39*8296d2f9SPeter Holmstatic int demo_init (void)
40*8296d2f9SPeter Holm{
41*8296d2f9SPeter Holm  for (int i=0; i<BUFFER_SIZE; i++)
42*8296d2f9SPeter Holm  {
43*8296d2f9SPeter Holm    gBuffer[i] = 'A';
44*8296d2f9SPeter Holm  }
45*8296d2f9SPeter Holm  return 0;
46*8296d2f9SPeter Holm}
47*8296d2f9SPeter Holm
48*8296d2f9SPeter Holmstatic void demo_exit (void)
49*8296d2f9SPeter Holm{
50*8296d2f9SPeter Holm  for (int i=0; i<BUFFER_SIZE; i++)
51*8296d2f9SPeter Holm  {
52*8296d2f9SPeter Holm    gBuffer[i] += 1;
53*8296d2f9SPeter Holm  }
54*8296d2f9SPeter Holm}
55*8296d2f9SPeter Holm
56*8296d2f9SPeter Holm/*
57*8296d2f9SPeter Holm * Load handler that deals with the loading and unloading of a KLD.
58*8296d2f9SPeter Holm */
59*8296d2f9SPeter Holm
60*8296d2f9SPeter Holmstatic int
61*8296d2f9SPeter Holmskel_loader(struct module *m, int what, void *arg)
62*8296d2f9SPeter Holm{
63*8296d2f9SPeter Holm  int err = 0;
64*8296d2f9SPeter Holm
65*8296d2f9SPeter Holm  switch (what) {
66*8296d2f9SPeter Holm  case MOD_LOAD:                /* kldload */
67*8296d2f9SPeter Holm    uprintf("Skeleton KLD loaded.\n");
68*8296d2f9SPeter Holm    demo_init();
69*8296d2f9SPeter Holm    break;
70*8296d2f9SPeter Holm  case MOD_UNLOAD:
71*8296d2f9SPeter Holm    uprintf("Skeleton KLD unloaded.\n");
72*8296d2f9SPeter Holm    demo_exit();
73*8296d2f9SPeter Holm    break;
74*8296d2f9SPeter Holm  default:
75*8296d2f9SPeter Holm    err = EOPNOTSUPP;
76*8296d2f9SPeter Holm    break;
77*8296d2f9SPeter Holm  }
78*8296d2f9SPeter Holm  return(err);
79*8296d2f9SPeter Holm}
80*8296d2f9SPeter Holm
81*8296d2f9SPeter Holm/* Declare this module to the rest of the kernel */
82*8296d2f9SPeter Holm
83*8296d2f9SPeter Holmstatic moduledata_t skel_mod = {
84*8296d2f9SPeter Holm  "skel",
85*8296d2f9SPeter Holm  skel_loader,
86*8296d2f9SPeter Holm  NULL
87*8296d2f9SPeter Holm};
88*8296d2f9SPeter Holm
89*8296d2f9SPeter HolmDECLARE_MODULE(skeleton, skel_mod, SI_SUB_KLD, SI_ORDER_ANY);
90*8296d2f9SPeter HolmEOF
91*8296d2f9SPeter Holm
92*8296d2f9SPeter Holmcat > Makefile <<EOF
93*8296d2f9SPeter HolmKMOD= skeleton
94*8296d2f9SPeter HolmSRCS= skeleton.c
95*8296d2f9SPeter Holm
96*8296d2f9SPeter Holm.include <bsd.kmod.mk>
97*8296d2f9SPeter HolmEOF
98*8296d2f9SPeter Holm
99*8296d2f9SPeter Holmmake
100*8296d2f9SPeter Holmold=`sysctl -n vm.stats.vm.v_wire_count`
101*8296d2f9SPeter Holmkldload $dir/skeleton.ko
102*8296d2f9SPeter Holmkldunload $dir/skeleton.ko
103*8296d2f9SPeter Holmleak=$((`sysctl -n vm.stats.vm.v_wire_count` - old))
104*8296d2f9SPeter Holmif [ $leak -gt 25 ]; then
105*8296d2f9SPeter Holm	echo "Test leaked $leak pages in the skeleton.ko module"
106*8296d2f9SPeter Holm	s=1
107*8296d2f9SPeter Holmelse
108*8296d2f9SPeter Holm	s=0
109*8296d2f9SPeter Holmfi
110*8296d2f9SPeter Holm
111*8296d2f9SPeter Holmcd $odir
112*8296d2f9SPeter Holmrm -rf $dir
113*8296d2f9SPeter Holmexit $s
114