From 9b8dc5de78845a0f155414ce5c1043c403aa061d Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 17 Oct 2008 08:58:16 +0000 Subject: [PATCH 1/1] Add regression test for 32/64-bit aligned fastpath extraction. --- MANIFEST | 2 ++ tests/18_extract_32_64_int.ml | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/18_extract_32_64_int.ml diff --git a/MANIFEST b/MANIFEST index 05e83db..5399fc8 100644 --- 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 index 0000000..bee7f3b --- /dev/null +++ b/tests/18_extract_32_64_int.ml @@ -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) -- 1.8.3.1