[Pixman] [PATCH 2/2] test: Add new thread-test program
Siarhei Siamashka
siarhei.siamashka at gmail.com
Sat Sep 28 16:46:53 PDT 2013
On Sat, 28 Sep 2013 11:38:58 -0400
Søren Sandmann <sandmann at cs.au.dk> wrote:
> From: Søren Sandmann Pedersen <ssp at redhat.com>
>
> This test program allocates an array of 16 uint32_ts and spawns 16
> threads that each use one of the allocated uint32_ts as destination
The 1x1 size for the destination image does not catch any problems
in the vmx code because the simd optimized parts are used only when
the width is at least 4 pixels.
> for a large number of composite operations. Each thread then checks
> whether the results have the right crc32 checksum.
>
> The purpose of this test is catch errors where memory outside images
> is read and then written back. Such out-of-bounds accesses are broken
> when multiple threads are involved.
Some changes are also needed to work in the same way on big endian
and little endian systems. I tweaked it in the following way to make
it run:
diff --git a/test/thread-test.c b/test/thread-test.c
index 917f417..8fc7d32 100644
--- a/test/thread-test.c
+++ b/test/thread-test.c
@@ -93,6 +93,15 @@ static const pixman_format_code_t formats[] =
#define RAND_ELT(arr) \
arr[prng_rand() % ARRAY_LENGTH (arr)]
+static inline uint32_t
+byteswap32 (uint32_t x)
+{
+ return ((x & ((uint32_t)0xFF << 24)) >> 24) |
+ ((x & ((uint32_t)0xFF << 16)) >> 8) |
+ ((x & ((uint32_t)0xFF << 8)) << 8) |
+ ((x & ((uint32_t)0xFF << 0)) << 24);
+}
+
static void *
thread (void *data)
{
@@ -106,7 +115,13 @@ thread (void *data)
for (i = 0; i < N_ROUNDS; ++i)
{
+ pixman_op_t op;
+ int rand1, rand2;
+#ifdef WORDS_BIGENDIAN
+ *info->dest = byteswap32 (prng_rand());
+#else
*info->dest = prng_rand();
+#endif
prng_randmemset (src_buf, sizeof (src_buf), 0);
@@ -115,10 +130,17 @@ thread (void *data)
dst_img = pixman_image_create_bits (
RAND_ELT (formats), 1, 1, info->dest, 4);
+ image_endian_swap (src_img);
+ image_endian_swap (dst_img);
+
+ rand2 = prng_rand() % 4;
+ rand1 = prng_rand() % 4;
+ op = RAND_ELT (operators);
+
pixman_image_composite32 (
- RAND_ELT (operators),
+ op,
src_img, NULL, dst_img,
- prng_rand() % 4, prng_rand() % 4, 0, 0, 0, 0, 1, 1);
+ rand1, rand2, 0, 0, 0, 0, 1, 1);
crc32 = compute_crc32_for_image (crc32, dst_img);
--
Best regards,
Siarhei Siamashka
More information about the Pixman
mailing list