Add regression test for 32/64-bit aligned fastpath extraction.
authorRichard W.M. Jones <rich@annexia.org>
Fri, 17 Oct 2008 08:58:16 +0000 (08:58 +0000)
committerRichard W.M. Jones <rich@annexia.org>
Fri, 17 Oct 2008 08:58:16 +0000 (08:58 +0000)
MANIFEST
tests/18_extract_32_64_int.ml [new file with mode: 0644]

index 05e83db..5399fc8 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -9,6 +9,7 @@ bitstring_objinfo.ml
 bitstring_persistent.ml
 bitstring_persistent.mli
 bitstring_types.ml
+bootstrap
 byteswap.in.h
 .depend
 cil-tools/bitstring_import_c.ml
@@ -50,6 +51,7 @@ tests/02_run.ml
 tests/10_match_bits.ml
 tests/11_match_ints.ml
 tests/15_extract_int.ml
+tests/18_extract_32_64_int.ml
 tests/20_varsize.ml
 tests/30_bitbuffer.ml
 tests/31_bitstring_concat.ml
diff --git a/tests/18_extract_32_64_int.ml b/tests/18_extract_32_64_int.ml
new file mode 100644 (file)
index 0000000..bee7f3b
--- /dev/null
@@ -0,0 +1,43 @@
+(* Test fix for a regression when extracting 32 and 64 bit aligned
+ * integers (discovered / fixed / tested by Hans Ole Rafaelsen).
+ * $Id$
+ *)
+
+open Printf
+
+open Bitstring
+
+let bitstring_of_int32 i =
+  BITSTRING { i : 32 }
+
+let bitstring_of_int64 i =
+  BITSTRING { i : 64 }
+
+let int32_of_bitstring bits =
+  bitmatch bits with
+  | { i : 32 } -> i
+
+let int64_of_bitstring bits =
+  bitmatch bits with
+  | { i : 64 } -> i
+
+let () =
+  let b1 = bitstring_of_int32 1_l in
+  let b2 = bitstring_of_int32 2_l in
+  let b3 = bitstring_of_int32 3_l in
+  let i1 = int32_of_bitstring b1 in
+  let i2 = int32_of_bitstring b2 in
+  let i3 = int32_of_bitstring b3 in
+  assert (i1 = 1_l);
+  assert (i2 = 2_l);
+  assert (i3 = 3_l);
+
+  let b1 = bitstring_of_int64 1_L in
+  let b2 = bitstring_of_int64 2_L in
+  let b3 = bitstring_of_int64 3_L in
+  let i1 = int64_of_bitstring b1 in
+  let i2 = int64_of_bitstring b2 in
+  let i3 = int64_of_bitstring b3 in
+  assert (i1 = 1_L);
+  assert (i2 = 2_L);
+  assert (i3 = 3_L)