4
%% Copyright Ericsson AB 2007-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
%% Originally based on Per Gustafsson's test suite.
24
-module(bs_bincomp_SUITE).
26
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
27
init_per_group/2,end_per_group/2,
28
init_per_testcase/2,end_per_testcase/2,
29
byte_aligned/1,bit_aligned/1,extended_byte_aligned/1,
30
extended_bit_aligned/1,mixed/1]).
32
-include_lib("test_server/include/test_server.hrl").
34
init_per_testcase(_Case, Config) ->
35
test_lib:interpret(?MODULE),
36
Dog = test_server:timetrap(?t:minutes(1)),
37
[{watchdog,Dog}|Config].
39
end_per_testcase(_Case, Config) ->
40
Dog = ?config(watchdog, Config),
41
?t:timetrap_cancel(Dog),
44
suite() -> [{ct_hooks,[ts_install_cth]}].
47
[byte_aligned, bit_aligned, extended_byte_aligned,
48
extended_bit_aligned, mixed].
53
init_per_suite(Config) ->
56
end_per_suite(_Config) ->
59
init_per_group(_GroupName, Config) ->
62
end_per_group(_GroupName, Config) ->
67
byte_aligned(Config) when is_list(Config) ->
68
?line <<"abcdefg">> = << <<(X+32)>> || <<X>> <= <<"ABCDEFG">> >>,
69
?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
70
<< <<X:32/little>> || <<X:32>> <= <<1:32,2:32,3:32,4:32>> >>,
71
?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
72
<< <<X:32/little>> || <<X:16>> <= <<1:16,2:16,3:16,4:16>> >>,
75
bit_aligned(Config) when is_list(Config) ->
76
?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> =
77
<< <<(X+32):7>> || <<X>> <= <<"ABCDEFG">> >>,
79
<< <<(X-32)>> || <<X:7>> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> >>,
80
?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
81
<< <<X:31/little>> || <<X:31>> <= <<1:31,2:31,3:31,4:31>> >>,
82
?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
83
<< <<X:31/little>> || <<X:15>> <= <<1:15,2:15,3:15,4:15>> >>,
86
extended_byte_aligned(Config) when is_list(Config) ->
87
?line <<"abcdefg">> = << <<(X+32)>> || X <- "ABCDEFG" >>,
88
?line "abcdefg" = [(X+32) || <<X>> <= <<"ABCDEFG">>],
89
?line <<1:32/little,2:32/little,3:32/little,4:32/little>> =
90
<< <<X:32/little>> || X <- [1,2,3,4] >>,
91
?line [256,512,768,1024] =
92
[X || <<X:16/little>> <= <<1:16,2:16,3:16,4:16>>],
95
extended_bit_aligned(Config) when is_list(Config) ->
96
?line <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>> =
97
<< <<(X+32):7>> || X <- "ABCDEFG" >>,
98
?line "ABCDEFG" = [(X-32) || <<X:7>> <= <<$a:7,$b:7,$c:7,$d:7,$e:7,$f:7,$g:7>>],
99
?line <<1:31/little,2:31/little,3:31/little,4:31/little>> =
100
<< <<X:31/little>> || X <- [1,2,3,4] >>,
101
?line [256,512,768,1024] =
102
[X || <<X:15/little>> <= <<1:15,2:15,3:15,4:15>>],
105
mixed(Config) when is_list(Config) ->
106
?line <<2,3,3,4,4,5,5,6>> =
107
<< <<(X+Y)>> || <<X>> <= <<1,2,3,4>>, <<Y>> <= <<1,2>> >>,
108
?line <<2,3,3,4,4,5,5,6>> =
109
<< <<(X+Y)>> || <<X>> <= <<1,2,3,4>>, Y <- [1,2] >>,
110
?line <<2,3,3,4,4,5,5,6>> =
111
<< <<(X+Y)>> || X <- [1,2,3,4], Y <- [1,2] >>,
112
?line [2,3,3,4,4,5,5,6] =
113
[(X+Y) || <<X>> <= <<1,2,3,4>>, <<Y>> <= <<1,2>>],
114
?line [2,3,3,4,4,5,5,6] =
115
[(X+Y) || <<X>> <= <<1,2,3,4>>, Y <- [1,2]],
116
?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
117
<< <<(X+Y):3>> || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>> >>,
118
?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
119
<< <<(X+Y):3>> || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2] >>,
120
?line <<2:3,3:3,3:3,4:3,4:3,5:3,5:3,6:3>> =
121
<< <<(X+Y):3>> || X <- [1,2,3,4], Y <- [1,2] >>,
122
?line [2,3,3,4,4,5,5,6] =
123
[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, <<Y:3>> <= <<1:3,2:3>>],
124
?line [2,3,3,4,4,5,5,6] =
125
[(X+Y) || <<X:3>> <= <<1:3,2:3,3:3,4:3>>, Y <- [1,2]],