1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This file is licensed under the GPL license.  For the full content
5f08c3bdfSopenharmony_ci * of this license, see the COPYING file at the top level of this
6f08c3bdfSopenharmony_ci * source tree.
7f08c3bdfSopenharmony_ci */
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_ci/*
10f08c3bdfSopenharmony_ci * Function to fill mem with reasonably complicated pattern and function
11f08c3bdfSopenharmony_ci * that checks that pattern is correct.
12f08c3bdfSopenharmony_ci */
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_cistatic void fill_mem(void *dst, size_t size)
15f08c3bdfSopenharmony_ci{
16f08c3bdfSopenharmony_ci	unsigned char *ptr = dst;
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci	while (--size > 0) {
19f08c3bdfSopenharmony_ci		*ptr = (size % 256) ^ 0x42;
20f08c3bdfSopenharmony_ci		ptr++;
21f08c3bdfSopenharmony_ci	}
22f08c3bdfSopenharmony_ci}
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_cistatic int check_mem(void *src, size_t size)
25f08c3bdfSopenharmony_ci{
26f08c3bdfSopenharmony_ci	unsigned char *ptr = src;
27f08c3bdfSopenharmony_ci
28f08c3bdfSopenharmony_ci	while (--size > 0) {
29f08c3bdfSopenharmony_ci		if (*ptr != ((size % 256) ^ 0x42))
30f08c3bdfSopenharmony_ci			return 1;
31f08c3bdfSopenharmony_ci		ptr++;
32f08c3bdfSopenharmony_ci	}
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_ci	return 0;
35f08c3bdfSopenharmony_ci}
36