ppc/pnv: change initrd address
[qemu/rayw.git] / tests / test-bufferiszero.c
blob42d194cadf45819534ec52ff1060749ba54127bb
1 /*
2 * QEMU buffer_is_zero test
4 * Copyright (c) 2016 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qemu/cutils.h"
24 static char buffer[8 * 1024 * 1024];
26 static void test_1(void)
28 size_t s, a, o;
30 /* Basic positive test. */
31 g_assert(buffer_is_zero(buffer, sizeof(buffer)));
33 /* Basic negative test. */
34 buffer[sizeof(buffer) - 1] = 1;
35 g_assert(!buffer_is_zero(buffer, sizeof(buffer)));
36 buffer[sizeof(buffer) - 1] = 0;
38 /* Positive tests for size and alignment. */
39 for (a = 1; a <= 64; a++) {
40 for (s = 1; s < 1024; s++) {
41 buffer[a - 1] = 1;
42 buffer[a + s] = 1;
43 g_assert(buffer_is_zero(buffer + a, s));
44 buffer[a - 1] = 0;
45 buffer[a + s] = 0;
49 /* Negative tests for size, alignment, and the offset of the marker. */
50 for (a = 1; a <= 64; a++) {
51 for (s = 1; s < 1024; s++) {
52 for (o = 0; o < s; ++o) {
53 buffer[a + o] = 1;
54 g_assert(!buffer_is_zero(buffer + a, s));
55 buffer[a + o] = 0;
61 static void test_2(void)
63 if (g_test_perf()) {
64 test_1();
65 } else {
66 do {
67 test_1();
68 } while (test_buffer_is_zero_next_accel());
72 int main(int argc, char **argv)
74 g_test_init(&argc, &argv, NULL);
75 g_test_add_func("/cutils/bufferiszero", test_2);
77 return g_test_run();