1 /* $NetBSD: t_strcpy.c,v 1.1 2011/07/07 08:59:33 jruoho Exp $ */
4 * Written by J.T. Conklin <jtc@acorntoolworks.com>
15 ATF_TC_HEAD(strcpy_basic
, tc
)
17 atf_tc_set_md_var(tc
, "descr", "Test strcpy(3) results");
20 ATF_TC_BODY(strcpy_basic
, tc
)
22 /* try to trick the compiler */
23 char * (*f
)(char *, const char *s
) = strcpy
;
25 unsigned int a0
, a1
, t
;
35 const struct tab tab
[] = {
37 * patterns that check for all combinations of leading and
38 * trailing unaligned characters (on a 64 bit processor)
52 { "abcdefghijk", 11 },
53 { "abcdefghijkl", 12 },
54 { "abcdefghijklm", 13 },
55 { "abcdefghijklmn", 14 },
56 { "abcdefghijklmno", 15 },
57 { "abcdefghijklmnop", 16 },
58 { "abcdefghijklmnopq", 17 },
59 { "abcdefghijklmnopqr", 18 },
60 { "abcdefghijklmnopqrs", 19 },
61 { "abcdefghijklmnopqrst", 20 },
62 { "abcdefghijklmnopqrstu", 21 },
63 { "abcdefghijklmnopqrstuv", 22 },
64 { "abcdefghijklmnopqrstuvw", 23 },
67 * patterns that check for the cases where the expression:
69 * ((word - 0x7f7f..7f) & 0x8080..80)
71 * returns non-zero even though there are no zero bytes in
75 { "" "\xff\xff\xff\xff\xff\xff\xff\xff" "abcdefgh", 16 },
76 { "a" "\xff\xff\xff\xff\xff\xff\xff\xff" "bcdefgh", 16 },
77 { "ab" "\xff\xff\xff\xff\xff\xff\xff\xff" "cdefgh", 16 },
78 { "abc" "\xff\xff\xff\xff\xff\xff\xff\xff" "defgh", 16 },
79 { "abcd" "\xff\xff\xff\xff\xff\xff\xff\xff" "efgh", 16 },
80 { "abcde" "\xff\xff\xff\xff\xff\xff\xff\xff" "fgh", 16 },
81 { "abcdef" "\xff\xff\xff\xff\xff\xff\xff\xff" "gh", 16 },
82 { "abcdefg" "\xff\xff\xff\xff\xff\xff\xff\xff" "h", 16 },
83 { "abcdefgh" "\xff\xff\xff\xff\xff\xff\xff\xff" "", 16 },
86 for (a0
= 0; a0
< sizeof(long); ++a0
) {
87 for (a1
= 0; a1
< sizeof(long); ++a1
) {
88 for (t
= 0; t
< (sizeof(tab
) / sizeof(tab
[0])); ++t
) {
90 memcpy(&buf1
[a1
], tab
[t
].val
, tab
[t
].len
+ 1);
91 ret
= f(&buf0
[a0
], &buf1
[a1
]);
94 * verify strcpy returns address of
97 if (&buf0
[a0
] != ret
) {
98 fprintf(stderr
, "a0 %d, a1 %d, t %d\n",
100 atf_tc_fail("strcpy did not return "
105 * verify string was copied correctly
107 if (memcmp(&buf0
[a0
], &buf1
[a1
],
108 tab
[t
].len
+ 1) != 0) {
109 fprintf(stderr
, "a0 %d, a1 %d, t %d\n",
111 atf_tc_fail("not correctly copied");
121 ATF_TP_ADD_TC(tp
, strcpy_basic
);
123 return atf_no_error();