blob: c500cae36550f14502afa9a70fd5cb854d27b26d [file] [log] [blame]
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +00001/*
2 * This testing program makes sure the byteswap functions work
3 *
4 * Copyright (C) 2000 by Theodore Ts'o.
Theodore Ts'oefc6f622008-08-27 23:07:54 -04005 *
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +00006 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04007 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +00009 * %End-Header%
10 */
11
Theodore Ts'od1154eb2011-09-18 17:34:37 -040012#include "config.h"
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000013#include <stdio.h>
14#include <string.h>
15#if HAVE_UNISTD_H
16#include <unistd.h>
17#endif
18#include <fcntl.h>
19#include <time.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22#if HAVE_ERRNO_H
23#include <errno.h>
24#endif
25
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000026#include "ext2_fs.h"
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000027#include "ext2fs.h"
28
29__u16 test1[] = {
30 0x0001, 0x0100,
31 0x1234, 0x3412,
32 0xff00, 0x00ff,
33 0x4000, 0x0040,
34 0xfeff, 0xfffe,
35 0x0000, 0x0000
36 };
37
38__u32 test2[] = {
39 0x00000001, 0x01000000,
40 0x80000000, 0x00000080,
41 0x12345678, 0x78563412,
42 0xffff0000, 0x0000ffff,
43 0x00ff0000, 0x0000ff00,
44 0xff000000, 0x000000ff,
45 0x00000000, 0x00000000
46 };
47
Theodore Ts'o546a1ff2002-03-07 23:52:56 -050048int main(int argc, char **argv)
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000049{
50 int i;
51 int errors = 0;
52
53 printf("Testing ext2fs_swab16\n");
54 i=0;
55 do {
56 printf("swab16(0x%04x) = 0x%04x\n", test1[i],
57 ext2fs_swab16(test1[i]));
58 if (ext2fs_swab16(test1[i]) != test1[i+1]) {
59 printf("Error!!! %04x != %04x\n",
60 ext2fs_swab16(test1[i]), test1[i+1]);
61 errors++;
62 }
63 if (ext2fs_swab16(test1[i+1]) != test1[i]) {
64 printf("Error!!! %04x != %04x\n",
65 ext2fs_swab16(test1[i+1]), test1[i]);
66 errors++;
67 }
68 i += 2;
69 } while (test1[i] != 0);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040070
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000071 printf("Testing ext2fs_swab32\n");
72 i = 0;
73 do {
74 printf("swab32(0x%08x) = 0x%08x\n", test2[i],
75 ext2fs_swab32(test2[i]));
76 if (ext2fs_swab32(test2[i]) != test2[i+1]) {
77 printf("Error!!! %04x != %04x\n",
78 ext2fs_swab32(test2[i]), test2[i+1]);
79 errors++;
80 }
81 if (ext2fs_swab32(test2[i+1]) != test2[i]) {
82 printf("Error!!! %04x != %04x\n",
83 ext2fs_swab32(test2[i+1]), test2[i]);
84 errors++;
85 }
86 i += 2;
87 } while (test2[i] != 0);
88
89 if (!errors)
90 printf("No errors found in the byteswap implementation!\n");
Theodore Ts'oefc6f622008-08-27 23:07:54 -040091
Theodore Ts'o9ec53cf2001-02-20 16:28:40 +000092 return errors;
93}