int v14_test_async_tx_get_bit(void *user_data) { async_tx_state_t *s; int bit; int parity_bit; static int destuff = 0; /* Special routine to test V.14 rate adaption, by randomly skipping stop bits. */ s = (async_tx_state_t *) user_data; if (s->bitpos == 0) { s->byte_in_progress = s->get_byte(s->user_data); s->byte_in_progress &= (0xFFFF >> (16 - s->data_bits)); if (s->parity) { parity_bit = parity8(s->byte_in_progress); if (s->parity == ASYNC_PARITY_ODD) parity_bit ^= 1; s->byte_in_progress |= (parity_bit << s->data_bits); s->byte_in_progress |= (0xFFFF << (s->data_bits + 1)); } else { s->byte_in_progress |= (0xFFFF << s->data_bits); } /* Start bit */ bit = 0; s->bitpos++; }
int main(int argc, char *argv[]) { int i; uint32_t x; uint8_t ax; uint8_t bx; uint16_t ax16; uint16_t bx16; uint32_t ax32; uint32_t bx32; for (i = 0, x = 0; i < 100000; i++) { ax = top_bit_dumb(x); bx = top_bit(x); if (ax != bx) { printf("Test failed: top bit mismatch 0x%" PRIx32 " -> %u %u\n", x, ax, bx); exit(2); } ax = bottom_bit_dumb(x); bx = bottom_bit(x); if (ax != bx) { printf("Test failed: bottom bit mismatch 0x%" PRIx32 " -> %u %u\n", x, ax, bx); exit(2); } x = rand(); } for (i = 0; i < 256; i++) { ax = bit_reverse8_dumb(i); bx = bit_reverse8(i); if (ax != bx) { printf("Test failed: bit reverse 8 - %02x %02x %02x\n", i, ax, bx); exit(2); } } for (i = 0; i < 1000000; i++) from[i] = rand(); bit_reverse(to, from, 1000000); for (i = 0; i < 1000000; i++) { if (bit_reverse8_dumb(from[i]) != to[i]) { printf("Test failed: bit reverse - at %d, %02x %02x %02x\n", i, from[i], bit_reverse8(from[i]), to[i]); exit(2); } } for (i = 0; i < 256; i++) { x = i | (((i + 1) & 0xFF) << 8) | (((i + 2) & 0xFF) << 16) | (((i + 3) & 0xFF) << 24); ax32 = bit_reverse_4bytes_dumb(x); bx32 = bit_reverse_4bytes(x); if (ax32 != bx32) { printf("Test failed: bit reverse 4 bytes - %" PRIx32 " %" PRIx32 " %" PRIx32 "\n", x, ax32, bx32); exit(2); } } for (i = 0; i < 65536; i++) { ax16 = bit_reverse16_dumb(i); bx16 = bit_reverse16(i); if (ax16 != bx16) { printf("Test failed: bit reverse 16 - %x %x %x\n", i, ax16, bx16); exit(2); } } for (i = 0; i < 0x7FFFFF00; i += 127) { ax32 = bit_reverse32_dumb(i); bx32 = bit_reverse32(i); if (ax32 != bx32) { printf("Test failed: bit reverse 32 - %d %" PRIx32 " %" PRIx32 "\n", i, ax32, bx32); exit(2); } } for (i = 0; i < 256; i++) { ax = parity8(i); bx = parity8_dumb(i); if (ax != bx) { printf("Test failed: parity 8 - %x %x %x\n", i, ax, bx); exit(2); } } for (i = -1; i < 32; i++) { ax32 = most_significant_one32(1 << i); if (ax32 != (1 << i)) { printf("Test failed: most significant one 32 - %x %" PRIx32 " %x\n", i, ax32, (1 << i)); exit(2); } ax32 = least_significant_one32(1 << i); if (ax32 != (1 << i)) { printf("Test failed: least significant one 32 - %x %" PRIx32 " %x\n", i, ax32, (1 << i)); exit(2); } } for (i = 0x80000000; i < 0x800FFFFF; i++) { ax = one_bits32_dumb(i); bx = one_bits32(i); if (ax != bx) { printf("Test failed: one bits - %d, %x %x\n", i, ax, bx); exit(2); } } printf("Tests passed.\n"); return 0; }