1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_sigqueue.c,v 1.5 2015/06/06 13:14:06 joerg Exp $ */
211be35a1SLionel Sambuc
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc * Copyright (c) 2011 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc * All rights reserved.
611be35a1SLionel Sambuc *
711be35a1SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc * by Christos Zoulas.
911be35a1SLionel Sambuc *
1011be35a1SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc * are met:
1311be35a1SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc * documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc *
1911be35a1SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc */
3111be35a1SLionel Sambuc
3211be35a1SLionel Sambuc #include <sys/cdefs.h>
33*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_sigqueue.c,v 1.5 2015/06/06 13:14:06 joerg Exp $");
3411be35a1SLionel Sambuc
3511be35a1SLionel Sambuc
3611be35a1SLionel Sambuc #include <atf-c.h>
3711be35a1SLionel Sambuc #include <errno.h>
3811be35a1SLionel Sambuc #include <signal.h>
3911be35a1SLionel Sambuc #include <stdlib.h>
4011be35a1SLionel Sambuc #include <sched.h>
4111be35a1SLionel Sambuc #include <unistd.h>
4211be35a1SLionel Sambuc
4311be35a1SLionel Sambuc static void handler(int, siginfo_t *, void *);
4411be35a1SLionel Sambuc
4511be35a1SLionel Sambuc #define VALUE (int)0xc001dad1
4611be35a1SLionel Sambuc static int value;
4711be35a1SLionel Sambuc
4811be35a1SLionel Sambuc static void
handler(int signo,siginfo_t * info,void * data)4911be35a1SLionel Sambuc handler(int signo, siginfo_t *info, void *data)
5011be35a1SLionel Sambuc {
5111be35a1SLionel Sambuc value = info->si_value.sival_int;
5211be35a1SLionel Sambuc kill(0, SIGINFO);
5311be35a1SLionel Sambuc }
5411be35a1SLionel Sambuc
5511be35a1SLionel Sambuc ATF_TC(sigqueue_basic);
ATF_TC_HEAD(sigqueue_basic,tc)5611be35a1SLionel Sambuc ATF_TC_HEAD(sigqueue_basic, tc)
5711be35a1SLionel Sambuc {
5811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Checks sigqueue(3) sigval delivery");
5911be35a1SLionel Sambuc }
6011be35a1SLionel Sambuc
ATF_TC_BODY(sigqueue_basic,tc)6111be35a1SLionel Sambuc ATF_TC_BODY(sigqueue_basic, tc)
6211be35a1SLionel Sambuc {
6311be35a1SLionel Sambuc struct sigaction sa;
6411be35a1SLionel Sambuc union sigval sv;
6511be35a1SLionel Sambuc
6611be35a1SLionel Sambuc sa.sa_sigaction = handler;
6711be35a1SLionel Sambuc sigemptyset(&sa.sa_mask);
6811be35a1SLionel Sambuc sa.sa_flags = SA_SIGINFO;
6911be35a1SLionel Sambuc
7011be35a1SLionel Sambuc if (sigaction(SIGUSR1, &sa, NULL) != 0)
7111be35a1SLionel Sambuc atf_tc_fail("sigaction failed");
7211be35a1SLionel Sambuc
7311be35a1SLionel Sambuc sv.sival_int = VALUE;
7411be35a1SLionel Sambuc
7511be35a1SLionel Sambuc if (sigqueue(0, SIGUSR1, sv) != 0)
7611be35a1SLionel Sambuc atf_tc_fail("sigqueue failed");
7711be35a1SLionel Sambuc
7811be35a1SLionel Sambuc sched_yield();
7911be35a1SLionel Sambuc ATF_REQUIRE_EQ(sv.sival_int, value);
8011be35a1SLionel Sambuc }
8111be35a1SLionel Sambuc
8211be35a1SLionel Sambuc ATF_TC(sigqueue_err);
ATF_TC_HEAD(sigqueue_err,tc)8311be35a1SLionel Sambuc ATF_TC_HEAD(sigqueue_err, tc)
8411be35a1SLionel Sambuc {
8511be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test errors from sigqueue(3)");
8611be35a1SLionel Sambuc }
8711be35a1SLionel Sambuc
ATF_TC_BODY(sigqueue_err,tc)8811be35a1SLionel Sambuc ATF_TC_BODY(sigqueue_err, tc)
8911be35a1SLionel Sambuc {
90*0a6a1f1dSLionel Sambuc static union sigval sv;
9111be35a1SLionel Sambuc
9211be35a1SLionel Sambuc errno = 0;
9311be35a1SLionel Sambuc ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1);
9411be35a1SLionel Sambuc }
9511be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)9611be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
9711be35a1SLionel Sambuc {
9811be35a1SLionel Sambuc
9911be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, sigqueue_basic);
10011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, sigqueue_err);
10111be35a1SLionel Sambuc
10211be35a1SLionel Sambuc return atf_no_error();
10311be35a1SLionel Sambuc }
104