summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@android.com>2016-05-17 10:10:18 -0700
committerRom Lemarchand <romlem@google.com>2016-05-17 10:10:18 -0700
commitf63f1206023881a8b14e5e14ea51c08b561dae78 (patch)
treed7671d77ac0161e609cfd7a055fe73ebcc5c03b3 /tests
parentba2475cd4d750288d24432ca51f3d62ec52bd9c1 (diff)
downloadextras-f63f1206023881a8b14e5e14ea51c08b561dae78.tar.gz
pagingtest: test both with prefetching enabled and disabled
Run the same tests with page cache prefetching both enabled and disabled. Change-Id: Ica253781a17fa0a66c07d0f5658c6c7d8b047a16
Diffstat (limited to 'tests')
-rw-r--r--tests/pagingtest/pageinout_test.c21
-rw-r--r--tests/pagingtest/pagingtest.c15
-rw-r--r--tests/pagingtest/pagingtest.h4
-rw-r--r--tests/pagingtest/thrashing_test.c18
4 files changed, 38 insertions, 20 deletions
diff --git a/tests/pagingtest/pageinout_test.c b/tests/pagingtest/pageinout_test.c
index eaa116c1..887794e7 100644
--- a/tests/pagingtest/pageinout_test.c
+++ b/tests/pagingtest/pageinout_test.c
@@ -1,5 +1,6 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,7 +9,7 @@
#include "pagingtest.h"
-int pageinout_test(int test_runs, unsigned long long file_size) {
+int pageinout_test(int test_runs, bool cache, unsigned long long file_size) {
int fd;
char tmpname[] = "pageinoutXXXXXX";
unsigned char *vec;
@@ -43,11 +44,13 @@ int pageinout_test(int test_runs, unsigned long long file_size) {
goto err;
}
- //madvise and fadvise as random to prevent prefetching
- rc = madvise((void *)buf, file_size, MADV_RANDOM) ||
- posix_fadvise(fd, 0, file_size, POSIX_FADV_RANDOM);
- if (rc) {
- goto err;
+ if (!cache) {
+ //madvise and fadvise as random to prevent prefetching
+ rc = madvise((void *)buf, file_size, MADV_RANDOM) ||
+ posix_fadvise(fd, 0, file_size, POSIX_FADV_RANDOM);
+ if (rc) {
+ goto err;
+ }
}
for (i = 0; i < test_runs; i++) {
@@ -82,9 +85,11 @@ int pageinout_test(int test_runs, unsigned long long file_size) {
}
}
- printf("page-in: %llu MB/s\n", (file_size * test_runs * USEC_PER_SEC) /
+ printf("%scached page-in: %llu MB/s\n", cache ? "" : "un",
+ (file_size * test_runs * USEC_PER_SEC) /
(1024 * 1024 * (total_time_in.tv_sec * USEC_PER_SEC + total_time_in.tv_usec)));
- printf("page-out (clean): %llu MB/s\n", (file_size * test_runs * USEC_PER_SEC) /
+ printf("%scached page-out (clean): %llu MB/s\n", cache ? "" : "un",
+ (file_size * test_runs * USEC_PER_SEC) /
(1024 * 1024 * (total_time_out.tv_sec * USEC_PER_SEC + total_time_out.tv_usec)));
ret = 0;
diff --git a/tests/pagingtest/pagingtest.c b/tests/pagingtest/pagingtest.c
index db8512c1..17a4ad4c 100644
--- a/tests/pagingtest/pagingtest.c
+++ b/tests/pagingtest/pagingtest.c
@@ -2,6 +2,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -56,7 +57,7 @@ int create_tmp_file(char *filename, off_t size) {
}
if (rc != size) {
- fprintf(stderr, "write random data incomplete\n");
+ fprintf(stderr, "write random data incomplete: received %zd, expected %jd\n", rc, (intmax_t)size);
goto err;
}
@@ -161,11 +162,19 @@ int main(int argc, char **argv) {
if (rc) {
return rc;
}
- rc = pageinout_test(test_runs, file_size);
+ rc = pageinout_test(test_runs, true, file_size);
if (rc) {
return rc;
}
- rc = thrashing_test(test_runs);
+ rc = pageinout_test(test_runs, false, file_size);
+ if (rc) {
+ return rc;
+ }
+ rc = thrashing_test(test_runs, true);
+ if (rc) {
+ return rc;
+ }
+ rc = thrashing_test(test_runs, false);
return rc;
}
diff --git a/tests/pagingtest/pagingtest.h b/tests/pagingtest/pagingtest.h
index 2da9818c..a6f3d03f 100644
--- a/tests/pagingtest/pagingtest.h
+++ b/tests/pagingtest/pagingtest.h
@@ -14,7 +14,7 @@ bool check_caching(void *buf, unsigned char *vec, size_t size, bool is_cached);
//Tests
int mmap_test(int test_runs, unsigned long long alloc_size);
-int pageinout_test(int test_runs, unsigned long long file_size);
-int thrashing_test(int test_runs);
+int pageinout_test(int test_runs, bool cache, unsigned long long file_size);
+int thrashing_test(int test_runs, bool cache);
#endif //__PAGINGTEST_H__
diff --git a/tests/pagingtest/thrashing_test.c b/tests/pagingtest/thrashing_test.c
index b0193d85..0f4547fe 100644
--- a/tests/pagingtest/thrashing_test.c
+++ b/tests/pagingtest/thrashing_test.c
@@ -1,5 +1,6 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -10,7 +11,7 @@
#define LINESIZE 32
-int thrashing_test(int test_runs) {
+int thrashing_test(int test_runs, bool cache) {
int fds[4] = {-1, -1, -1, -1};
char tmpnames[4][17] = { "thrashing1XXXXXX", "thrashing2XXXXXX", "thrashing3XXXXXX", "thrashing4XXXXXX" };
volatile char *bufs[4] = {0};
@@ -45,11 +46,13 @@ int thrashing_test(int test_runs) {
fprintf(stderr, "Failed to mmap file: %s\n", strerror(errno));
goto err;
}
- //madvise and fadvise as random to prevent prefetching
- ret = madvise((void *)bufs[i], filesize, MADV_RANDOM) ||
- posix_fadvise(fds[i], 0, filesize, POSIX_FADV_RANDOM);
- if (ret) {
- goto err;
+ if (!cache) {
+ //madvise and fadvise as random to prevent prefetching
+ ret = madvise((void *)bufs[i], filesize, MADV_RANDOM) ||
+ posix_fadvise(fds[i], 0, filesize, POSIX_FADV_RANDOM);
+ if (ret) {
+ goto err;
+ }
}
}
@@ -66,7 +69,8 @@ int thrashing_test(int test_runs) {
}
}
- printf("thrashing: %llu MB/s\n", (filesize * ARRAY_SIZE(fds) * test_runs * USEC_PER_SEC) /
+ printf("%scached thrashing: %llu MB/s\n", cache ? "" : "un",
+ (filesize * ARRAY_SIZE(fds) * test_runs * USEC_PER_SEC) /
(1024 * 1024 * (total_time.tv_sec * USEC_PER_SEC + total_time.tv_usec)));
ret = 0;