summaryrefslogtreecommitdiff
path: root/libarchive/test/test_read_pax_truncated.c
diff options
context:
space:
mode:
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2020-09-17 18:28:17 +0100
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>2022-01-15 13:47:21 +0000
commit10a9214ac65e171f08589ef0ec94ffcbccbfcc49 (patch)
tree69acfc0e0ab9faaa856f692a49fc0390d8c835dc /libarchive/test/test_read_pax_truncated.c
parentb9675888c288fb8b293a69783712bbc2a4573773 (diff)
downloadlibarchive-10a9214ac65e171f08589ef0ec94ffcbccbfcc49.tar.gz
Avoid millions of rand() calls() when running tests
Many tests use a loop calling rand() to fill buffers with test data. As these calls cannot be inlined, this adds up to noticeable overhead: For example, running on QEMU RISC-V the test_write_format_7zip_large_copy test took ~22 seconds before and with this change it's ~17 seconds. This change uses a simpler xorshift64 random number generator that can be inlined into the loop filling the data buffer. By default the seed for this RNG is rand(), but it can be overwritten by setting the TEST_RANDOM_SEED environment variable. For a native build the difference is much less noticeable, but it's still measurable: test_write_format_7zip_large_copy takes 314.9 ms ± 3.9 ms before and 227.8 ms ± 5.8 ms after (i.e. 38% faster for that test).
Diffstat (limited to 'libarchive/test/test_read_pax_truncated.c')
-rw-r--r--libarchive/test/test_read_pax_truncated.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/libarchive/test/test_read_pax_truncated.c b/libarchive/test/test_read_pax_truncated.c
index 1f6e78ac..a6705fa9 100644
--- a/libarchive/test/test_read_pax_truncated.c
+++ b/libarchive/test/test_read_pax_truncated.c
@@ -23,6 +23,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+#include "test_utils.h"
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_read_pax_truncated.c 189483 2009-03-07 03:34:34Z kientzle $");
DEFINE_TEST(test_read_pax_truncated)
@@ -48,8 +49,8 @@ DEFINE_TEST(test_read_pax_truncated)
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "file");
archive_entry_set_mode(ae, S_IFREG | 0755);
- for (i = 0; i < filedata_size; i++)
- filedata[i] = (unsigned char)rand();
+ fill_with_pseudorandom_data(filedata, filedata_size);
+
archive_entry_set_atime(ae, 1, 2);
archive_entry_set_ctime(ae, 3, 4);
archive_entry_set_mtime(ae, 5, 6);