1*4022a4faSjruoho /* $NetBSD: t_lwp_ctl.c,v 1.2 2012/03/18 06:20:51 jruoho Exp $ */
20a082b37Sjruoho
30a082b37Sjruoho /*-
40a082b37Sjruoho * Copyright (c) 2008 The NetBSD Foundation, Inc.
50a082b37Sjruoho * All rights reserved.
60a082b37Sjruoho *
70a082b37Sjruoho * Redistribution and use in source and binary forms, with or without
80a082b37Sjruoho * modification, are permitted provided that the following conditions
90a082b37Sjruoho * are met:
100a082b37Sjruoho * 1. Redistributions of source code must retain the above copyright
110a082b37Sjruoho * notice, this list of conditions and the following disclaimer.
120a082b37Sjruoho * 2. Redistributions in binary form must reproduce the above copyright
130a082b37Sjruoho * notice, this list of conditions and the following disclaimer in the
140a082b37Sjruoho * documentation and/or other materials provided with the distribution.
150a082b37Sjruoho *
160a082b37Sjruoho * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
170a082b37Sjruoho * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
180a082b37Sjruoho * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
190a082b37Sjruoho * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
200a082b37Sjruoho * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
210a082b37Sjruoho * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
220a082b37Sjruoho * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
230a082b37Sjruoho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
240a082b37Sjruoho * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
250a082b37Sjruoho * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
260a082b37Sjruoho * POSSIBILITY OF SUCH DAMAGE.
270a082b37Sjruoho */
280a082b37Sjruoho
290a082b37Sjruoho #include <sys/cdefs.h>
300a082b37Sjruoho __COPYRIGHT("@(#) Copyright (c) 2008\
310a082b37Sjruoho The NetBSD Foundation, inc. All rights reserved.");
32*4022a4faSjruoho __RCSID("$NetBSD: t_lwp_ctl.c,v 1.2 2012/03/18 06:20:51 jruoho Exp $");
330a082b37Sjruoho
340a082b37Sjruoho #include <sys/lwpctl.h>
350a082b37Sjruoho
36*4022a4faSjruoho #include <atf-c.h>
370a082b37Sjruoho #include <lwp.h>
380a082b37Sjruoho #include <stdio.h>
390a082b37Sjruoho #include <time.h>
400a082b37Sjruoho
410a082b37Sjruoho ATF_TC(lwpctl_counter);
ATF_TC_HEAD(lwpctl_counter,tc)420a082b37Sjruoho ATF_TC_HEAD(lwpctl_counter, tc)
430a082b37Sjruoho {
440a082b37Sjruoho atf_tc_set_md_var(tc, "descr", "Checks lwpctl preemption counter");
450a082b37Sjruoho }
460a082b37Sjruoho
ATF_TC_BODY(lwpctl_counter,tc)470a082b37Sjruoho ATF_TC_BODY(lwpctl_counter, tc)
480a082b37Sjruoho {
490a082b37Sjruoho lwpctl_t *lc;
500a082b37Sjruoho struct timespec ts;
510a082b37Sjruoho int ctr1, ctr2;
520a082b37Sjruoho
53*4022a4faSjruoho ATF_REQUIRE(_lwp_ctl(LWPCTL_FEATURE_PCTR, &lc) == 0);
540a082b37Sjruoho
550a082b37Sjruoho /* Ensure that preemption is reported. */
560a082b37Sjruoho ctr1 = lc->lc_pctr;
570a082b37Sjruoho (void)printf("pctr = %d\n", ctr1);
580a082b37Sjruoho ts.tv_nsec = 10*1000000;
590a082b37Sjruoho ts.tv_sec = 0;
60*4022a4faSjruoho
61*4022a4faSjruoho ATF_REQUIRE(nanosleep(&ts, 0) != -1);
62*4022a4faSjruoho
630a082b37Sjruoho ctr2 = lc->lc_pctr;
640a082b37Sjruoho (void)printf("pctr = %d\n", ctr2);
650a082b37Sjruoho
660a082b37Sjruoho ATF_REQUIRE_MSG(ctr1 != ctr2, "counters match");
670a082b37Sjruoho }
680a082b37Sjruoho
ATF_TP_ADD_TCS(tp)690a082b37Sjruoho ATF_TP_ADD_TCS(tp)
700a082b37Sjruoho {
710a082b37Sjruoho ATF_TP_ADD_TC(tp, lwpctl_counter);
720a082b37Sjruoho
730a082b37Sjruoho return atf_no_error();
740a082b37Sjruoho }
75