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