summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2012-01-22 20:09:54 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2012-01-22 20:09:54 +0100
commitfbfe374b280be9542f7ddb59c41c6096f4d773fa (patch)
tree19fddc5793417e9a2015c3a6cada4a42258c7e02 /lib
parent1a9fa8fd12c78236b1eb4a83062cd8f732c7abb3 (diff)
lib: extract drmtest_permute_array
Lots of tests need to create havoc to LRUs in the kernel or otherwise need to shuffle things around a bit. So make a small array permutation function available. Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib')
-rw-r--r--lib/drmtest.c16
-rw-r--r--lib/drmtest.h4
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 521a38a2..cc946411 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -332,6 +332,22 @@ void drmtest_stop_signal_helper(void)
signal_helper = -1;
}
+/* other helpers */
+void drmtest_permute_array(void *array, unsigned size,
+ void (*exchange_func)(void *array,
+ unsigned i,
+ unsigned j))
+{
+ int i;
+
+ for (i = size - 1; i > 1; i--) {
+ /* yes, not perfectly uniform, who cares */
+ long l = random() % (i +1);
+ if (i != l)
+ exchange_func(array, i, l);
+ }
+}
+
/* mappable aperture trasher helper */
drm_intel_bo **trash_bos;
int num_trash_bos;
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 3a3bc9aa..23d6f089 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -55,6 +55,10 @@ uint64_t gem_mappable_aperture_size(void);
/* generally useful helpers */
void drmtest_fork_signal_helper(void);
void drmtest_stop_signal_helper(void);
+void drmtest_permute_array(void *array, unsigned size,
+ void (*exchange_func)(void *array,
+ unsigned i,
+ unsigned j));
/* helpers based upon the libdrm buffer manager */
void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr);