-# $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $
+# $OpenBSD: Makefile,v 1.5 2024/08/26 12:15:40 bluhm Exp $
# $NetBSD: Makefile,v 1.4 1995/04/20 22:37:50 cgd Exp $
-PROG= ./bitstring_test
+PROG= bitstring_test
-REGRESS_TARGETS=test-8 test-27 test-32 test-49 test-64 test-67
+REGRESS_TARGETS=
-test-8: ${PROG}
- ${PROG} 8 | diff - ${.CURDIR}/good/8
+.for i in 8 27 32 49 64 67
-test-27: ${PROG}
- ${PROG} 27 | diff - ${.CURDIR}/good/27
+REGRESS_TARGETS+= run-test-$i
+run-test-$i: ${PROG}
+ ./${PROG} $i | diff - ${.CURDIR}/good/$i
-test-32: ${PROG}
- ${PROG} 32 | diff - ${.CURDIR}/good/32
-
-test-49: ${PROG}
- ${PROG} 49 | diff - ${.CURDIR}/good/49
-
-test-64: ${PROG}
- ${PROG} 64 | diff - ${.CURDIR}/good/64
-
-test-67: ${PROG}
- ${PROG} 67 | diff - ${.CURDIR}/good/67
+create-good: create-$i
+create-$i: ${PROG}
+ ./${PROG} $i >${.CURDIR}/good/$i
+.endfor
.include <bsd.regress.mk>
-/* $OpenBSD: bitstring_test.c,v 1.6 2024/08/23 17:19:16 florian Exp $ */
+/* $OpenBSD: bitstring_test.c,v 1.7 2024/08/26 12:15:40 bluhm Exp $ */
/* $NetBSD: bitstring_test.c,v 1.4 1995/04/29 05:44:35 cgd Exp $ */
/*
* inspect the output, you should notice problems
* choose the ATT or BSD flavor
*/
-/* #define ATT /*- */
+// #define ATT /*-*/
#define BSD /*-*/
/*
static void
printbits(bitstr_t *b, int n)
{
- register int i;
+ register int i, k;
int jc, js;
bit_ffc(b, n, &jc);
int
main(int argc, char *argv[])
{
- int i;
+ int i, j, k, *p;
bitstr_t *bs;
bitstr_t bit_decl(bss, DECL_TEST_LENGTH);
TEST_LENGTH = DECL_TEST_LENGTH;
if (TEST_LENGTH < 4) {
- fprintf(stderr, "TEST_LENGTH must be at least 4, but it is %d\n",
+ fprintf(stderr,
+ "TEST_LENGTH must be at least 4, but it is %d\n",
TEST_LENGTH);
exit(1);
}
}
(void) printf("be: 1 0 ");
for (i = 0; i < TEST_LENGTH; i++)
- (void) putchar(*("100" + (i % 3)));
+ (void) putchar("100"[i % 3]);
(void) printf("\nis: ");
printbits(bs, TEST_LENGTH);
}
(void) printf("be: 0 3 ");
for (i = 0; i < TEST_LENGTH; i++)
- (void) putchar(*("000100" + (i % 6)));
+ (void) putchar("000100"[i % 6]);
(void) printf("\nis: ");
printbits(bs, TEST_LENGTH);
printbits(bs, TEST_LENGTH);
}
+ (void) printf("\n");
+ (void) printf("macros should evaluate arguments only once\n");
+ i = j = 0;
+ _bit_byte(i++);
+ (void) printf("_bit_byte(%d) -> %d\n", j++, i);
+ _bit_mask(i++);
+ (void) printf("_bit_mask(%d) -> %d\n", j++, i);
+ bitstr_size(i++);
+ (void) printf("bitstr_size(%d) -> %d\n", j++, i);
+ free(bit_alloc(i++));
+ (void) printf("bit_alloc(%d) -> %d\n", j++, i);
+ { bitstr_t bit_decl(bd, i++); }
+ (void) printf("bit_alloc(%d) -> %d\n", j++, i);
+ bit_test(bs, i++);
+ (void) printf("bit_test(%d) -> %d\n", j++, i);
+ bit_set(bs, i++);
+ (void) printf("bit_set(%d) -> %d\n", j++, i);
+ bit_clear(bs, i++);
+ (void) printf("bit_clear(%d) -> %d\n", j++, i);
+ i %= TEST_LENGTH; j %= TEST_LENGTH;
+ bit_nclear(bs, i++, i++);
+ (void) printf("bit_nclear(%d, %d) -> %d\n", j, j + 1, i);
+ j += 2;
+ bit_nset(bs, i++, i++);
+ (void) printf("bit_nset(%d, %d) -> %d\n", j, j + 1, i);
+ j += 2;
+ p = &k;
+ bit_ffc(bs, i++, p++);
+ (void) printf("bit_ffc(%d, %ld) -> %d\n", j++, --p - &k, i);
+ bit_ffs(bs, i++, p++);
+ (void) printf("bit_ffs(%d, %ld) -> %d\n", j++, --p - &k, i);
+
(void) free(bs);
- (void) exit(0);
+ return (0);
}