c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * Copyright (c) 2016-2017 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * Permission is hereby granted, free of charge, to any person obtaining a copy
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * of this software and associated documentation files (the "Software"), to deal
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * in the Software without restriction, including without limitation the rights
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * copies of the Software, and to permit persons to whom the Software is
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * furnished to do so, subject to the following conditions:
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * The above copyright notice and this permission notice shall be included in
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * all copies or substantial portions of the Software.
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
08259c1f206026ca9b9f4b4e97603943c6093defJosef 'Jeff' Sipek uint##size##_t got = i_bswap_##size(in); \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek test_begin(t_strdup_printf("byteorder - bswap " \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek "(size:%-2u iter:%u)", \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipekstatic void __test(int iter, const struct bswap_run *run)
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK(iter, 8, run->in & 0xff, run->out8);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK(iter, 16, run->in & 0xffff, run->out16);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK(iter, 32, run->in & 0xffffffff, run->out32);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek unsigned int i;
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipekstatic const struct unaligned_run uruns[] = {
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek#define __CHECK_READ(iter, size, pfx, in, fxn, exp) \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek test_begin(t_strdup_printf("byteorder - unaligned read "\
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek "(%-3s size:%-2u iter:%u)", \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek#define CHECK_READ(iter, size, in, be_exp, le_exp, cpu_exp) \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek cpu##size##_to_cpu_unaligned, cpu_exp); \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipekstatic void __test_read(int iter, const struct unaligned_run *run)
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_READ(iter, 8, run->in, run->be8, run->le8, run->cpu8);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_READ(iter, 16, run->in, run->be16, run->le16, run->cpu16);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_READ(iter, 32, run->in, run->be32, run->le32, run->cpu32);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_READ(iter, 64, run->in, run->be64, run->le64, run->cpu64);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek#define __CHECK_WRITE(iter, size, pfx, in, fxn, exp) \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek test_begin(t_strdup_printf("byteorder - unaligned write "\
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek "(%-3s size:%-2u iter:%u)", \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek test_assert(memcmp(got, exp, sizeof(got)) == 0); \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek#define CHECK_WRITE(iter, size, out, be_in, le_in) \
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipekstatic void __test_write(int iter, const struct unaligned_run *run)
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_WRITE(iter, 8, run->in, run->be8, run->le8);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_WRITE(iter, 16, run->in, run->be16, run->le16);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_WRITE(iter, 32, run->in, run->be32, run->le32);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek CHECK_WRITE(iter, 64, run->in, run->be64, run->le64);
c9d76e2baf653fa5504d6849e5c1aae32eff3c53Josef 'Jeff' Sipek unsigned int i;