This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 62ad65536ccbc9b75e09fd80591572ebdbe509a4 (commit) via d0202e863397c4427f5bb8163de13764e98dcb31 (commit) via 24824d445743e205a9afb6a218c93a5bc4a883c0 (commit) from 98c0bddd4c211b197d0186f2fcb7db48d3a46ace (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/62ad65536ccbc9b75e09fd80591572ebdbe50...
commit 62ad65536ccbc9b75e09fd80591572ebdbe509a4 Author: Cyril Hrubis metan@ucw.cz Date: Fri Nov 15 00:30:43 2013 +0100
tests: core: Add BlitClipped() tests.
Add a few basic BlitClipped tests + regression test for a off by one bug I've found today. (fix is on the way)
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/core/BlitClipped.c b/tests/core/BlitClipped.c new file mode 100644 index 0000000..3f0ba65 --- /dev/null +++ b/tests/core/BlitClipped.c @@ -0,0 +1,237 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +/* + + Clipped Blit tests. + + */ +#include <errno.h> + +#include <core/GP_Context.h> +#include <core/GP_Blit.h> + +#include "tst_test.h" +#include "tst_preload.h" + +struct clipped_test { + /* size of the contexes */ + GP_Size src_w, src_h; + GP_Size dst_w, dst_h; + + /* Source rectangle */ + GP_Coord x0, y0; + GP_Size w0, h0; + + /* Destination offset */ + GP_Coord x1, y1; +}; + +static int clipped_test(struct clipped_test *test) +{ + GP_Context *src, *dst; + + src = GP_ContextAlloc(test->src_w, test->src_h, GP_PIXEL_RGB888); + dst = GP_ContextAlloc(test->dst_w, test->dst_h, GP_PIXEL_RGB888); + + if (!src || !dst) { + tst_msg("GP_ContextAlloc() failed"); + return TST_UNTESTED; + } + + GP_BlitXYWH_Clipped(src, test->x0, test->y0, test->w0, test->h0, + dst, test->x1, test->y1); + + GP_ContextFree(src); + GP_ContextFree(dst); + + return TST_SUCCESS; +} + +static int clipped_test_canaries(struct clipped_test *test) +{ + int ret; + + tst_malloc_canaries_set(MALLOC_CANARY_BEGIN); + ret = clipped_test(test); + + tst_malloc_canaries_set(MALLOC_CANARY_END); + ret |= clipped_test(test); + + tst_malloc_canaries_set(MALLOC_CANARY_OFF); + + return ret; +} + +static struct clipped_test off_by_one_1 = { + .src_w = 100, + .src_h = 100, + + .dst_w = 100, + .dst_h = 100, + + .x0 = 0, + .y0 = 0, + .w0 = 100, + .h0 = 100, + + .x1 = 1, + .y1 = 1, +}; + +static struct clipped_test off_by_one_2 = { + .src_w = 100, + .src_h = 100, + + .dst_w = 100, + .dst_h = 100, + + .x0 = 0, + .y0 = 0, + .w0 = 100, + .h0 = 100, + + .x1 = 1, + .y1 = 0, +}; + +static struct clipped_test off_by_one_3 = { + .src_w = 100, + .src_h = 100, + + .dst_w = 100, + .dst_h = 100, + + .x0 = 0, + .y0 = 0, + .w0 = 100, + .h0 = 100, + + .x1 = 0, + .y1 = 1, +}; + +static struct clipped_test empty_src = { + .src_w = 100, + .src_h = 100, + + .dst_w = 200, + .dst_h = 200, + + .x0 = 0, + .y0 = 0, + .w0 = 0, + .h0 = 0, + + .x1 = 0, + .y1 = 0, +}; + +static struct clipped_test out_of_dst_1 = { + .src_w = 100, + .src_h = 100, + + .dst_w = 200, + .dst_h = 200, + + .x0 = 0, + .y0 = 0, + .w0 = 100, + .h0 = 100, + + .x1 = 200, + .y1 = 0, +}; + +static struct clipped_test out_of_dst_2 = { + .src_w = 100, + .src_h = 100, + + .dst_w = 200, + .dst_h = 200, + + .x0 = 0, + .y0 = 0, + .w0 = 100, + .h0 = 100, + + .x1 = 0, + .y1 = 200, +}; + +static struct clipped_test src_rect_out_of_src = { + .src_w = 100, + .src_h = 100, + + .dst_w = 200, + .dst_h = 200, + + .x0 = -100, + .y0 = -100, + .w0 = 200, + .h0 = 200, + + .x1 = 0, + .y1 = 0, +}; + +const struct tst_suite tst_suite = { + .suite_name = "Blit Clipped Testsuite", + .tests = { + {.name = "Empty src", + .tst_fn = clipped_test_canaries, + .data = &empty_src, + .flags = TST_CHECK_MALLOC}, + + {.name = "Out of dst 1", + .tst_fn = clipped_test_canaries, + .data = &out_of_dst_1, + .flags = TST_CHECK_MALLOC}, + + {.name = "Out of dst 2", + .tst_fn = clipped_test_canaries, + .data = &out_of_dst_2, + .flags = TST_CHECK_MALLOC}, + + {.name = "Src rect out of src", + .tst_fn = clipped_test_canaries, + .data = &src_rect_out_of_src, + .flags = TST_CHECK_MALLOC}, + + {.name = "Regression off by one 1", + .tst_fn = clipped_test_canaries, + .data = &off_by_one_1, + .flags = TST_CHECK_MALLOC}, + + {.name = "Regression off by one 2", + .tst_fn = clipped_test_canaries, + .data = &off_by_one_2, + .flags = TST_CHECK_MALLOC}, + + {.name = "Regression off by one 3", + .tst_fn = clipped_test_canaries, + .data = &off_by_one_3, + .flags = TST_CHECK_MALLOC}, + + {.name = NULL}, + } +}; diff --git a/tests/core/Makefile b/tests/core/Makefile index 3568fd0..9ede6dc 100644 --- a/tests/core/Makefile +++ b/tests/core/Makefile @@ -2,13 +2,13 @@ TOPDIR=../..
include $(TOPDIR)/pre.mk
-CSOURCES=Context.c Pixel.c +CSOURCES=Context.c Pixel.c BlitClipped.c
GENSOURCES+=WritePixel.gen.c GetPutPixel.gen.c Convert.gen.c BlitConv.gen.c Convert_Scale.gen.c GetSetBits.gen.c
APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen - Convert_Scale.gen GetSetBits.gen + Convert_Scale.gen GetSetBits.gen BlitClipped
include ../tests.mk
diff --git a/tests/core/test_list.txt b/tests/core/test_list.txt index 5fbaeba..c728b8b 100644 --- a/tests/core/test_list.txt +++ b/tests/core/test_list.txt @@ -7,3 +7,4 @@ GetPutPixel.gen Convert.gen Convert_Scale.gen BlitConv.gen +BlitClipped
http://repo.or.cz/w/gfxprim.git/commit/d0202e863397c4427f5bb8163de13764e98dc...
commit d0202e863397c4427f5bb8163de13764e98dcb31 Author: Cyril Hrubis metan@ucw.cz Date: Thu Nov 14 23:32:15 2013 +0100
tests: framework: Finish and rename malloc barriers
Rename malloc barriers to malloc canaries and plug them into the malloc tracking code, so that they could be enabled for all malloc() calls.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/framework/Makefile b/tests/framework/Makefile index f7ceb2e..15cd84a 100644 --- a/tests/framework/Makefile +++ b/tests/framework/Makefile @@ -14,7 +14,7 @@ APPS=test
ALL+=libtst_preload.so libtst.a
-libtst_preload.so: tst_preload.o tst_alloc_barriers.o tst_preload_FILE.o +libtst_preload.so: tst_preload.o tst_malloc_canaries.o tst_preload_FILE.o $(CC) -Wl,-soname -Wl,tst_preload.so --shared -ldl -fPIC $^ -o $@
libtst.a: tst_suite.o tst_job.o tst_msg.o tst_log.o tst_main.o tst_timespec.o diff --git a/tests/framework/test.c b/tests/framework/test.c index db42323..3fbbc8d 100644 --- a/tests/framework/test.c +++ b/tests/framework/test.c @@ -27,7 +27,7 @@ #include <string.h>
#include "tst_test.h" -#include "tst_alloc_barriers.h" +#include "tst_malloc_canaries.h" #include "tst_preload_FILE.h"
int success_fn(void) @@ -120,9 +120,9 @@ int double_free(void) return TST_SUCCESS; }
-int barrier_allocation(void) +int canary_allocation(void) { - char *buf = tst_alloc_barrier_right(31); + char *buf = tst_malloc_canary_right(31);
int i;
@@ -262,7 +262,7 @@ const struct tst_suite tst_suite = { {.name = "Mem Leak test", .tst_fn = malloc_leak_fn, .flags = TST_CHECK_MALLOC}, {.name = "Mem Ok test", .tst_fn = malloc_ok_fn, .flags = TST_CHECK_MALLOC}, {.name = "Double free()", .tst_fn = double_free}, - {.name = "Barrier allocation", .tst_fn = barrier_allocation}, + {.name = "Canary allocation", .tst_fn = canary_allocation}, {.name = "Failed FILE", .tst_fn = fail_FILE, .flags = TST_TMPDIR}, {.name = "Resource", .tst_fn = res_fn, .flags = TST_TMPDIR, .res_path = "test.c"}, diff --git a/tests/framework/tst_alloc_barriers.c b/tests/framework/tst_malloc_canaries.c similarity index 91% rename from tests/framework/tst_alloc_barriers.c rename to tests/framework/tst_malloc_canaries.c index 567e462..40f16c9 100644 --- a/tests/framework/tst_alloc_barriers.c +++ b/tests/framework/tst_malloc_canaries.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -25,9 +25,9 @@ #include <stdlib.h> #include <unistd.h>
-#include "tst_alloc_barriers.h" +#include "tst_malloc_canaries.h"
-void *tst_alloc_barrier_right(size_t size) +void *tst_malloc_canary_right(size_t size) { size_t pagesize = sysconf(_SC_PAGESIZE); size_t pages = size/pagesize + !!(size%pagesize) + 1; @@ -50,7 +50,7 @@ void *tst_alloc_barrier_right(size_t size) return buf + (pagesize - size%pagesize); }
-void tst_free_barrier_right(void *ptr, size_t size) +void tst_free_canary_right(void *ptr, size_t size) { size_t pagesize = sysconf(_SC_PAGESIZE); size_t pages = size/pagesize + !!(size%pagesize); @@ -64,7 +64,7 @@ void tst_free_barrier_right(void *ptr, size_t size) free(start); }
-void *tst_alloc_barrier_left(size_t size) +void *tst_malloc_canary_left(size_t size) { size_t pagesize = sysconf(_SC_PAGESIZE); size_t pages = size/pagesize + !!(size%pagesize) + 1; @@ -87,7 +87,7 @@ void *tst_alloc_barrier_left(size_t size) return buf + pagesize; }
-void tst_free_barrier_left(void *ptr, size_t size __attribute__((unused))) +void tst_free_canary_left(void *ptr, size_t size __attribute__((unused))) { size_t pagesize = sysconf(_SC_PAGESIZE); void *start = ptr - pagesize; diff --git a/tests/framework/tst_alloc_barriers.h b/tests/framework/tst_malloc_canaries.h similarity index 78% rename from tests/framework/tst_alloc_barriers.h rename to tests/framework/tst_malloc_canaries.h index dc6b12d..ca07190 100644 --- a/tests/framework/tst_alloc_barriers.h +++ b/tests/framework/tst_malloc_canaries.h @@ -16,45 +16,45 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
/*
- This code could create a buffer with either left or right barrier. Barrier is + This code could create a buffer with either left or right canary. Canary is a page that exists right before respectively right after the buffer and is set to PROT_NONE (reading or writing at adresses in such page causes Segmentation Fault).
*/
-#ifndef TST_ALLOC_BARRIERS_H -#define TST_ALLOC_BARRIERS_H +#ifndef TST_ALLOC_CANARY_H +#define TST_ALLOC_CANARY_H
/* - * Allocate memory with a barrier page at the right side of the buffer + * Allocate memory with a canary page at the right side of the buffer * (right == higher addresses). * * Returns NULL in case allocation or mprotect has failed. */ -void *tst_alloc_barrier_right(size_t size); +void *tst_malloc_canary_right(size_t size);
/* * Free allocated buffer. */ -void tst_free_barrier_right(void *ptr, size_t size); +void tst_free_canary_right(void *ptr, size_t size);
/* - * Allocate memory with barrier page at the left side of the buffer. + * Allocate memory with canary page at the left side of the buffer. * * Returns NULL in case allocation or mprotect has failed. */ -void *tst_alloc_barrier_left(size_t size); +void *tst_malloc_canary_left(size_t size);
/* * Free allocated buffer. */ -void tst_free_barrier_left(void *ptr, size_t size); +void tst_free_canary_left(void *ptr, size_t size);
-#endif /* TST_ALLOC_BARRIERS_H */ +#endif /* TST_ALLOC_CANARY_H */ diff --git a/tests/framework/tst_preload.c b/tests/framework/tst_preload.c index 9205a66..9436c2c 100644 --- a/tests/framework/tst_preload.c +++ b/tests/framework/tst_preload.c @@ -16,19 +16,30 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#define _GNU_SOURCE #include <stdio.h> #include <stdint.h> +#include <string.h> #include <dlfcn.h>
#include "tst_test.h" #include "tst_preload.h" +#include "tst_malloc_canaries.h"
static int check_malloc = 0; +static int malloc_canary = MALLOC_CANARY_OFF; + +static size_t cur_size = 0; +static unsigned int cur_chunks = 0; +static size_t total_size = 0; +static unsigned int total_chunks = 0; +/* Maximal allocated size at a time */ +static size_t max_size = 0; +static unsigned int max_chunks = 0;
void tst_malloc_check_start(void) { @@ -37,16 +48,35 @@ void tst_malloc_check_start(void)
void tst_malloc_check_stop(void) { + /* + * We cannot stop the tracing when canaries are on + * because we need the chunk table to keep track + * which allocations are with canary and their + * sizes for free and realloc. + */ + if (malloc_canary != MALLOC_CANARY_OFF) { + tst_warn("Cannot turn malloc checks off when canaries are on"); + return; + } + check_malloc = 0; }
-static size_t cur_size = 0; -static unsigned int cur_chunks = 0; -static size_t total_size = 0; -static unsigned int total_chunks = 0; -/* Maximal allocated size at a time */ -static size_t max_size = 0; -static unsigned int max_chunks = 0; +void tst_malloc_canaries_set(enum tst_malloc_canary canary) +{ + if (!check_malloc) { + tst_warn("Cannot turn canaries on when checking is off"); + return; + } + + if (canary > MALLOC_CANARY_END) { + tst_warn("Invalid canary type"); + return; + } + + malloc_canary = canary; +} +
void tst_malloc_check_report(struct malloc_stats *stats) { @@ -65,6 +95,7 @@ void tst_malloc_check_report(struct malloc_stats *stats) struct chunk { void *ptr; size_t size; + enum tst_malloc_canary canary; int cont; };
@@ -82,6 +113,7 @@ static void add_chunk(size_t size, void *ptr) /* Store chunk */ chunks[chunks_top].size = size; chunks[chunks_top].ptr = ptr; + chunks[chunks_top].canary = malloc_canary; chunks_top++;
/* Update global stats */ @@ -117,14 +149,40 @@ static void rem_chunk(void *ptr) tst_warn("Chunk passed to free not found (%p)", ptr); }
+static struct chunk *get_chunk(void *ptr) +{ + unsigned int i; + + for (i = 0; i < chunks_top; i++) { + if (chunks[i].ptr == ptr) + return &chunks[i]; + } + + return NULL; +} + void *malloc(size_t size) { static void *(*real_malloc)(size_t) = NULL; + void *ptr;
if (!real_malloc) real_malloc = dlsym(RTLD_NEXT, "malloc");
- void *ptr = real_malloc(size); + switch (malloc_canary) { + case MALLOC_CANARY_OFF: + ptr = real_malloc(size); + break; + case MALLOC_CANARY_BEGIN: + ptr = tst_malloc_canary_left(size); + break; + case MALLOC_CANARY_END: + ptr = tst_malloc_canary_right(size); + break; + /* Shut up gcc */ + default: + return NULL; + }
if (check_malloc && ptr) add_chunk(size, ptr); @@ -132,15 +190,81 @@ void *malloc(size_t size) return ptr; }
+void free(void *ptr) +{ + static void (*real_free)(void *) = NULL; + struct chunk *chunk; + + if (!real_free) + real_free = dlsym(RTLD_NEXT, "free"); + + if (!ptr) + return; + + chunk = get_chunk(ptr); + + /* Was allocated before malloc checking was turned on */ + if (!chunk) { + real_free(ptr); + return; + } + + switch (chunk->canary) { + case MALLOC_CANARY_OFF: + real_free(ptr); + break; + case MALLOC_CANARY_BEGIN: + tst_free_canary_left(ptr, chunk->size); + break; + case MALLOC_CANARY_END: + tst_free_canary_right(ptr, chunk->size); + break; + } + + rem_chunk(ptr); +} + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + void *realloc(void *optr, size_t size) { static void *(*real_realloc)(void*, size_t) = NULL; + struct chunk *chunk; + void *ptr;
if (!real_realloc) real_realloc = dlsym(RTLD_NEXT, "realloc");
- void *ptr = real_realloc(optr, size); + switch (malloc_canary) { + case MALLOC_CANARY_OFF: + ptr = real_realloc(optr, size); + break; + case MALLOC_CANARY_BEGIN: + case MALLOC_CANARY_END: + chunk = get_chunk(optr);
+ if (!chunk) { + tst_warn("%p allocated before checking was turned on, " + "using using real_realloc()", optr); + + ptr = real_realloc(optr, size); + + goto out; + } + + ptr = malloc(size); + + if (ptr) { + memcpy(ptr, optr, min(chunk->size, size)); + free(optr); + } + break; + /* Shut up gcc */ + default: + return NULL; + } + +out: if (!ptr) return NULL;
@@ -153,19 +277,6 @@ void *realloc(void *optr, size_t size) return ptr; }
-void free(void *ptr) -{ - static void (*real_free)(void *) = NULL; - - if (!real_free) - real_free = dlsym(RTLD_NEXT, "free"); - - if (check_malloc && ptr != NULL) - rem_chunk(ptr); - - real_free(ptr); -} - void tst_malloc_print(const struct malloc_stats *stats) { fprintf(stderr, "Total size %zu chunks %u, lost size %zu chunks %un", diff --git a/tests/framework/tst_preload.h b/tests/framework/tst_preload.h index 0c44d3d..b4922c4 100644 --- a/tests/framework/tst_preload.h +++ b/tests/framework/tst_preload.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -33,6 +33,25 @@ void tst_malloc_check_start(void); */ void tst_malloc_check_stop(void);
+enum tst_malloc_canary { + MALLOC_CANARY_OFF, + /* canary before the chunk */ + MALLOC_CANARY_BEGIN, + /* canary after the chunk */ + MALLOC_CANARY_END, +}; + +/* + * Turns on malloc canaries. + * + * If turned on each malloc gets a canary (a page with both read and write + * turned off) allocated at the end or at the start of the allocated chunk. + * + * Canaries cannot be turned on when malloc checking is off, and malloc checking + * cannot be turned off when canaries are turned on. + */ +void tst_malloc_canaries_set(enum tst_malloc_canary canary); + struct malloc_stats { /* * Sum of all alocated chunks.
http://repo.or.cz/w/gfxprim.git/commit/24824d445743e205a9afb6a218c93a5bc4a88...
commit 24824d445743e205a9afb6a218c93a5bc4a883c0 Author: Cyril Hrubis metan@ucw.cz Date: Thu Nov 14 19:39:27 2013 +0100
backends: X11: Fix memleak.
Free the array of supported _NET_WM Atoms.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/backends/GP_X11_Conn.h b/libs/backends/GP_X11_Conn.h index 3bbd683..4c5d732 100644 --- a/libs/backends/GP_X11_Conn.h +++ b/libs/backends/GP_X11_Conn.h @@ -89,6 +89,8 @@ static void x11_detect_wm_features(void)
for (i = 0; i < count; i++) x11_check_atoms(args[i]); + + XFree(args); } }
-----------------------------------------------------------------------
Summary of changes: libs/backends/GP_X11_Conn.h | 2 + tests/core/BlitClipped.c | 237 ++++++++++++++++++++ tests/core/Makefile | 4 +- tests/core/test_list.txt | 1 + tests/framework/Makefile | 2 +- tests/framework/test.c | 8 +- ...{tst_alloc_barriers.c => tst_malloc_canaries.c} | 12 +- ...{tst_alloc_barriers.h => tst_malloc_canaries.h} | 22 +- tests/framework/tst_preload.c | 157 +++++++++++-- tests/framework/tst_preload.h | 21 ++- 10 files changed, 418 insertions(+), 48 deletions(-) create mode 100644 tests/core/BlitClipped.c rename tests/framework/{tst_alloc_barriers.c => tst_malloc_canaries.c} (91%) rename tests/framework/{tst_alloc_barriers.h => tst_malloc_canaries.h} (78%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.