Home | History | Annotate | Line # | Download | only in dtrace
      1  1.3     chs /*	$NetBSD: dtrace_test.c,v 1.3 2018/05/28 21:05:03 chs Exp $	*/
      2  1.2  darran 
      3  1.1  darran /*-
      4  1.1  darran  * Copyright 2008 John Birrell <jb (at) FreeBSD.org>
      5  1.1  darran  *
      6  1.1  darran  * Redistribution and use in source and binary forms, with or without
      7  1.1  darran  * modification, are permitted provided that the following conditions
      8  1.1  darran  * are met:
      9  1.1  darran  * 1. Redistributions of source code must retain the above copyright
     10  1.1  darran  *    notice, this list of conditions and the following disclaimer.
     11  1.1  darran  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  darran  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  darran  *    documentation and/or other materials provided with the distribution.
     14  1.1  darran  *
     15  1.1  darran  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  darran  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  darran  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  darran  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  darran  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  darran  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  darran  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  darran  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  darran  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  darran  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  darran  * SUCH DAMAGE.
     26  1.1  darran  *
     27  1.3     chs  * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_test.c 258622 2013-11-26 08:46:27Z avg $
     28  1.1  darran  *
     29  1.1  darran  */
     30  1.1  darran #include <sys/cdefs.h>
     31  1.1  darran #include <sys/types.h>
     32  1.1  darran #include <sys/param.h>
     33  1.3     chs #include <sys/systm.h>
     34  1.3     chs 
     35  1.1  darran #include <sys/conf.h>
     36  1.1  darran #include <sys/kernel.h>
     37  1.1  darran #include <sys/module.h>
     38  1.3     chs #include <sys/sdt.h>
     39  1.3     chs #include <sys/sysctl.h>
     40  1.1  darran #include <sys/vnode.h>
     41  1.1  darran 
     42  1.3     chs SDT_PROVIDER_DEFINE(test);
     43  1.3     chs 
     44  1.3     chs SDT_PROBE_DEFINE7(test, , , sdttest, "int", "int", "int", "int", "int",
     45  1.3     chs     "int", "int");
     46  1.3     chs 
     47  1.1  darran /*
     48  1.1  darran  * These are variables that the DTrace test suite references in the
     49  1.1  darran  * Solaris kernel. We define them here so that the tests function
     50  1.1  darran  * unaltered.
     51  1.1  darran  */
     52  1.1  darran int	kmem_flags;
     53  1.1  darran 
     54  1.1  darran typedef struct vnode vnode_t;
     55  1.1  darran vnode_t dummy;
     56  1.1  darran vnode_t *rootvp = &dummy;
     57  1.1  darran 
     58  1.3     chs /*
     59  1.3     chs  * Test SDT probes with more than 5 arguments. On amd64, such probes require
     60  1.3     chs  * special handling since only the first 5 arguments will be passed to
     61  1.3     chs  * dtrace_probe() in registers; the rest must be fetched off the stack.
     62  1.3     chs  */
     63  1.3     chs static int
     64  1.3     chs dtrace_test_sdttest(SYSCTL_HANDLER_ARGS)
     65  1.3     chs {
     66  1.3     chs 	int val, error;
     67  1.3     chs 
     68  1.3     chs 	val = 0;
     69  1.3     chs 	error = sysctl_handle_int(oidp, &val, 0, req);
     70  1.3     chs 	if (error || req->newptr == NULL)
     71  1.3     chs 		return (error);
     72  1.3     chs 	else if (val == 0)
     73  1.3     chs 		return (0);
     74  1.3     chs 
     75  1.3     chs 	SDT_PROBE7(test, , , sdttest, 1, 2, 3, 4, 5, 6, 7);
     76  1.3     chs 
     77  1.3     chs 	return (error);
     78  1.3     chs }
     79  1.3     chs 
     80  1.3     chs static SYSCTL_NODE(_debug, OID_AUTO, dtracetest, CTLFLAG_RD, 0, "");
     81  1.3     chs 
     82  1.3     chs SYSCTL_PROC(_debug_dtracetest, OID_AUTO, sdttest, CTLTYPE_INT | CTLFLAG_RW,
     83  1.3     chs     NULL, 0, dtrace_test_sdttest, "I", "Trigger the SDT test probe");
     84  1.3     chs 
     85  1.1  darran static int
     86  1.1  darran dtrace_test_modevent(module_t mod, int type, void *data)
     87  1.1  darran {
     88  1.1  darran 	int error = 0;
     89  1.1  darran 
     90  1.1  darran 	switch (type) {
     91  1.1  darran 	case MOD_LOAD:
     92  1.1  darran 		break;
     93  1.1  darran 
     94  1.1  darran 	case MOD_UNLOAD:
     95  1.1  darran 		break;
     96  1.1  darran 
     97  1.1  darran 	case MOD_SHUTDOWN:
     98  1.1  darran 		break;
     99  1.1  darran 
    100  1.1  darran 	default:
    101  1.1  darran 		error = EOPNOTSUPP;
    102  1.1  darran 		break;
    103  1.1  darran 
    104  1.1  darran 	}
    105  1.1  darran 	return (error);
    106  1.1  darran }
    107  1.1  darran 
    108  1.1  darran DEV_MODULE(dtrace_test, dtrace_test_modevent, NULL);
    109  1.1  darran MODULE_VERSION(dtrace_test, 1);
    110  1.1  darran MODULE_DEPEND(dtrace_test, dtraceall, 1, 1, 1);
    111