diff options
author | Kostis Sagonas <[email protected]> | 2014-01-12 20:10:49 +0100 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2014-02-24 16:57:30 +0100 |
commit | 7dae40dd0d595776eec7c0407a7849962650e762 (patch) | |
tree | ed38c5c773db2c8d55ea5662ee27cbe71ee65f2f /lib/hipe/test/bs_SUITE_data/bs_checksum.erl | |
parent | 4ce83eb728748787f8a2da6155112c6da42a0eba (diff) | |
download | otp-7dae40dd0d595776eec7c0407a7849962650e762.tar.gz otp-7dae40dd0d595776eec7c0407a7849962650e762.tar.bz2 otp-7dae40dd0d595776eec7c0407a7849962650e762.zip |
Add tests for the HiPE compiler (Part 1: binaries and bitstrings)
Create tests for the HiPE native code compiler. This is the first
part of the effort and contains tests that check that the native
code produced by the HiPE compiler for binaries and bitstrings is
OK and behaves similarly to the code produced by the BEAM compiler.
Diffstat (limited to 'lib/hipe/test/bs_SUITE_data/bs_checksum.erl')
-rw-r--r-- | lib/hipe/test/bs_SUITE_data/bs_checksum.erl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/hipe/test/bs_SUITE_data/bs_checksum.erl b/lib/hipe/test/bs_SUITE_data/bs_checksum.erl new file mode 100644 index 0000000000..ca4f254f12 --- /dev/null +++ b/lib/hipe/test/bs_SUITE_data/bs_checksum.erl @@ -0,0 +1,35 @@ +%% -*- erlang-indent-level: 2 -*- +%%-------------------------------------------------------------------- +%% Code from Zoltan Toth that crashed the HiPE compiler (in R11B-3). +%% The problem was that the binary matching produces a pretty large +%% integer and we tried to find the range for this integer in a bad way. +%% Fixed on the same day -- 6th March 2007. +%%-------------------------------------------------------------------- + +-module(bs_checksum). + +-export([test/0]). + +test() -> + "3389DAE361AF79B04C9C8E7057F60CC6" = checksum(<<42>>), + ok. + +checksum(Bin) -> + Context = erlang:md5_init(), + checksum(Context, Bin). + +checksum(Context, <<>>) -> + bin_to_hex(erlang:md5_final(Context)); +checksum(Context, <<Bin:20480/binary,Rest/binary>>) -> + checksum(erlang:md5_update(Context, Bin), Rest); +checksum(Context,Bin) -> + checksum(erlang:md5_update(Context, Bin), <<>>). + +bin_to_hex(Bin) -> + lists:flatten([byte_to_hex(X) || X <- binary_to_list(Bin)]). + +byte_to_hex(Byte) -> + [int_to_hex(Byte div 16), int_to_hex(Byte rem 16)]. + +int_to_hex(Int) when Int < 10 -> $0 + Int; +int_to_hex(Int) when Int > 9 -> $A + Int - 10. |