/*-
* Copyright (c) 1993, 2008, 2010 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
(void) fprintf(file, "\ntest bit_set\n");
for (i=0; i < test_length; i+=3)
bit_set(bs, i);
(void) fprintf(file, "be: 1 0 ");
for (i=0; i < test_length; i++)
(void) fprintf(file, "%c", "100"[i % 3]);
(void) fprintf(file, "\nis: ");
printbits(file, bs, test_length);
(void) fprintf(file, "\ntest bit_clear\n");
for (i=0; i < test_length; i+=6)
bit_clear(bs, i);
(void) fprintf(file, "be: 0 3 ");
for (i=0; i < test_length; i++)
(void) fprintf(file, "%c", "000100"[i % 6]);
(void) fprintf(file, "\nis: ");
printbits(file, bs, test_length);
(void) fprintf(file, "\ntest bit_test using previous bitstring\n");
(void) fprintf(file, " i bit_test(i)\n");
for (i=0; i < test_length; i++)
(void) fprintf(file, "%3d%15d\n", i, bit_test(bs, i));
(void) fprintf(file, "\n");
(void) fprintf(file, "first 1 bit should move right 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nclear(bs, 0, test_length - 1);
bit_nset(bs, i, test_length - 1);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
(void) fprintf(file, "\n");
(void) fprintf(file, "first 0 bit should move right 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nset(bs, 0, test_length - 1);
bit_nclear(bs, i, test_length - 1);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
(void) fprintf(file, "\n");
(void) fprintf(file, "first 0 bit should move left 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nclear(bs, 0, test_length - 1);
bit_nset(bs, 0, test_length - 1 - i);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
(void) fprintf(file, "\n");
(void) fprintf(file, "first 1 bit should move left 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nset(bs, 0, test_length - 1);
bit_nclear(bs, 0, test_length - 1 - i);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
(void) fprintf(file, "\n");
(void) fprintf(file, "0 bit should move right 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nset(bs, 0, test_length - 1);
bit_nclear(bs, i, i);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
(void) fprintf(file, "\n");
(void) fprintf(file, "1 bit should move right 1 position each line\n");
for (i=0; i < test_length; i++) {
bit_nclear(bs, 0, test_length - 1);
bit_nset(bs, i, i);
(void) fprintf(file, "%3d ", i); printbits(file, bs, test_length);
}
/* XXX The following is a huge hack that was added to simplify the
* conversion of these tests from src/regress/ to src/tests/. The
* tests in this file should be checking their own results, without
* having to resort to external data files. */
snprintf(command, sizeof(command), "diff -u %s/d_bitstring_%d.out out",
atf_tc_get_config_var(tc, "srcdir"), test_length);
if (system(command) != EXIT_SUCCESS)
atf_tc_fail("Test failed; see output for details");
}