Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
5681-tar_SUITE-Use-rand-for-generating-random-b...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5681-tar_SUITE-Use-rand-for-generating-random-bytes.patch of Package erlang
From 94643e66fbbabe7bd2c8816fd7a914557fb71b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Thu, 5 May 2022 07:41:01 +0200 Subject: [PATCH 1/3] tar_SUITE: Use rand for generating random bytes --- lib/stdlib/test/tar_SUITE.erl | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/lib/stdlib/test/tar_SUITE.erl b/lib/stdlib/test/tar_SUITE.erl index 4eac9c8162..cce73d7de9 100644 --- a/lib/stdlib/test/tar_SUITE.erl +++ b/lib/stdlib/test/tar_SUITE.erl @@ -113,8 +113,8 @@ borderline_test(Size, TempDir, IsUstar) -> Name = filename:join(TempDir, Prefix++SizeList), %% Create a file and archive it. - X0 = erlang:monotonic_time(), - ok = file:write_file(Name, random_byte_list(X0, Size)), + RandomBytes = rand:bytes(Size), + ok = file:write_file(Name, RandomBytes), ok = erl_tar:create(Archive, [Name]), ok = file:delete(Name), @@ -125,7 +125,7 @@ borderline_test(Size, TempDir, IsUstar) -> %% Verify contents of extracted file. {ok, Bin} = file:read_file(Name), - true = match_byte_list(X0, binary_to_list(Bin)), + RandomBytes = Bin, %% Verify that Unix tar can read it. case IsUstar of @@ -199,34 +199,6 @@ make_cmd(Cmd) -> {unix, _} -> lists:concat(["sh -c '", Cmd, "'"]) end. -%% Verifies a random byte list. - -match_byte_list(X0, [Byte|Rest]) -> - X = next_random(X0), - case (X bsr 26) band 16#ff of - Byte -> match_byte_list(X, Rest); - _ -> false - end; -match_byte_list(_, []) -> - true. - -%% Generates a random byte list. - -random_byte_list(X0, Count) -> - random_byte_list(X0, Count, []). - -random_byte_list(X0, Count, Result) when Count > 0-> - X = next_random(X0), - random_byte_list(X, Count-1, [(X bsr 26) band 16#ff|Result]); -random_byte_list(_X, 0, Result) -> - lists:reverse(Result). - -%% This RNG is from line 21 on page 102 in Knuth: The Art of Computer Programming, -%% Volume II, Seminumerical Algorithms. - -next_random(X) -> - (X*17059465+1) band 16#fffffffff. - %% Test the 'atomic' operations: create/extract/table, on compressed %% and uncompressed archives. %% Also test the 'cooked' option. -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor