Home | History | Annotate | Line # | Download | only in kqueue
      1  1.1  thorpej /* $NetBSD: t_oneshot.c,v 1.1 2021/10/23 18:46:26 thorpej Exp $ */
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 2021 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      8  1.1  thorpej  * modification, are permitted provided that the following conditions
      9  1.1  thorpej  * are met:
     10  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     11  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     12  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     15  1.1  thorpej  *
     16  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  thorpej  */
     28  1.1  thorpej 
     29  1.1  thorpej #include <sys/cdefs.h>
     30  1.1  thorpej __RCSID("$NetBSD: t_oneshot.c,v 1.1 2021/10/23 18:46:26 thorpej Exp $");
     31  1.1  thorpej 
     32  1.1  thorpej #include <sys/types.h>
     33  1.1  thorpej #include <sys/event.h>
     34  1.1  thorpej #include <errno.h>
     35  1.1  thorpej #include <stdio.h>
     36  1.1  thorpej #include <stdlib.h>
     37  1.1  thorpej #include <time.h>
     38  1.1  thorpej #include <unistd.h>
     39  1.1  thorpej 
     40  1.1  thorpej #include <atf-c.h>
     41  1.1  thorpej 
     42  1.1  thorpej #define	MY_UDATA	((void *)0xbeefcafe)
     43  1.1  thorpej 
     44  1.1  thorpej ATF_TC(oneshot_udata);
     45  1.1  thorpej ATF_TC_HEAD(oneshot_udata, tc)
     46  1.1  thorpej {
     47  1.1  thorpej 	atf_tc_set_md_var(tc, "descr",
     48  1.1  thorpej 	    "tests that udata is round-tripped correctly for ONESHOT events.");
     49  1.1  thorpej }
     50  1.1  thorpej 
     51  1.1  thorpej ATF_TC_BODY(oneshot_udata, tc)
     52  1.1  thorpej {
     53  1.1  thorpej 	struct kevent event[1];
     54  1.1  thorpej 	int kq;
     55  1.1  thorpej 
     56  1.1  thorpej 	ATF_REQUIRE((kq = kqueue()) >= 0);
     57  1.1  thorpej 
     58  1.1  thorpej 	EV_SET(&event[0], 1, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 1, MY_UDATA);
     59  1.1  thorpej 
     60  1.1  thorpej 	ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, NULL) == 0);
     61  1.1  thorpej 	memset(event, 0, sizeof(event));
     62  1.1  thorpej 	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, NULL) == 1);
     63  1.1  thorpej 	ATF_REQUIRE(event[0].ident == 1);
     64  1.1  thorpej 	ATF_REQUIRE(event[0].data == 1);
     65  1.1  thorpej 	ATF_REQUIRE(event[0].udata == MY_UDATA);
     66  1.1  thorpej }
     67  1.1  thorpej 
     68  1.1  thorpej ATF_TP_ADD_TCS(tp)
     69  1.1  thorpej {
     70  1.1  thorpej 	ATF_TP_ADD_TC(tp, oneshot_udata);
     71  1.1  thorpej 
     72  1.1  thorpej 	return atf_no_error();
     73  1.1  thorpej }
     74