Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This testing program makes sure the byteswap functions work |
| 3 | * |
| 4 | * Copyright (C) 2000 by Theodore Ts'o. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 5 | * |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 6 | * %Begin-Header% |
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 7 | * This file may be redistributed under the terms of the GNU Library |
| 8 | * General Public License, version 2. |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 9 | * %End-Header% |
| 10 | */ |
| 11 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 12 | #include "config.h" |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 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 | |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 26 | #include "ext2_fs.h" |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 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 | |
Theodore Ts'o | 546a1ff | 2002-03-07 23:52:56 -0500 | [diff] [blame] | 48 | int main(int argc, char **argv) |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 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); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 70 | |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 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"); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 91 | |
Theodore Ts'o | 9ec53cf | 2001-02-20 16:28:40 +0000 | [diff] [blame] | 92 | return errors; |
| 93 | } |