Merge ^/vendor/NetBSD/tests/dist@r312294
This includes a number of accepted upstream fixes, as well as a reimplementation of the net/carp/... testcase (which is currently unused).
This commit is contained in:
commit
6bece6cfa6
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: h_memset.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */
|
||||
/* $NetBSD: h_memset.c,v 1.2 2017/01/16 16:34:24 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -29,7 +29,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: h_memset.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $");
|
||||
__RCSID("$NetBSD: h_memset.c,v 1.2 2017/01/16 16:34:24 christos Exp $");
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -41,9 +41,5 @@ main(int argc, char *argv[])
|
||||
char b[10];
|
||||
size_t len = atoi(argv[1]);
|
||||
(void)memset(b, 0, len);
|
||||
#ifdef __FreeBSD__
|
||||
return b[0]; /* keeps optimizer from zapping the call to memset() */
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: h_read.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */
|
||||
/* $NetBSD: h_read.c,v 1.2 2017/01/16 16:35:57 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -29,17 +29,15 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: h_read.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $");
|
||||
__RCSID("$NetBSD: h_read.c,v 1.2 2017/01/16 16:35:57 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@ -54,14 +52,3 @@ main(int argc, char *argv[])
|
||||
(void)printf("%s\n", b);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char b[MAXPATHLEN];
|
||||
size_t len = atoi(argv[1]);
|
||||
|
||||
(void)printf("%s\n", b);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $ */
|
||||
/* $NetBSD: t_mmap.c,v 1.12 2017/01/16 16:31:05 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
@ -55,9 +55,10 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $");
|
||||
__RCSID("$NetBSD: t_mmap.c,v 1.12 2017/01/16 16:31:05 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
@ -73,11 +74,8 @@ __RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $");
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <paths.h>
|
||||
#ifdef __NetBSD__
|
||||
#include <machine/disklabel.h>
|
||||
#else
|
||||
#ifdef __FreeBSD__
|
||||
#include <stdint.h>
|
||||
#include <sys/disklabel.h>
|
||||
#endif
|
||||
|
||||
static long page = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_timer_create.c,v 1.4 2012/03/18 07:00:52 jruoho Exp $ */
|
||||
/* $NetBSD: t_timer_create.c,v 1.5 2017/01/16 16:32:13 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
@ -38,11 +38,7 @@ static timer_t t;
|
||||
static bool fail = true;
|
||||
|
||||
static void
|
||||
#ifdef __FreeBSD__
|
||||
timer_signal_handler(int signo, siginfo_t *si, void *osi __unused)
|
||||
#else
|
||||
timer_signal_handler(int signo, siginfo_t *si, void *osi)
|
||||
#endif
|
||||
{
|
||||
timer_t *tp;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $ */
|
||||
/* $NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 The NetBSD Foundation, Inc.
|
||||
@ -26,8 +26,9 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $");
|
||||
__RCSID("$NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $");
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
@ -40,11 +41,7 @@ __RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $");
|
||||
|
||||
#include "isqemu.h"
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "h_common.h"
|
||||
#endif
|
||||
|
||||
#define WAITTIME 2 /* Timeout wait secound */
|
||||
|
||||
@ -62,13 +59,8 @@ run(void *param)
|
||||
|
||||
|
||||
clck = *(clockid_t *)param;
|
||||
#ifdef __FreeBSD__
|
||||
PTHREAD_REQUIRE(pthread_condattr_init(&attr));
|
||||
PTHREAD_REQUIRE(pthread_condattr_setclock(&attr, clck));
|
||||
#else
|
||||
pthread_condattr_init(&attr);
|
||||
pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */
|
||||
#endif
|
||||
pthread_cond_init(&cond, &attr);
|
||||
|
||||
ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $ */
|
||||
/* $NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
@ -29,10 +29,11 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $");
|
||||
__RCSID("$NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $");
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
@ -47,9 +48,7 @@ static void *func(void *);
|
||||
static void *
|
||||
func(void *arg)
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
sleep(2);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -79,25 +78,17 @@ ATF_TC_BODY(pthread_detach, tc)
|
||||
*/
|
||||
PTHREAD_REQUIRE(pthread_detach(t));
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
sleep(1);
|
||||
#endif
|
||||
rv = pthread_join(t, NULL);
|
||||
ATF_REQUIRE(rv == EINVAL);
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
sleep(3);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* As usual, ESRCH should follow if
|
||||
* we try to detach an invalid thread.
|
||||
*/
|
||||
#ifdef __NetBSD__
|
||||
rv = pthread_cancel(NULL);
|
||||
#else
|
||||
rv = pthread_cancel(t);
|
||||
#endif
|
||||
ATF_REQUIRE(rv == ESRCH);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
|
||||
/* $NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -29,7 +29,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
|
||||
__RCSID("$NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $");
|
||||
|
||||
/*
|
||||
* Written by Love Hörnquist Åstrand <lha@NetBSD.org>, March 2003.
|
||||
@ -61,11 +61,7 @@ print_pid(void *arg)
|
||||
|
||||
thread_survived = 1;
|
||||
if (parent != getpid()) {
|
||||
#ifdef __FreeBSD__
|
||||
_exit(1);
|
||||
#else
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -99,11 +95,7 @@ ATF_TC_BODY(fork, tc)
|
||||
ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child");
|
||||
} else {
|
||||
sleep(5);
|
||||
#ifdef __FreeBSD__
|
||||
_exit(thread_survived ? 1 : 0);
|
||||
#else
|
||||
exit(thread_survived ? 1 : 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */
|
||||
/* $NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -29,7 +29,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $");
|
||||
__RCSID("$NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $");
|
||||
|
||||
/*
|
||||
* This is adapted from part of csw/cstest of the MPD implementation by
|
||||
@ -49,10 +49,12 @@ __RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $");
|
||||
* <is@netbsd.org>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -82,24 +84,16 @@ stir(void *p)
|
||||
|
||||
for (;;) {
|
||||
x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6)));
|
||||
#ifdef __FreeBSD__
|
||||
ATF_REQUIRE_MSG(sched_yield() == 0,
|
||||
"sched_yield failed: %s", strerror(errno));
|
||||
#else
|
||||
PTHREAD_REQUIRE(sched_yield());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static double
|
||||
mul3(double x, double y, double z)
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
ATF_REQUIRE_MSG(sched_yield() == 0,
|
||||
"sched_yield failed: %s", strerror(errno));
|
||||
#else
|
||||
PTHREAD_REQUIRE(sched_yield());
|
||||
#endif
|
||||
|
||||
return x * y * z;
|
||||
}
|
||||
@ -129,11 +123,7 @@ bar(void *p)
|
||||
static void
|
||||
recurse(void) {
|
||||
pthread_t s2;
|
||||
#ifdef __FreeBSD__
|
||||
PTHREAD_REQUIRE(pthread_create(&s2, 0, bar, 0));
|
||||
#else
|
||||
pthread_create(&s2, 0, bar, 0);
|
||||
#endif
|
||||
sleep(20); /* XXX must be long enough for our slowest machine */
|
||||
}
|
||||
|
||||
@ -153,11 +143,7 @@ ATF_TC_BODY(fpu, tc)
|
||||
|
||||
PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0));
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
PTHREAD_REQUIRE(pthread_create(&s5, 0, stir, stirseed));
|
||||
#else
|
||||
pthread_create(&s5, 0, stir, stirseed);
|
||||
#endif
|
||||
recurse();
|
||||
|
||||
atf_tc_fail("exiting from main");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */
|
||||
/* $NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -29,12 +29,10 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $");
|
||||
__RCSID("$NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $");
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/time.h> /* For timespecadd */
|
||||
#include <inttypes.h> /* For UINT16_MAX */
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -594,20 +592,16 @@ ATF_TC_BODY(mutexattr2, tc)
|
||||
int min_prio = sched_get_priority_min(SCHED_FIFO);
|
||||
for (int i = min_prio; i <= max_prio; i++) {
|
||||
int prioceiling;
|
||||
#ifdef __FreeBSD__
|
||||
int protocol;
|
||||
|
||||
PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr,
|
||||
&protocol));
|
||||
|
||||
printf("priority: %d\nprotocol: %d\n", i, protocol);
|
||||
#endif
|
||||
PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i));
|
||||
PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr,
|
||||
&prioceiling));
|
||||
#ifdef __FreeBSD__
|
||||
printf("prioceiling: %d\n", prioceiling);
|
||||
#endif
|
||||
ATF_REQUIRE_EQ(i, prioceiling);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $ */
|
||||
/* $NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
|
||||
@ -86,8 +86,9 @@
|
||||
#include <sys/cdefs.h>
|
||||
__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
|
||||
The NetBSD Foundation, inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $");
|
||||
__RCSID("$NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $");
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_swapcontext.c,v 1.2 2014/08/25 16:31:15 bouyer Exp $ */
|
||||
/* $NetBSD: t_swapcontext.c,v 1.3 2017/01/16 16:27:06 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
|
||||
@ -28,15 +28,13 @@
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD");
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <ucontext.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ucontext.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
@ -82,12 +80,8 @@ threadfunc(void *arg)
|
||||
|
||||
oself = (void *)pthread_self();
|
||||
printf("before swapcontext self = %p\n", oself);
|
||||
#ifdef __FreeBSD__
|
||||
ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s",
|
||||
strerror(errno));
|
||||
#else
|
||||
PTHREAD_REQUIRE(swapcontext(&octx, &nctx));
|
||||
#endif
|
||||
|
||||
/* NOTREACHED */
|
||||
return NULL;
|
||||
@ -118,12 +112,8 @@ ATF_TC_BODY(swapcontext1, tc)
|
||||
|
||||
printf("Testing if swapcontext() alters pthread_self()\n");
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s",
|
||||
strerror(errno));
|
||||
#else
|
||||
PTHREAD_REQUIRE(getcontext(&nctx));
|
||||
#endif
|
||||
PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL));
|
||||
PTHREAD_REQUIRE(pthread_join(thread, NULL));
|
||||
}
|
||||
|
@ -1,221 +0,0 @@
|
||||
/* $NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip_carp.h>
|
||||
|
||||
#include <rump/rump.h>
|
||||
#include <rump/rump_syscalls.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "../config/netconfig.c"
|
||||
#include "h_macros.h"
|
||||
|
||||
static bool oknow = false;
|
||||
|
||||
static void
|
||||
sighnd(int sig)
|
||||
{
|
||||
|
||||
ATF_REQUIRE_EQ(sig, SIGCHLD);
|
||||
if (oknow)
|
||||
return;
|
||||
|
||||
atf_tc_fail("child died unexpectedly");
|
||||
}
|
||||
|
||||
ATF_TC(handover);
|
||||
ATF_TC_HEAD(handover, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr", "check that carp handover works if "
|
||||
"the master dies");
|
||||
}
|
||||
|
||||
#define THEBUS "buuuuuuus,etherbus"
|
||||
|
||||
static void
|
||||
child(bool master)
|
||||
{
|
||||
char ifname[IFNAMSIZ];
|
||||
struct carpreq cr;
|
||||
struct ifreq ifr;
|
||||
const char *carpif;
|
||||
int s;
|
||||
|
||||
/* helps reading carp debug output */
|
||||
if (master)
|
||||
carpif = "carp0";
|
||||
else
|
||||
carpif = "carp1";
|
||||
|
||||
/*
|
||||
* Should use sysctl, bug debug is dabug.
|
||||
*/
|
||||
{
|
||||
//extern int rumpns_carp_opts[]; /* XXX */
|
||||
//rumpns_carp_opts[CARPCTL_LOG] = 1;
|
||||
}
|
||||
|
||||
|
||||
rump_init();
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strlcpy(ifr.ifr_name, carpif, sizeof(ifr.ifr_name));
|
||||
|
||||
RL(s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0));
|
||||
RL(rump_sys_ioctl(s, SIOCIFCREATE, &ifr));
|
||||
|
||||
netcfg_rump_makeshmif(THEBUS, ifname);
|
||||
|
||||
if (master)
|
||||
netcfg_rump_if(ifname, "10.1.1.1", "255.255.255.0");
|
||||
else
|
||||
netcfg_rump_if(ifname, "10.1.1.2", "255.255.255.0");
|
||||
|
||||
/* configure the carp interface */
|
||||
ifr.ifr_data = &cr;
|
||||
RL(rump_sys_ioctl(s, SIOCGVH, &ifr));
|
||||
|
||||
strlcpy(cr.carpr_carpdev, ifname, sizeof(cr.carpr_carpdev));
|
||||
cr.carpr_vhid = 175;
|
||||
if (master)
|
||||
cr.carpr_advskew = 0;
|
||||
else
|
||||
cr.carpr_advskew = 200;
|
||||
cr.carpr_advbase = 1;
|
||||
strcpy((char *)cr.carpr_key, "s3cret");
|
||||
|
||||
RL(rump_sys_ioctl(s, SIOCSVH, &ifr));
|
||||
netcfg_rump_if(carpif, "10.1.1.100", "255.255.255.0");
|
||||
|
||||
/* tassa pause()en enka muuta voi */
|
||||
pause();
|
||||
}
|
||||
|
||||
ATF_TC_BODY(handover, tc)
|
||||
{
|
||||
char ifname[IFNAMSIZ];
|
||||
pid_t mpid, cpid;
|
||||
int i, status;
|
||||
|
||||
signal(SIGCHLD, sighnd);
|
||||
|
||||
/* fork master */
|
||||
switch (mpid = fork()) {
|
||||
case -1:
|
||||
atf_tc_fail_errno("fork failed");
|
||||
/*NOTREACHED*/
|
||||
case 0:
|
||||
child(true);
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(500000);
|
||||
|
||||
/* fork backup */
|
||||
switch (cpid = fork()) {
|
||||
case -1:
|
||||
kill(mpid, SIGKILL);
|
||||
atf_tc_fail_errno("fork failed");
|
||||
/*NOTREACHED*/
|
||||
case 0:
|
||||
child(false);
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(500000);
|
||||
|
||||
rump_init();
|
||||
netcfg_rump_makeshmif(THEBUS, ifname);
|
||||
netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0");
|
||||
|
||||
/* check that the primary addresses are up */
|
||||
ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true);
|
||||
ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true);
|
||||
|
||||
/* give carp a while to croak */
|
||||
sleep(4);
|
||||
|
||||
/* check that the shared IP works */
|
||||
ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true);
|
||||
|
||||
/* KILLING SPREE */
|
||||
oknow = true;
|
||||
kill(mpid, SIGKILL);
|
||||
wait(&status);
|
||||
usleep(10000); /* just in case */
|
||||
oknow = false;
|
||||
|
||||
/* check that primary is now dead */
|
||||
ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false);
|
||||
|
||||
/* do it in installments. carp will cluck meanwhile */
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (netcfg_rump_pingtest("10.1.1.100", 1000) == true)
|
||||
break;
|
||||
}
|
||||
if (i == 5)
|
||||
atf_tc_fail("failed to failover");
|
||||
|
||||
/* to kill the child */
|
||||
oknow = true;
|
||||
kill(cpid, SIGKILL);
|
||||
|
||||
/* clean & done */
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, handover);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
165
contrib/netbsd-tests/net/carp/t_basic.sh
Executable file
165
contrib/netbsd-tests/net/carp/t_basic.sh
Executable file
@ -0,0 +1,165 @@
|
||||
# $NetBSD: t_basic.sh,v 1.1 2017/01/16 08:18:11 ozaki-r Exp $
|
||||
#
|
||||
# Copyright (c) 2017 Internet Initiative Japan Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SOCK_CLIENT=unix://carp_client
|
||||
SOCK_MASTER=unix://carp_master
|
||||
SOCK_BACKUP=unix://carp_backup
|
||||
BUS=bus_carp
|
||||
IP_CLIENT=10.1.1.240
|
||||
IP_MASTER=10.1.1.1
|
||||
IP_BACKUP=10.1.1.2
|
||||
IP_CARP=10.1.1.100
|
||||
TIMEOUT=3
|
||||
|
||||
atf_test_case carp_handover cleanup
|
||||
|
||||
carp_handover_head()
|
||||
{
|
||||
|
||||
atf_set "descr" "Tests for CARP handover"
|
||||
atf_set "require.progs" "rump_server"
|
||||
}
|
||||
|
||||
setup_carp()
|
||||
{
|
||||
local sock=$1
|
||||
local master=$2
|
||||
local carpif= ip= advskew=
|
||||
|
||||
if $master; then
|
||||
carpif=carp0
|
||||
ip=$IP_MASTER
|
||||
advskew=0
|
||||
else
|
||||
carpif=carp1
|
||||
ip=$IP_BACKUP
|
||||
advskew=200
|
||||
fi
|
||||
|
||||
export RUMP_SERVER=$sock
|
||||
atf_check -s exit:0 rump.ifconfig $carpif create
|
||||
atf_check -s exit:0 rump.ifconfig shmif0 $ip/24 up
|
||||
atf_check -s exit:0 rump.ifconfig $carpif \
|
||||
vhid 175 advskew $advskew advbase 1 pass s3cret \
|
||||
$IP_CARP netmask 255.255.255.0
|
||||
atf_check -s exit:0 rump.ifconfig -w 10
|
||||
}
|
||||
|
||||
wait_handover()
|
||||
{
|
||||
local i=0
|
||||
|
||||
export RUMP_SERVER=$SOCK_CLIENT
|
||||
|
||||
while [ $i -ne 5 ]; do
|
||||
$DEBUG && echo "Trying ping $IP_CARP"
|
||||
rump.ping -n -w 1 -c 1 $IP_CARP >/dev/null
|
||||
if [ $? = 0 ]; then
|
||||
$DEBUG && echo "Passed ping $IP_CARP"
|
||||
break;
|
||||
fi
|
||||
$DEBUG && echo "Failed ping $IP_CARP"
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
if [ $i -eq 5 ]; then
|
||||
atf_fail "Failed to failover (5 sec)"
|
||||
fi
|
||||
}
|
||||
|
||||
carp_handover_body()
|
||||
{
|
||||
|
||||
rump_server_start $SOCK_CLIENT
|
||||
rump_server_start $SOCK_MASTER
|
||||
rump_server_start $SOCK_BACKUP
|
||||
|
||||
rump_server_add_iface $SOCK_CLIENT shmif0 $BUS
|
||||
rump_server_add_iface $SOCK_MASTER shmif0 $BUS
|
||||
rump_server_add_iface $SOCK_BACKUP shmif0 $BUS
|
||||
|
||||
setup_carp $SOCK_MASTER true
|
||||
setup_carp $SOCK_BACKUP false
|
||||
|
||||
export RUMP_SERVER=$SOCK_CLIENT
|
||||
atf_check -s exit:0 rump.ifconfig shmif0 $IP_CLIENT/24 up
|
||||
atf_check -s exit:0 rump.ifconfig -w 10
|
||||
|
||||
# Check that the primary addresses are up
|
||||
atf_check -s exit:0 -o ignore \
|
||||
rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER
|
||||
atf_check -s exit:0 -o ignore \
|
||||
rump.ping -n -w $TIMEOUT -c 1 $IP_BACKUP
|
||||
|
||||
# Give carp a while to croak
|
||||
sleep 4
|
||||
|
||||
# Check state
|
||||
export RUMP_SERVER=$SOCK_MASTER
|
||||
$DEBUG && rump.ifconfig
|
||||
atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \
|
||||
rump.ifconfig carp0
|
||||
export RUMP_SERVER=$SOCK_BACKUP
|
||||
$DEBUG && rump.ifconfig
|
||||
atf_check -s exit:0 -o match:'carp: BACKUP carpdev shmif0' \
|
||||
rump.ifconfig carp1
|
||||
export RUMP_SERVER=$SOCK_CLIENT
|
||||
|
||||
# Check that the shared IP works
|
||||
atf_check -s exit:0 -o ignore \
|
||||
rump.ping -n -w $TIMEOUT -c 1 $IP_CARP
|
||||
|
||||
# KILLING SPREE
|
||||
env RUMP_SERVER=$SOCK_MASTER rump.halt
|
||||
sleep 1
|
||||
|
||||
# Check that primary is now dead
|
||||
atf_check -s not-exit:0 -o ignore \
|
||||
rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER
|
||||
|
||||
# Do it in installments. carp will cluck meanwhile
|
||||
wait_handover
|
||||
|
||||
# Check state
|
||||
export RUMP_SERVER=$SOCK_BACKUP
|
||||
$DEBUG && rump.ifconfig
|
||||
atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \
|
||||
rump.ifconfig carp1
|
||||
}
|
||||
|
||||
carp_handover_cleanup()
|
||||
{
|
||||
|
||||
$DEBUG && dump
|
||||
cleanup
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
|
||||
atf_add_test_case carp_handover
|
||||
}
|
Loading…
Reference in New Issue
Block a user