MOS Source Code
Loading...
Searching...
No Matches
test_memops.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "test_engine_impl.h"
4
5#include <mos_stdlib.h>
6#include <mos_string.h>
7
8MOS_TEST_CASE(test_lib_memcpy)
9{
10 char *src = kcalloc(500, sizeof(char));
11 char *dst = kcalloc(500, sizeof(char));
12
13 for (size_t i = 0; i < 500; i++)
14 src[i] = i;
15
16 memcpy(dst, src, 500);
17
18 for (size_t i = 0; i < 500; i++)
19 MOS_TEST_CHECK(dst[i] == src[i], true);
20
21 kfree(src);
22 kfree(dst);
23}
24
25MOS_TEST_CASE(test_lib_memmove_simple)
26{
27 char *src = kcalloc(500, sizeof(char));
28 char *dst = kcalloc(500, sizeof(char));
29
30 for (size_t i = 0; i < 500; i++)
31 src[i] = i;
32
33 memmove(dst, src, 500);
34 for (size_t i = 0; i < 500; i++)
35 MOS_TEST_CHECK(dst[i] == src[i], true);
36
37 kfree(src);
38 kfree(dst);
39}
40
41MOS_TEST_CASE(test_memmove_overlapped)
42{
43 size_t *src = kcalloc(500, sizeof(size_t));
44
45 for (size_t i = 0; i < 300; i++)
46 src[i] = i;
47
48 memmove(src + 200, src, 300 * sizeof(size_t));
49
50 for (size_t i = 200; i < 500; i++)
51 MOS_TEST_CHECK(src[i], i - 200);
52
53 kfree(src);
54}
55
56MOS_TEST_CASE(test_memmove_overlapped_backwards)
57{
58 size_t *src = kcalloc(500, sizeof(size_t));
59
60 for (size_t i = 0; i < 500; i++)
61 src[i] = i;
62
63 // | 0 - 99 - 100 - 199 - 200 - 299| - 300 - 399 - 400 - 499
64 memmove(src, src + 200, 300 * sizeof(size_t));
65 // |200 - 299 - 300 - 399 - 400 - 499| - 300 - 399 - 400 - 499
66
67 // the front 200 ~ 499 area
68 for (size_t i = 0; i < 300; i++)
69 MOS_TEST_CHECK(src[i], i + 200);
70
71 // 300 ~ 499 area
72 for (size_t i = 300; i < 500; i++)
73 MOS_TEST_CHECK(src[i], i);
74 kfree(src);
75}
MOSAPI void * memmove(void *dest, const void *src, size_t n)
Definition mos_string.c:111
static void * memcpy(void *s1, const void *s2, size_t n)
Definition pb_syshdr.h:90
#define MOS_TEST_CHECK(actual, expected)
#define MOS_TEST_CASE(_TestName)