Fri Jun 9 08:23:45 2017 UTC ()
Test bind()ing to a non-existent interface.


(bouyer)
diff -r1.5 -r1.6 src/tests/net/can/t_can.c

cvs diff -r1.5 -r1.6 src/tests/net/can/t_can.c (expand / switch to unified diff)

--- src/tests/net/can/t_can.c 2017/05/28 14:53:13 1.5
+++ src/tests/net/can/t_can.c 2017/06/09 08:23:45 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_can.c,v 1.5 2017/05/28 14:53:13 christos Exp $ */ 1/* $NetBSD: t_can.c,v 1.6 2017/06/09 08:23:45 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 2017 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Manuel Bouyer 8 * by Manuel Bouyer
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 23 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34#ifndef lint 34#ifndef lint
35__RCSID("$NetBSD: t_can.c,v 1.5 2017/05/28 14:53:13 christos Exp $"); 35__RCSID("$NetBSD: t_can.c,v 1.6 2017/06/09 08:23:45 bouyer Exp $");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/resource.h> 39#include <sys/resource.h>
40#include <sys/wait.h> 40#include <sys/wait.h>
41#include <sys/sockio.h> 41#include <sys/sockio.h>
42#include <sys/param.h> 42#include <sys/param.h>
43 43
44#include <atf-c.h> 44#include <atf-c.h>
45#include <assert.h> 45#include <assert.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
@@ -707,28 +707,54 @@ ATF_TC_BODY(cannoloop, tc) @@ -707,28 +707,54 @@ ATF_TC_BODY(cannoloop, tc)
707 "recvfrom (2) packet is not what we sent"); 707 "recvfrom (2) packet is not what we sent");
708 ATF_CHECK_MSG(sa.can_family == AF_CAN, 708 ATF_CHECK_MSG(sa.can_family == AF_CAN,
709 "recvfrom provided wrong %d family", sa.can_family); 709 "recvfrom provided wrong %d family", sa.can_family);
710 ATF_CHECK_MSG(salen == sizeof(sa), 710 ATF_CHECK_MSG(salen == sizeof(sa),
711 "recvfrom provided wrong size %u (!= %zu)", 711 "recvfrom provided wrong size %u (!= %zu)",
712 salen, sizeof(sa)); 712 salen, sizeof(sa));
713 ATF_CHECK_MSG(sa.can_ifindex == ifindex, 713 ATF_CHECK_MSG(sa.can_ifindex == ifindex,
714 "recvfrom provided wrong ifindex %d (!= %d)", 714 "recvfrom provided wrong ifindex %d (!= %d)",
715 sa.can_ifindex, ifindex); 715 sa.can_ifindex, ifindex);
716 atf_tc_fail_nonfatal("we got message on s2"); 716 atf_tc_fail_nonfatal("we got message on s2");
717 } 717 }
718} 718}
719 719
 720ATF_TC(canbindunknown);
 721ATF_TC_HEAD(canbindunknown, tc)
 722{
 723
 724 atf_tc_set_md_var(tc, "descr", "check that bind to unkown interface fails");
 725 atf_tc_set_md_var(tc, "timeout", "5");
 726}
 727
 728ATF_TC_BODY(canbindunknown, tc)
 729{
 730 struct sockaddr_can sa;
 731 int r, s;
 732
 733 rump_init();
 734
 735 s = can_socket_with_own();
 736
 737 sa.can_family = AF_CAN;
 738 sa.can_ifindex = 10; /* should not exist */
 739
 740 r = rump_sys_bind(s, (struct sockaddr *)&sa, sizeof(sa));
 741
 742 ATF_CHECK_MSG(r < 0, "bind() didn't fail (%d)", r);
 743}
 744
720ATF_TP_ADD_TCS(tp) 745ATF_TP_ADD_TCS(tp)
721{ 746{
722 747
723 ATF_TP_ADD_TC(tp, canlocreate); 748 ATF_TP_ADD_TC(tp, canlocreate);
724 ATF_TP_ADD_TC(tp, cannoown); 749 ATF_TP_ADD_TC(tp, cannoown);
725 ATF_TP_ADD_TC(tp, canwritelo); 750 ATF_TP_ADD_TC(tp, canwritelo);
726 ATF_TP_ADD_TC(tp, canwriteunbound); 751 ATF_TP_ADD_TC(tp, canwriteunbound);
727 ATF_TP_ADD_TC(tp, cansendtolo); 752 ATF_TP_ADD_TC(tp, cansendtolo);
728 ATF_TP_ADD_TC(tp, cansendtowrite); 753 ATF_TP_ADD_TC(tp, cansendtowrite);
729 ATF_TP_ADD_TC(tp, canreadlocal); 754 ATF_TP_ADD_TC(tp, canreadlocal);
730 ATF_TP_ADD_TC(tp, canrecvfrom); 755 ATF_TP_ADD_TC(tp, canrecvfrom);
731 ATF_TP_ADD_TC(tp, canbindfilter); 756 ATF_TP_ADD_TC(tp, canbindfilter);
732 ATF_TP_ADD_TC(tp, cannoloop); 757 ATF_TP_ADD_TC(tp, cannoloop);
 758 ATF_TP_ADD_TC(tp, canbindunknown);
733 return atf_no_error(); 759 return atf_no_error();
734} 760}