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)
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++) {
43 g_assert(buffer_is_zero(buffer + a, s));
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) {
54 g_assert(!buffer_is_zero(buffer + a, s));
61 static void test_2(void)
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);