From 5dced3d1b3deca80e01415a2e35dc7972dcbfae7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 11:25:10 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- lib/ext2fs/tst_byteswap.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/ext2fs/tst_byteswap.c (limited to 'lib/ext2fs/tst_byteswap.c') diff --git a/lib/ext2fs/tst_byteswap.c b/lib/ext2fs/tst_byteswap.c new file mode 100644 index 0000000..c500cae --- /dev/null +++ b/lib/ext2fs/tst_byteswap.c @@ -0,0 +1,93 @@ +/* + * This testing program makes sure the byteswap functions work + * + * Copyright (C) 2000 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "config.h" +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include +#if HAVE_ERRNO_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +__u16 test1[] = { + 0x0001, 0x0100, + 0x1234, 0x3412, + 0xff00, 0x00ff, + 0x4000, 0x0040, + 0xfeff, 0xfffe, + 0x0000, 0x0000 + }; + +__u32 test2[] = { + 0x00000001, 0x01000000, + 0x80000000, 0x00000080, + 0x12345678, 0x78563412, + 0xffff0000, 0x0000ffff, + 0x00ff0000, 0x0000ff00, + 0xff000000, 0x000000ff, + 0x00000000, 0x00000000 + }; + +int main(int argc, char **argv) +{ + int i; + int errors = 0; + + printf("Testing ext2fs_swab16\n"); + i=0; + do { + printf("swab16(0x%04x) = 0x%04x\n", test1[i], + ext2fs_swab16(test1[i])); + if (ext2fs_swab16(test1[i]) != test1[i+1]) { + printf("Error!!! %04x != %04x\n", + ext2fs_swab16(test1[i]), test1[i+1]); + errors++; + } + if (ext2fs_swab16(test1[i+1]) != test1[i]) { + printf("Error!!! %04x != %04x\n", + ext2fs_swab16(test1[i+1]), test1[i]); + errors++; + } + i += 2; + } while (test1[i] != 0); + + printf("Testing ext2fs_swab32\n"); + i = 0; + do { + printf("swab32(0x%08x) = 0x%08x\n", test2[i], + ext2fs_swab32(test2[i])); + if (ext2fs_swab32(test2[i]) != test2[i+1]) { + printf("Error!!! %04x != %04x\n", + ext2fs_swab32(test2[i]), test2[i+1]); + errors++; + } + if (ext2fs_swab32(test2[i+1]) != test2[i]) { + printf("Error!!! %04x != %04x\n", + ext2fs_swab32(test2[i+1]), test2[i]); + errors++; + } + i += 2; + } while (test2[i] != 0); + + if (!errors) + printf("No errors found in the byteswap implementation!\n"); + + return errors; +} -- cgit v1.2.3