summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2008-12-05 16:27:19 +0100
committerKarel Zak2008-12-05 16:27:19 +0100
commit0112925a991035f7dc6e83daf8a286ec2d29c62a (patch)
tree432707cf32437f9786f9b6d3fa089bcff5dfe5ec
parentinclude: swapheader.h is missing in Makefile.am (diff)
downloadkernel-qcow2-util-linux-0112925a991035f7dc6e83daf8a286ec2d29c62a.tar.gz
kernel-qcow2-util-linux-0112925a991035f7dc6e83daf8a286ec2d29c62a.tar.xz
kernel-qcow2-util-linux-0112925a991035f7dc6e83daf8a286ec2d29c62a.zip
tests: add swabN() regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--tests/commands.sh.in1
-rw-r--r--tests/expected/ts-bitops-swapbytes21
-rw-r--r--tests/helpers/.gitignore1
-rw-r--r--tests/helpers/Makefile.am2
-rw-r--r--tests/helpers/test_byteswap.c114
-rwxr-xr-xtests/ts-bitops-swapbytes29
6 files changed, 167 insertions, 1 deletions
diff --git a/tests/commands.sh.in b/tests/commands.sh.in
index 2c0535bfc..bc4dbbde7 100644
--- a/tests/commands.sh.in
+++ b/tests/commands.sh.in
@@ -9,6 +9,7 @@ TS_TESTUSER=${TS_TESTUSER:-"test"}
# helpers
TS_HELPER_SYSINFO="$TS_TOPDIR/helpers/test_sysinfo"
TS_HELPER_PATHS="$TS_TOPDIR/helpers/test_pathnames"
+TS_HELPER_BYTESWAP="$TS_TOPDIR/helpers/test_byteswap"
# external commands
TS_ECMD_BLKID="@BLKID@"
diff --git a/tests/expected/ts-bitops-swapbytes b/tests/expected/ts-bitops-swapbytes
new file mode 100644
index 000000000..b9468a75e
--- /dev/null
+++ b/tests/expected/ts-bitops-swapbytes
@@ -0,0 +1,21 @@
+Testing swab16
+swab16(0x0001) = 0x0100
+swab16(0x1234) = 0x3412
+swab16(0xff00) = 0x00ff
+swab16(0x4000) = 0x0040
+swab16(0xfeff) = 0xfffe
+Testing swab32
+swab32(0x00000001) = 0x01000000
+swab32(0x80000000) = 0x00000080
+swab32(0x12345678) = 0x78563412
+swab32(0xffff0000) = 0x0000ffff
+swab32(0x00ff0000) = 0x0000ff00
+swab32(0xff000000) = 0x000000ff
+Testing swab64
+swab64(0x0000000000000001) = 0x0100000000000000
+swab64(0x8000000000000000) = 0x0000000000000080
+swab64(0x1234567812345678) = 0x7856341278563412
+swab64(0xffffffff00000000) = 0x00000000ffffffff
+swab64(0x00ff000000000000) = 0x000000000000ff00
+swab64(0xff00000000000000) = 0x00000000000000ff
+No errors found in the byteswap implementation
diff --git a/tests/helpers/.gitignore b/tests/helpers/.gitignore
index de086d537..a2ca1fc06 100644
--- a/tests/helpers/.gitignore
+++ b/tests/helpers/.gitignore
@@ -1,2 +1,3 @@
test_pathnames
test_sysinfo
+test_byteswap
diff --git a/tests/helpers/Makefile.am b/tests/helpers/Makefile.am
index 24dcd2afa..127923295 100644
--- a/tests/helpers/Makefile.am
+++ b/tests/helpers/Makefile.am
@@ -1,4 +1,4 @@
include $(top_srcdir)/config/include-Makefile.am
-noinst_PROGRAMS = test_sysinfo test_pathnames
+noinst_PROGRAMS = test_sysinfo test_pathnames test_byteswap
diff --git a/tests/helpers/test_byteswap.c b/tests/helpers/test_byteswap.c
new file mode 100644
index 000000000..3932d5a13
--- /dev/null
+++ b/tests/helpers/test_byteswap.c
@@ -0,0 +1,114 @@
+/*
+ * This testing program makes sure the byteswap functions work
+ *
+ * Copyright (C) 2000 by Theodore Ts'o.
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include "bitops.h"
+
+uint16_t ary16[] = {
+ 0x0001, 0x0100,
+ 0x1234, 0x3412,
+ 0xff00, 0x00ff,
+ 0x4000, 0x0040,
+ 0xfeff, 0xfffe,
+ 0x0000, 0x0000
+ };
+
+uint32_t ary32[] = {
+ 0x00000001, 0x01000000,
+ 0x80000000, 0x00000080,
+ 0x12345678, 0x78563412,
+ 0xffff0000, 0x0000ffff,
+ 0x00ff0000, 0x0000ff00,
+ 0xff000000, 0x000000ff,
+ 0x00000000, 0x00000000
+ };
+
+uint64_t ary64[] = {
+ 0x0000000000000001, 0x0100000000000000,
+ 0x8000000000000000, 0x0000000000000080,
+ 0x1234567812345678, 0x7856341278563412,
+ 0xffffffff00000000, 0x00000000ffffffff,
+ 0x00ff000000000000, 0x000000000000ff00,
+ 0xff00000000000000, 0x00000000000000ff,
+ 0x0000000000000000, 0x0000000000000000
+ };
+
+int main(int argc, char **argv)
+{
+ int i;
+ int errors = 0;
+
+ printf("Testing swab16\n");
+ i=0;
+ do {
+ printf("swab16(0x%04"PRIx16") = 0x%04"PRIx16"\n",
+ ary16[i], swab16(ary16[i]));
+ if (swab16(ary16[i]) != ary16[i+1]) {
+ printf("Error!!! %04"PRIx16" != %04"PRIx16"\n",
+ swab16(ary16[i]), ary16[i+1]);
+ errors++;
+ }
+ if (swab16(ary16[i+1]) != ary16[i]) {
+ printf("Error!!! %04"PRIx16" != %04"PRIx16"\n",
+ swab16(ary16[i+1]), ary16[i]);
+ errors++;
+ }
+ i += 2;
+ } while (ary16[i] != 0);
+
+ printf("Testing swab32\n");
+ i = 0;
+ do {
+ printf("swab32(0x%08"PRIx32") = 0x%08"PRIx32"\n",
+ ary32[i], swab32(ary32[i]));
+ if (swab32(ary32[i]) != ary32[i+1]) {
+ printf("Error!!! %04"PRIx32" != %04"PRIx32"\n",
+ swab32(ary32[i]), ary32[i+1]);
+ errors++;
+ }
+ if (swab32(ary32[i+1]) != ary32[i]) {
+ printf("Error!!! %04"PRIx32" != %04"PRIx32"\n",
+ swab32(ary32[i+1]), ary32[i]);
+ errors++;
+ }
+ i += 2;
+ } while (ary32[i] != 0);
+
+ printf("Testing swab64\n");
+ i = 0;
+ do {
+ printf("swab64(0x%016"PRIx64") = 0x%016"PRIx64"\n",
+ ary64[i], swab64(ary64[i]));
+ if (swab64(ary64[i]) != ary64[i+1]) {
+ printf("Error!!! %016"PRIx64" != %016"PRIx64"\n",
+ swab64(ary64[i]), ary64[i+1]);
+ errors++;
+ }
+ if (swab64(ary64[i+1]) != ary64[i]) {
+ printf("Error!!! %016"PRIx64" != %016"PRIx64"\n",
+ swab64(ary64[i+1]), ary64[i]);
+ errors++;
+ }
+ i += 2;
+ } while (ary64[i] != 0);
+
+ if (!errors)
+ printf("No errors found in the byteswap implementation\n");
+
+ return errors;
+}
diff --git a/tests/ts-bitops-swapbytes b/tests/ts-bitops-swapbytes
new file mode 100755
index 000000000..78c330dab
--- /dev/null
+++ b/tests/ts-bitops-swapbytes
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux-ng.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+. ./commands.sh
+. ./functions.sh
+
+TS_COMPONENT="bitops"
+TS_DESC="swapbytes"
+
+ts_init "$*"
+
+$TS_HELPER_BYTESWAP >> $TS_OUTPUT
+
+ts_finalize
+