diff options
author | John Högberg <[email protected]> | 2018-02-13 12:34:08 +0100 |
---|---|---|
committer | John Högberg <[email protected]> | 2018-02-15 17:00:05 +0100 |
commit | 13497e652a9b9495fbefd52396620bfccc6d7a7c (patch) | |
tree | 3bf4c2e5b1505c4a61b145c15cb26cf1159f3994 /erts/emulator/test | |
parent | 45f2c76f3f4f83e82d6475536e488d4efa724a91 (diff) | |
download | otp-13497e652a9b9495fbefd52396620bfccc6d7a7c.tar.gz otp-13497e652a9b9495fbefd52396620bfccc6d7a7c.tar.bz2 otp-13497e652a9b9495fbefd52396620bfccc6d7a7c.zip |
Handle unaligned binaries in erlang:iolist_to_iovec/1
A binary is a binary as long as its size in bits is evenly divisible
by 8, regardless of whether it has a bit offset or not.
Diffstat (limited to 'erts/emulator/test')
-rw-r--r-- | erts/emulator/test/iovec_SUITE.erl | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/erts/emulator/test/iovec_SUITE.erl b/erts/emulator/test/iovec_SUITE.erl index baf1174a14..76adbe4b5e 100644 --- a/erts/emulator/test/iovec_SUITE.erl +++ b/erts/emulator/test/iovec_SUITE.erl @@ -25,7 +25,7 @@ -export([integer_lists/1, binary_lists/1, empty_lists/1, empty_binary_lists/1, mixed_lists/1, improper_lists/1, illegal_lists/1, cons_bomb/1, sub_binary_lists/1, iolist_to_iovec_idempotence/1, - iolist_to_iovec_correctness/1]). + iolist_to_iovec_correctness/1, unaligned_sub_binaries/1]). -include_lib("common_test/include/ct.hrl"). @@ -36,7 +36,8 @@ suite() -> all() -> [integer_lists, binary_lists, empty_lists, empty_binary_lists, mixed_lists, sub_binary_lists, illegal_lists, improper_lists, cons_bomb, - iolist_to_iovec_idempotence, iolist_to_iovec_correctness]. + iolist_to_iovec_idempotence, iolist_to_iovec_correctness, + unaligned_sub_binaries]. init_per_suite(Config) -> Config. @@ -123,6 +124,15 @@ iolist_to_iovec_correctness(Config) when is_list(Config) -> true = is_iolist_equal(Optimized, Variations), ok. +unaligned_sub_binaries(Config) when is_list(Config) -> + UnalignedBins = [gen_unaligned_binary(I) || I <- lists:seq(32, 4 bsl 10, 512)], + UnalignedVariations = gen_variations(UnalignedBins), + + Optimized = erlang:iolist_to_iovec(UnalignedVariations), + + true = is_iolist_equal(Optimized, UnalignedVariations), + ok. + illegality_test(Fun, Variations) -> [{'EXIT',{badarg, _}} = (catch Fun(Variation)) || Variation <- Variations], ok. @@ -138,6 +148,13 @@ equivalence_test(Fun, [Head | _] = Variations) -> is_iolist_equal(A, B) -> iolist_to_binary(A) =:= iolist_to_binary(B). +gen_unaligned_binary(Size) -> + Bin0 = << <<I>> || I <- lists:seq(1, Size) >>, + <<0:3,Bin:Size/binary,31:5>> = id(<<0:3,Bin0/binary,31:5>>), + Bin. + +id(I) -> I. + %% Generates a bunch of lists whose contents will be equal to Base repeated a %% few times. The lists only differ by their structure, so their reduction to %% a simpler format should yield the same result. |