Remove building with NOCRYPTO option
[minix.git] / tests / rump / rumpkern / t_copy.c
bloba31e58ca7a37bc37e3da5f851f0c6624be11db15
1 /* $NetBSD: t_copy.c,v 1.2 2013/07/26 16:09:48 njoly Exp $ */
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
32 #include <atf-c.h>
33 #include <errno.h>
34 #include <string.h>
36 #include <rump/rump.h>
38 ATF_TC(copystr);
39 ATF_TC_HEAD(copystr, tc)
42 atf_tc_set_md_var(tc, "descr", "Tests copystr()");
45 ATF_TC(copyinstr);
46 ATF_TC_HEAD(copyinstr, tc)
49 atf_tc_set_md_var(tc, "descr", "Tests copyinstr()");
52 ATF_TC(copyoutstr);
53 ATF_TC_HEAD(copyoutstr, tc)
56 atf_tc_set_md_var(tc, "descr", "Tests copyoutstr()");
59 typedef int (copystr_fn)(const void *, void *, size_t, size_t *);
60 typedef int (copy_fn)(const void *, void *, size_t);
62 extern copystr_fn rumpns_copystr, rumpns_copyinstr, rumpns_copyoutstr;
63 extern copy_fn rumpns_copyin, rumpns_copyout;
65 #define TESTSTR "jippii, lisaa puuroa"
67 static void
68 dotest(copystr_fn *thefun)
70 char buf[sizeof(TESTSTR)+1];
71 size_t len;
73 rump_init();
74 rump_schedule();
76 /* larger buffer */
77 memset(buf, 0xaa, sizeof(buf));
78 ATF_REQUIRE_EQ(thefun(TESTSTR, buf, sizeof(buf), &len), 0);
79 ATF_REQUIRE_EQ(len, sizeof(TESTSTR));
80 ATF_REQUIRE_STREQ(TESTSTR, buf);
82 /* just large enough */
83 memset(buf, 0xaa, sizeof(buf));
84 ATF_REQUIRE_EQ(thefun(TESTSTR, buf, sizeof(buf)-1, &len), 0);
85 ATF_REQUIRE_EQ(len, sizeof(TESTSTR));
86 ATF_REQUIRE_STREQ(TESTSTR, buf);
88 /* one too small */
89 memset(buf, 0xaa, sizeof(buf));
90 ATF_REQUIRE_EQ(thefun(TESTSTR, buf, sizeof(buf)-2, NULL), ENAMETOOLONG);
92 rump_unschedule();
95 ATF_TC_BODY(copystr, tc)
98 dotest(rumpns_copystr);
101 ATF_TC_BODY(copyinstr, tc)
104 dotest(rumpns_copyinstr);
107 ATF_TC_BODY(copyoutstr, tc)
110 dotest(rumpns_copyoutstr);
113 ATF_TC(copy_efault);
114 ATF_TC_HEAD(copy_efault, tc)
117 atf_tc_set_md_var(tc, "descr", "Tests that copy(9) functions can return EFAULT");
119 ATF_TC_BODY(copy_efault, tc)
121 char buf[1024];
123 ATF_REQUIRE_EQ(rumpns_copyin(NULL, buf, sizeof(buf)), EFAULT);
124 ATF_REQUIRE_EQ(rumpns_copyout(buf, NULL, sizeof(buf)), EFAULT);
126 ATF_REQUIRE_EQ(rumpns_copyinstr(NULL, buf, sizeof(buf), NULL), EFAULT);
127 ATF_REQUIRE_EQ(rumpns_copyoutstr(buf, NULL, sizeof(buf), NULL), EFAULT);
130 ATF_TP_ADD_TCS(tp)
133 ATF_TP_ADD_TC(tp, copystr);
134 ATF_TP_ADD_TC(tp, copyinstr);
135 ATF_TP_ADD_TC(tp, copyoutstr);
136 ATF_TP_ADD_TC(tp, copy_efault);
138 return atf_no_error();