MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_rte_strlcat

Function test_rte_strlcat

dpdk/app/test/test_string_fns.c:132–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132static int
133test_rte_strlcat(void)
134{
135 /* only run actual unit tests if we have system-provided strlcat */
136#if defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD)
137#define BUF_LEN 32
138 const char dst[BUF_LEN] = "Test string";
139 const char src[] = " appended";
140 char bsd_dst[BUF_LEN];
141 char rte_dst[BUF_LEN];
142 size_t i, bsd_ret, rte_ret;
143
144 LOG("dst = '%s', strlen(dst) = %zu\n", dst, strlen(dst));
145 LOG("src = '%s', strlen(src) = %zu\n", src, strlen(src));
146 LOG("---\n");
147
148 for (i = 0; i < BUF_LEN; i++) {
149 /* initialize destination buffers */
150 memcpy(bsd_dst, dst, BUF_LEN);
151 memcpy(rte_dst, dst, BUF_LEN);
152 /* compare implementations */
153 bsd_ret = strlcat(bsd_dst, src, i);
154 rte_ret = rte_strlcat(rte_dst, src, i);
155 if (bsd_ret != rte_ret) {
156 LOG("Incorrect retval for buf length = %zu\n", i);
157 LOG("BSD: '%zu', rte: '%zu'\n", bsd_ret, rte_ret);
158 return -1;
159 }
160 if (memcmp(bsd_dst, rte_dst, BUF_LEN) != 0) {
161 LOG("Resulting buffers don't match\n");
162 LOG("BSD: '%s', rte: '%s'\n", bsd_dst, rte_dst);
163 return -1;
164 }
165 LOG("buffer size = %zu: dst = '%s', ret = %zu\n",
166 i, rte_dst, rte_ret);
167 }
168 LOG("Checked %zu combinations\n", i);
169#undef BUF_LEN
170#endif /* defined(__BSD_VISIBLE) || defined(RTE_USE_LIBBSD) */
171
172 return 0;
173}
174
175static int
176test_string_fns(void)

Callers 1

test_string_fnsFunction · 0.85

Calls 3

rte_strlcatFunction · 0.85
memcpyFunction · 0.50
strlcatFunction · 0.50

Tested by

no test coverage detected