• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This testing program makes sure the byteswap functions work
3  *
4  * Copyright (C) 2000 by Theodore Ts'o.
5  *
6  * %Begin-Header%
7  * This file may be redistributed under the terms of the GNU Library
8  * General Public License, version 2.
9  * %End-Header%
10  */
11 
12 #include "config.h"
13 #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 
26 #include "ext2_fs.h"
27 #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 
main(int argc,char ** argv)48 int main(int argc, char **argv)
49 {
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);
70 
71 	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");
91 
92 	return errors;
93 }
94