1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 <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
};
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;
}
|