[Pixman] [PATCH] test: Fix fence-image-self-test on Mac

Pekka Paalanen ppaalanen at gmail.com
Tue Oct 13 02:39:39 PDT 2015


On Tue, 13 Oct 2015 11:07:53 +0200
Andrea Canciani <ranma42 at gmail.com> wrote:

> On MacOS X an out-of-bounds access to an mmap-ed region typically
> results in a SIGBUS, but fence-image-self-test was only accepting a
> SIGSEGV as notification of invalid access.

Hi,

out-of-bounds may be true, but in this case we use mprotect() achieve
the same. Up to you if you want to be more accurate in the message, IMO.


> Fixes fence-image-self-test
> ---
>  test/fence-image-self-test.c | 12 +++++++-----
>  test/utils.c                 |  6 +++---
>  2 files changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/test/fence-image-self-test.c b/test/fence-image-self-test.c
> index c883038..484c4ac 100644
> --- a/test/fence-image-self-test.c
> +++ b/test/fence-image-self-test.c
> @@ -73,7 +73,7 @@ prinfo (const char *fmt, ...)
>  }
>  
>  static void
> -do_expect_segv (void (*fn)(void *), void *data)
> +do_expect_signal (void (*fn)(void *), void *data)
>  {
>      struct sigaction sa;
>  
> @@ -82,6 +82,8 @@ do_expect_segv (void (*fn)(void *), void *data)
>      sa.sa_sigaction = segv_handler;
>      if (sigaction (SIGSEGV, &sa, NULL) == -1)
>          die ("sigaction failed", errno);
> +    if (sigaction (SIGBUS, &sa, NULL) == -1)
> +        die ("sigaction failed", errno);
>  
>      (*fn)(data);
>  
> @@ -96,7 +98,7 @@ do_expect_segv (void (*fn)(void *), void *data)
>   * to exit with success, and return failure otherwise.
>   */
>  static pixman_bool_t
> -expect_segv (void (*fn)(void *), void *data)
> +expect_signal (void (*fn)(void *), void *data)
>  {
>      pid_t pid, wp;
>      int status;
> @@ -106,7 +108,7 @@ expect_segv (void (*fn)(void *), void *data)
>          die ("fork failed", errno);
>  
>      if (pid == 0)
> -        do_expect_segv (fn, data); /* never returns */
> +        do_expect_signal (fn, data); /* never returns */
>  
>      wp = waitpid (pid, &status, 0);
>      if (wp != pid)
> @@ -131,9 +133,9 @@ test_read_fault (uint8_t *p, int offset)
>  {
>      prinfo ("*(uint8_t *)(%p + %d)", p, offset);
>  
> -    if (expect_segv (read_u8, p + offset))
> +    if (expect_signal (read_u8, p + offset))
>      {
> -        prinfo ("\tSEGV OK\n");
> +        prinfo ("\signal OK\n");

/home/pq/work/git/pixman/test/fence-image-self-test.c: In function ‘test_read_fault’:
/home/pq/work/git/pixman/test/fence-image-self-test.c:138:17: warning: unknown escape sequence: '\s' [enabled by default]


>          return TRUE;
>      }
> diff --git a/test/utils.c b/test/utils.c
> index 8657966..f8e42a5 100644
> --- a/test/utils.c
> +++ b/test/utils.c
> @@ -471,9 +471,9 @@ fence_image_destroy (pixman_image_t *image, void *data)
>   * min_width is only a minimum width for the image. The width is aligned up
>   * for the row size to be divisible by both page size and pixel size.
>   *
> - * If stride_fence is true, the additional page on each row will be armed
> - * to cause SIGSEVG on all accesses. This should catch all accesses outside
> - * the valid row pixels.
> + * If stride_fence is true, the additional page on each row will be
> + * armed to cause SIGSEGV or SIGBUS on all accesses. This should catch
> + * all accesses outside the valid row pixels.
>   */
>  pixman_image_t *
>  fence_image_create_bits (pixman_format_code_t format,

Tested to still work on x86_64.

With the compiler warning fixed to keep the "\t" correctly:
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/pixman/attachments/20151013/7121d837/attachment.sig>


More information about the Pixman mailing list