2001-02-20 19:28:40 +03:00
|
|
|
/*
|
|
|
|
* This testing program makes sure the byteswap functions work
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 by Theodore Ts'o.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
2001-02-20 19:28:40 +03:00
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
2001-02-20 19:28:40 +03:00
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
2001-02-20 19:28:40 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#if HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#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
|
|
|
|
};
|
|
|
|
|
2002-03-08 07:52:56 +03:00
|
|
|
int main(int argc, char **argv)
|
2001-02-20 19:28:40 +03:00
|
|
|
{
|
|
|
|
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);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2001-02-20 19:28:40 +03:00
|
|
|
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");
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2001-02-20 19:28:40 +03:00
|
|
|
return errors;
|
|
|
|
}
|