[erlang-bugs] binary_to_term--are these bugs?

John Hughes john.hughes@REDACTED
Sun Jan 20 16:55:56 CET 2008


Hi Zvi,

I guess I should have explained them. They're part of QuickCheck, our
testing tool, not Erlang/OTP.

- ?FORALL(Bin,binary(),...) binds Bin to a randomly generated binary within
the rest of the property.

- ?WHENFAIL(io:format(...),...) tells QuickCheck to run the io:format only
when reporting a failed test case.

- ?LET(L,list(...),...) is used to define the binary test data generator: it
binds L to a random list of bytes, which is then converted to a binary.

QuickCheck then generates and runs tests, and when a test fails, simplifies
it to a minimal failing example. The values you see printed are the value of
Bin (printed by ?FORALL), and the values of Term and Bins (printed by
?WHENFAIL). I ran a few thousand tests to find these examples. There's more
information about QuickCheck at www.quviq.com.

By the way, if you're still running R11B then try this one for fun:

binary_to_term(<<131,105,165,0,0,0>>).

(It's fixed in R12B). This one took some tens of thousands of tests, and a
bit more work on my part, to find and simplify.

John

----------------------------------------------------------------------

Date: Sat, 19 Jan 2008 12:16:48 -0800 (PST)
From: Zvi <exta7@REDACTED>
Subject: Re: [erlang-bugs] binary_to_term--are these bugs?
To: erlang-bugs@REDACTED
Message-ID: <14974713.post@REDACTED>
Content-Type: text/plain; charset=us-ascii


Hi John,

can you please tell where these macros defines?

?FORALL
?WHENFAIL
?LET

TIA,
Zvi


John Hughes-7 wrote:
> 
> I've found some behaviour that I didn't expect in binary_to_term in R12B.
> I'm testing the QuickCheck property
> 
>  
> 
> prop_binary_to_term() ->
> 
>     ?FORALL(Bin,binary(),
> 
>               case catch binary_to_term(Bin) of
> 
>                    {'EXIT',{badarg,_}} ->
> 
>                        true;
> 
>                    Term ->
> 
>                        Bins = term_to_binaries(Term),
> 
>                        ?WHENFAIL(io:format("~p~n~p~n",[Term,Bins]),
> 
>                                    lists:any(fun(Bin2)->Bin=:=Bin2
> end,Bins))
> 
>               end).
> 
>  
> 
> term_to_binaries(T) ->
> 
>    
> lists:usort([term_to_binary(T,[{compressed,Level},{minor_version,Ver}])
> 
>                     || Level <- lists:seq(0,9),
> 
>                        Ver <- [0,1]]).
> 
>  
> 
> binary() ->
> 
>     ?LET(L,list(choose(0,255)),
> 
>            list_to_binary(L)).
> 
>  
> 
> The property says that any binary that binary_to_term successfully
> decodes,
> must be an encoding of that term using some compression level and minor
> version (the encoding options mentioned in the documentation). But it
> fails,
> on, for example:
> 
>  
> 
> <<131,97,0,0>>
> 
> 0
> 
> [<<131,97,0>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,106,0>>
> 
> []
> 
> [<<131,106>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,106,191,1,69,44,184,180,64>>
> 
> []
> 
> [<<131,106>>]
> 
>  
> 
> Or
> 
>  
> 
> <<131,67,0>>
> 
> '_'
> 
> [<<131,100,0,1,95>>]
> 
>  
> 
> where the output in each case is the binary, the term it decodes to, and
> the
> list of all possible encodings produced by term_to_binary.
> 
>  
> 
> Is this a bug?
> 
>  
> 
> John
> 
> 
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs
> 

-- 
View this message in context:
http://www.nabble.com/binary_to_term--are-these-bugs--tp14950900p14974713.ht
ml
Sent from the Erlang Bugs mailing list archive at Nabble.com.



------------------------------

_______________________________________________
erlang-bugs mailing list
erlang-bugs@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-bugs

End of erlang-bugs Digest, Vol 104, Issue 1
*******************************************





More information about the erlang-bugs mailing list