summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-09-08 09:36:48 +0300
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-09-09 11:30:51 +0300
commite9ef2cc4dea04792a03d604c075c344055765217 (patch)
treedd3ab9c0bca46e82444a0e257335f79264f5625f
parent82f8c997dfd3f60a48134107ecf38663b464bdc9 (diff)
utils.[ch]: add fence_get_page_size()
Add a function to get the page size used for memory fence purposes, and use it everywhere where getpagesize() was used. This offers a single point in code to override the page size, in case one wants to experiment how the tests work with a higher page size than what the developer's machine has. This also offers a clean API, without adding #ifdefs, to tests for checking the page size. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com> Reviewed-by: Ben Avison <bavison@riscosopen.org>
-rw-r--r--test/utils.c21
-rw-r--r--test/utils.h4
2 files changed, 22 insertions, 3 deletions
diff --git a/test/utils.c b/test/utils.c
index 9089ffc..222d4d5 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -382,6 +382,15 @@ typedef struct
#if FENCE_MALLOC_ACTIVE
+unsigned long
+fence_get_page_size ()
+{
+ /* You can fake a page size here, if you want to test e.g. 64 kB
+ * pages on a 4 kB page system. Just put a multiplier below.
+ */
+ return getpagesize ();
+}
+
/* This is apparently necessary on at least OS X */
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
@@ -390,7 +399,7 @@ typedef struct
void *
fence_malloc (int64_t len)
{
- unsigned long page_size = getpagesize();
+ unsigned long page_size = fence_get_page_size ();
unsigned long page_mask = page_size - 1;
uint32_t n_payload_bytes = (len + page_mask) & ~page_mask;
uint32_t n_bytes =
@@ -439,7 +448,7 @@ fence_malloc (int64_t len)
void
fence_free (void *data)
{
- uint32_t page_size = getpagesize();
+ uint32_t page_size = fence_get_page_size ();
uint8_t *payload = data;
uint8_t *leading_protected = payload - N_LEADING_PROTECTED * page_size;
uint8_t *initial_page = leading_protected - page_size;
@@ -472,7 +481,7 @@ fence_image_create_bits (pixman_format_code_t format,
int height,
pixman_bool_t stride_fence)
{
- unsigned page_size = getpagesize();
+ unsigned page_size = fence_get_page_size ();
unsigned page_mask = page_size - 1;
unsigned bitspp = PIXMAN_FORMAT_BPP (format);
unsigned bits_boundary;
@@ -565,6 +574,12 @@ fence_image_create_bits (pixman_format_code_t format,
*/
}
+unsigned long
+fence_get_page_size ()
+{
+ return 0;
+}
+
#endif /* FENCE_MALLOC_ACTIVE */
uint8_t *
diff --git a/test/utils.h b/test/utils.h
index 5aae554..e299d1d 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -112,6 +112,10 @@ fence_image_create_bits (pixman_format_code_t format,
int height,
pixman_bool_t stride_fence);
+/* Return the page size if FENCE_MALLOC_ACTIVE, or zero otherwise */
+unsigned long
+fence_get_page_size ();
+
/* Generate n_bytes random bytes in fence_malloced memory */
uint8_t *
make_random_bytes (int n_bytes);