/*
* Copyright (c) 2016-2017 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "test-lib.h"
#include "byteorder.h"
struct bswap_run {
};
{
.in = 0,
.out8 = 0,
.out16 = 0,
.out32 = 0,
.out64 = 0,
},
{
.in = 0xffffffffffffffff,
.out8 = 0xff,
.out16 = 0xffff,
.out32 = 0xffffffff,
.out64 = 0xffffffffffffffff,
},
{
.in = 0x123456789abcdef0,
.out8 = 0xf0,
.out16 = 0xf0de,
.out32 = 0xf0debc9a,
.out64 = 0xf0debc9a78563412,
},
{
.in = 0x8080808080808080,
.out8 = 0x80,
.out16 = 0x8080,
.out32 = 0x80808080,
.out64 = 0x8080808080808080,
},
};
do { \
\
"(size:%-2u iter:%u)", \
test_end(); \
} while (0)
{
}
static void test_bswap(void)
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(runs) ; i++)
}
struct unaligned_run {
/* outputs */
#ifdef WORDS_BIGENDIAN
#else
#endif
};
{
.in = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
.be8 = 0,
.be16 = 0,
.be32 = 0,
.be64 = 0,
.le8 = 0,
.le16 = 0,
.le32 = 0,
.le64 = 0,
},
{
.in = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
},
.be8 = 0xff,
.be16 = 0xffff,
.be32 = 0xffffffff,
.be64 = 0xffffffffffffffff,
.le8 = 0xff,
.le16 = 0xffff,
.le32 = 0xffffffff,
.le64 = 0xffffffffffffffff,
},
{
.in = {
0x12, 0x34, 0x56, 0x78,
0x9a, 0xbc, 0xde, 0xf0,
},
.be8 = 0x12,
.be16 = 0x1234,
.be32 = 0x12345678,
.be64 = 0x123456789abcdef0,
.le8 = 0x12,
.le16 = 0x3412,
.le32 = 0x78563412,
.le64 = 0xf0debc9a78563412,
},
{
.in = {
0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80,
},
.be8 = 0x80,
.be16 = 0x8080,
.be32 = 0x80808080,
.be64 = 0x8080808080808080,
.le8 = 0x80,
.le16 = 0x8080,
.le32 = 0x80808080,
.le64 = 0x8080808080808080,
},
};
do { \
\
"(%-3s size:%-2u iter:%u)", \
test_end(); \
} while (0)
do { \
} while (0)
{
}
do { \
\
\
"(%-3s size:%-2u iter:%u)", \
test_end(); \
} while (0)
do { \
} while (0)
{
}
static void test_unaligned(void)
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(uruns) ; i++)
__test_read(i, &uruns[i]);
for (i = 0; i < N_ELEMENTS(uruns) ; i++)
__test_write(i, &uruns[i]);
}
void test_byteorder(void)
{
test_bswap();
}