1312123Sngie/*	$NetBSD: t_exect.c,v 1.6 2016/12/12 10:34:55 joerg Exp $	*/
2312123Sngie
3312123Sngie/*-
4312123Sngie * Copyright (c) 2014 The NetBSD Foundation, Inc.
5312123Sngie * All rights reserved.
6312123Sngie *
7312123Sngie * Redistribution and use in source and binary forms, with or without
8312123Sngie * modification, are permitted provided that the following conditions
9312123Sngie * are met:
10312123Sngie * 1. Redistributions of source code must retain the above copyright
11312123Sngie *    notice, this list of conditions and the following disclaimer.
12312123Sngie * 2. Redistributions in binary form must reproduce the above copyright
13312123Sngie *    notice, this list of conditions and the following disclaimer in the
14312123Sngie *    documentation and/or other materials provided with the distribution.
15312123Sngie *
16312123Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17312123Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18312123Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19312123Sngie * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20312123Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21312123Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22312123Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23312123Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24312123Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25312123Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26312123Sngie * POSSIBILITY OF SUCH DAMAGE.
27312123Sngie */
28312123Sngie
29312123Sngie#include <atf-c.h>
30312123Sngie
31312123Sngie#include <errno.h>
32312123Sngie#include <signal.h>
33312123Sngie#include <stddef.h>
34312123Sngie#include <stdio.h>
35312123Sngie#include <unistd.h>
36312123Sngie
37312123SngieATF_TC(t_exect_null);
38312123Sngie
39312123SngieATF_TC_HEAD(t_exect_null, tc)
40312123Sngie{
41312123Sngie	atf_tc_set_md_var(tc, "descr",
42312123Sngie	    "Tests an empty exect(2) executing");
43312123Sngie}
44312123Sngie
45312123Sngiestatic volatile sig_atomic_t caught = 0;
46312123Sngie
47312123Sngiestatic void
48312123Sngiesigtrap_handler(int sig, siginfo_t *info, void *ctx)
49312123Sngie{
50312123Sngie	ATF_REQUIRE_EQ(sig, SIGTRAP);
51312123Sngie	ATF_REQUIRE_EQ(info->si_code, TRAP_TRACE);
52312123Sngie
53312123Sngie	++caught;
54312123Sngie}
55312123Sngie
56312123SngieATF_TC_BODY(t_exect_null, tc)
57312123Sngie{
58312123Sngie	struct sigaction act;
59312123Sngie
60312123Sngie	/*
61312123Sngie	 * Currently exect(3) is misdesigned -- see PR port-amd64/51700 and it
62312123Sngie	 * needs to be redone from scratch.
63312123Sngie	 *
64312123Sngie	 * This test affects amd64 releng machines causing tests to hang or
65312123Sngie	 * fail. As there is little point to test interface that is still not,
66312123Sngie	 * designed and implemented and is breaking tests - skip it
67312123Sngie	 * unconditionally for all ports.
68312123Sngie	 */
69312123Sngie	/* Prevent static analysis from requiring t_exec_null to be __dead. */
70312123Sngie	if (!caught)
71312123Sngie		atf_tc_skip("exect(3) misdesigned and hangs - PR port-amd64/51700");
72312123Sngie
73312123Sngie	ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0);
74312123Sngie	act.sa_sigaction = sigtrap_handler;
75312123Sngie	act.sa_flags = SA_SIGINFO;
76312123Sngie
77312123Sngie	ATF_REQUIRE(sigaction(SIGTRAP, &act, 0) == 0);
78312123Sngie
79312123Sngie	ATF_REQUIRE_ERRNO(EFAULT, exect(NULL, NULL, NULL) == -1);
80312123Sngie
81312123Sngie	ATF_REQUIRE_EQ_MSG(caught, 1, "expected caught (1) != received (%d)",
82312123Sngie	    (int)caught);
83312123Sngie}
84312123Sngie
85312123SngieATF_TP_ADD_TCS(tp)
86312123Sngie{
87312123Sngie	ATF_TP_ADD_TC(tp, t_exect_null);
88312123Sngie
89312123Sngie	return atf_no_error();
90312123Sngie}
91