summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@android.com>2016-06-28 07:51:33 -0700
committerRom Lemarchand <romlem@google.com>2016-06-28 07:51:33 -0700
commitc1eb02e560462434f96139e6d9d3398112ac8203 (patch)
treee8bf71f598f2c67ff434cbccc3d5585f0061964a
parentb5769be9cd537023d632e622d879d17c277b2f1a (diff)
downloadextras-c1eb02e560462434f96139e6d9d3398112ac8203.tar.gz
pagingtest: fix large read errors
Some kernels have a limit on the length of reads from urandom - fix Change-Id: I67dda25c2e43121da1470a56e40d03c59fd5fabe
-rw-r--r--tests/pagingtest/pagingtest.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/pagingtest/pagingtest.c b/tests/pagingtest/pagingtest.c
index 17a4ad4c..158d8a36 100644
--- a/tests/pagingtest/pagingtest.c
+++ b/tests/pagingtest/pagingtest.c
@@ -4,6 +4,7 @@
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
@@ -17,6 +18,8 @@
int create_tmp_file(char *filename, off_t size) {
void *buf;
+ uint8_t *tmp_buf;
+ off_t tmp_size;
ssize_t rc;
int fd;
int urandom;
@@ -49,17 +52,19 @@ int create_tmp_file(char *filename, off_t size) {
goto err_mmap;
}
- rc = read(urandom, buf, size);
+ tmp_buf = buf;
+ tmp_size = size;
+ do {
+ rc = read(urandom, tmp_buf, tmp_size);
- if (rc < 0) {
- fprintf(stderr, "write random data failed: %s\n", strerror(errno));
- goto err;
- }
+ if (rc < 0) {
+ fprintf(stderr, "write random data failed: %s\n", strerror(errno));
+ goto err;
+ }
- if (rc != size) {
- fprintf(stderr, "write random data incomplete: received %zd, expected %jd\n", rc, (intmax_t)size);
- goto err;
- }
+ tmp_buf += rc;
+ tmp_size -= rc;
+ } while (tmp_size > 0);
if (madvise(buf, size, MADV_DONTNEED)) {
fprintf(stderr, "madvise DONTNEED failed: %s\n", strerror(errno));