@@ -34,6 +34,7 @@ start() ->
3434 ok = run_test (fun () -> test_heap_binary () end ),
3535 ok = run_test (fun () -> test_const_binary () end ),
3636 ok = run_test (fun () -> test_non_const_binary () end ),
37+ ok = run_test (fun () -> test_refc_binaries () end ),
3738 ok = run_test (fun () -> test_send () end ),
3839 ok = run_test (fun () -> test_spawn () end ),
3940 ok = run_test (fun () -> test_spawn_fun () end ),
@@ -66,8 +67,22 @@ test_non_const_binary() ->
6667 id (Bin ),
6768 ok .
6869
70+ test_refc_binaries () ->
71+ String = create_string (1024 ),
72+ Bins = [create_binary (String ) || _ <- [x , x , x ]],
73+ BinsInfo = [{1024 , 1 } || _ <- [x , x , x ]],
74+ ok = verify_refc_binary_info (BinsInfo ),
75+ MoreBins = [create_binary (String ) || _ <- [x , x , x ], _ <- [x , x , x ], _ <- [x , x , x ]],
76+ MoreBinsInfo = BinsInfo ++ [{1024 , 1 } || _ <- [x , x , x ], _ <- [x , x , x ], _ <- [x , x , x ]],
77+ ok = verify_refc_binary_info (MoreBinsInfo ),
78+ id (String ),
79+ id (Bins ),
80+ id (MoreBins ),
81+ ok .
82+
6983test_send () ->
7084 Bin = create_binary (1024 ),
85+ ok = verify_refc_binary_info ([{1024 , 1 }]),
7186 Pid = erlang :spawn (fun () -> loop (# state {}) end ),
7287 PidHeapSize0 = get_heap_size (Pid ),
7388 % %
@@ -77,6 +92,7 @@ test_send() ->
7792 PidHeapSize1 = get_heap_size (Pid ),
7893 true = PidHeapSize0 < PidHeapSize1 ,
7994 true = PidHeapSize1 < 1024 ,
95+ ok = verify_refc_binary_info ([{1024 , 2 }]),
8096 % %
8197 % % Make sure we can get what we sent
8298 % %
@@ -160,6 +176,7 @@ loop(State) ->
160176 Pid ! {Ref , ok },
161177 loop (State # state {bin = Bin });
162178 {Pid , Ref , halt } ->
179+ erlang :garbage_collect (),
163180 Pid ! {Ref , ok }
164181 end .
165182
@@ -187,6 +204,7 @@ run_test(Fun) ->
187204 end .
188205
189206execute (Pid , Fun ) ->
207+ erlang :garbage_collect (),
190208 Result =
191209 try
192210 Fun (),
@@ -197,4 +215,13 @@ execute(Pid, Fun) ->
197215 end ,
198216 Pid ! Result .
199217
218+ verify_refc_binary_info (Expected ) ->
219+ case erlang :system_info (machine ) of
220+ " BEAM" ->
221+ ok ;
222+ _ ->
223+ Expected = erlang :system_info (refc_binary_info ),
224+ ok
225+ end .
226+
200227id (X ) -> X .
0 commit comments