~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/test/binary_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
 
27
27
%%      binary_to_list/1
28
28
%%      binary_to_list/3
29
29
%%      binary_to_term/1
 
30
%%      binary_to_term/2
30
31
%%      bitstr_to_list/1
31
32
%%      term_to_binary/1
32
33
%%      erlang:external_size/1
49
50
         t_hash/1,
50
51
         bad_size/1,
51
52
         bad_term_to_binary/1,
52
 
         bad_binary_to_term_2/1,
 
53
         bad_binary_to_term_2/1,safe_binary_to_term2/1,
53
54
         bad_binary_to_term/1, bad_terms/1, more_bad_terms/1,
54
55
         otp_5484/1,otp_5933/1,
55
56
         ordering/1,unaligned_order/1,gc_test/1,
66
67
     t_split_binary, bad_split, t_concat_binary,
67
68
     bad_list_to_binary, bad_binary_to_list, terms, terms_float,
68
69
     external_size, t_iolist_size,
69
 
     bad_binary_to_term_2,
 
70
     bad_binary_to_term_2,safe_binary_to_term2,
70
71
     bad_binary_to_term, bad_terms, t_hash, bad_size, bad_term_to_binary,
71
72
     more_bad_terms, otp_5484, otp_5933, ordering, unaligned_order,
72
73
     gc_test, bit_sized_binary_sizes, bitlevel_roundtrip, otp_6817, otp_8117,
438
439
                              ok
439
440
                      end,
440
441
                      Term = binary_to_term(Bin),
 
442
                      Term = erlang:binary_to_term(Bin, [safe]),
441
443
                      Unaligned = make_unaligned_sub_binary(Bin),
442
444
                      Term = binary_to_term(Unaligned),
 
445
                      Term = erlang:binary_to_term(Unaligned, []),
 
446
                      Term = erlang:binary_to_term(Bin, [safe]),
443
447
                      BinC = erlang:term_to_binary(Term, [compressed]),
444
448
                      Term = binary_to_term(BinC),
445
449
                      true = size(BinC) =< size(Bin),
538
542
bad_bin_to_term(BadBin) ->
539
543
    {'EXIT',{badarg,_}} = (catch binary_to_term(BadBin)).
540
544
 
 
545
bad_bin_to_term(BadBin,Opts) ->
 
546
    {'EXIT',{badarg,_}} = (catch erlang:binary_to_term(BadBin,Opts)).
 
547
 
 
548
safe_binary_to_term2(doc) -> "Test safety options for binary_to_term/2";
 
549
safe_binary_to_term2(Config) when is_list(Config) ->
 
550
    ?line bad_bin_to_term(<<131,100,0,14,"undefined_atom">>, [safe]),
 
551
    ?line bad_bin_to_term(<<131,100,0,14,"other_bad_atom">>, [safe]),
 
552
    BadHostAtom = <<100,0,14,"badguy@badhost">>,
 
553
    Empty = <<0,0,0,0>>,
 
554
    BadRef = <<131,114,0,3,BadHostAtom/binary,0,<<0,0,0,255>>/binary,
 
555
              Empty/binary,Empty/binary>>,
 
556
    ?line bad_bin_to_term(BadRef, [safe]), % good ref, with a bad atom
 
557
    ?line fullsweep_after = erlang:binary_to_term(<<131,100,0,15,"fullsweep_after">>, [safe]), % should be a good atom
 
558
    BadExtFun = <<131,113,100,0,4,98,108,117,101,100,0,4,109,111,111,110,97,3>>,
 
559
    ?line bad_bin_to_term(BadExtFun, [safe]),
 
560
    ok.
 
561
 
541
562
%% Tests bad input to binary_to_term/1.
542
563
 
543
564
bad_terms(suite) -> [];
559
580
    ?line corrupter(CompressedBin, size(CompressedBin)-1).
560
581
 
561
582
corrupter(Bin, Pos) when Pos >= 0 ->
562
 
    ?line {ShorterBin, _} = split_binary(Bin, Pos),
 
583
    ?line {ShorterBin, Rest} = split_binary(Bin, Pos),
563
584
    ?line catch binary_to_term(ShorterBin), %% emulator shouldn't crash
564
585
    ?line MovedBin = list_to_binary([ShorterBin]),
565
586
    ?line catch binary_to_term(MovedBin), %% emulator shouldn't crash
566
 
    ?line corrupter(MovedBin, Pos-1);
 
587
 
 
588
    %% Bit faults, shouldn't crash
 
589
    <<Byte,Tail/binary>> = Rest,
 
590
    Fun = fun(M) -> FaultyByte = Byte bxor M,                    
 
591
                    catch binary_to_term(<<ShorterBin/binary,
 
592
                                          FaultyByte, Tail/binary>>) end,
 
593
    ?line lists:foreach(Fun,[1,2,4,8,16,32,64,128,255]),    
 
594
    ?line corrupter(Bin, Pos-1);
567
595
corrupter(_Bin, _) ->
568
596
    ok.
569
597