1 /* $NetBSD: t_copy.c,v 1.2 2013/07/26 16:09:48 njoly Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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>
36 #include <rump/rump.h>
39 ATF_TC_HEAD(copystr
, tc
)
42 atf_tc_set_md_var(tc
, "descr", "Tests copystr()");
46 ATF_TC_HEAD(copyinstr
, tc
)
49 atf_tc_set_md_var(tc
, "descr", "Tests copyinstr()");
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"
68 dotest(copystr_fn
*thefun
)
70 char buf
[sizeof(TESTSTR
)+1];
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
);
89 memset(buf
, 0xaa, sizeof(buf
));
90 ATF_REQUIRE_EQ(thefun(TESTSTR
, buf
, sizeof(buf
)-2, NULL
), ENAMETOOLONG
);
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
);
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
)
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
);
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();