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 2d7e9bb328d9e81fed96350d419f367b3fb01961 (commit) via 7402c552f2c82fd3574b90cd95e720e2865fc8b6 (commit) via 7b51e7842889c3eb0ecf06dc9586d1acb4bfbce6 (commit) from 14e8e751a6d78a0376951b09eff2a51c577d96ea (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/2d7e9bb328d9e81fed96350d419f367b3fb01...
commit 2d7e9bb328d9e81fed96350d419f367b3fb01961 Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 22 19:23:51 2012 +0200
tests: Add JSON output.
diff --git a/tests/framework/tst_log.c b/tests/framework/tst_log.c index cc063e4..57234e3 100644 --- a/tests/framework/tst_log.c +++ b/tests/framework/tst_log.c @@ -20,6 +20,9 @@ * * *****************************************************************************/
+#include <sys/utsname.h> +#include <stdio.h> + #include "tst_test.h" #include "tst_job.h" #include "tst_msg.h" @@ -169,12 +172,84 @@ static int append_html(struct tst_job *job, FILE *f) return 0; }
+static int append_msg_json(struct tst_job *job, FILE *f) +{ + struct tst_msg *msg; + + fprintf(f, "ttt"Test Reports": [n"); + + for (msg = job->store.first; msg != NULL; msg = msg->next) { + fprintf(f, "tttt"%s"", msg->msg); + + if (msg->next != NULL) + fprintf(f, ",n"); + } + + fprintf(f, "nttt],n"); + + return 0; +} + +static int append_malloc_stats_json(struct tst_job *job, FILE *f) +{ + fprintf(f, "ttt"Malloc Stats": {n"); + fprintf(f, "tttt"Total Size": %zi,n", + job->malloc_stats.total_size); + fprintf(f, "tttt"Total Chunks": %u,n", + job->malloc_stats.total_chunks); + fprintf(f, "tttt"Lost Size": %zi,n", + job->malloc_stats.lost_size); + fprintf(f, "tttt"Lost Chunks": %un", + job->malloc_stats.lost_chunks); + fprintf(f, "ttt},n"); + + return 0; +} + +static int hack_json_start = 0; + +static int append_json(struct tst_job *job, FILE *f) +{ + if (hack_json_start) + hack_json_start = 0; + else + fprintf(f, ",n"); + + fprintf(f, "tt{n"); + fprintf(f, "ttt"Test Name": "%s",n", job->test->name); + fprintf(f, "ttt"Test Result": "%s",n", ret_to_str(job->result)); + + /* Append any test reports */ + append_msg_json(job, f); + + /* If calculated include malloc report */ + if (job->test->flags & TST_MALLOC_CHECK) + append_malloc_stats_json(job, f); + + /* Time statistics */ + int sec, nsec; + + tst_diff_timespec(&sec, &nsec, &job->start_time, &job->stop_time); + + fprintf(f, "ttt"CPU Time": %i.%09i,n", + (int)job->cpu_time.tv_sec, (int)job->cpu_time.tv_nsec); + + fprintf(f, "ttt"Run Time": %i.%09in", sec, nsec); + + fprintf(f, "tt}"); + + return 0; +} + int tst_log_append(struct tst_job *job, FILE *f, enum tst_log_fmt format) { switch (format) { case TST_LOG_HTML: return append_html(job, f); break; + case TST_LOG_JSON: + return append_json(job, f); + break; default: return 1; } @@ -205,6 +280,61 @@ FILE *open_html(const struct tst_suite *suite, const char *path) return f; }
+static void write_system_info_json(FILE *f) +{ + struct utsname buf; + + uname(&buf); + + fprintf(f, "t"System Info": {n"); + + fprintf(f, "tt"OS": "%s",n", buf.sysname); + fprintf(f, "tt"Hostname": "%s",n", buf.nodename); + fprintf(f, "tt"Release": "%s",n", buf.release); + + /* CPU related info */ + fprintf(f, "tt"CPU": {"); + + /* lscpu is part of reasonably new util-linux */ + FILE *cmd = popen("lscpu", "r"); + + if (cmd != NULL) { + char id[256], val[1024]; + char *del = "n"; + + while (fscanf(cmd, "%[^:]%*c %[^n]n", id, val) == 2) { + fprintf(f, "%sttt"%s": "%s"", del, id, val); + del = ",n"; + } + + fclose(cmd); + fprintf(f, "n"); + } + + fprintf(f, "tt}n"); + + fprintf(f, "t},n"); +} + +FILE *open_json(const struct tst_suite *suite, const char *path) +{ + FILE *f; + + f = fopen(path, "w"); + + if (f == NULL) + return NULL; + + fprintf(f, "{n"); + fprintf(f, "t"Suite Name": "%s",n", suite->suite_name); + write_system_info_json(f); + fprintf(f, "t"Test Results": [n"); + + hack_json_start = 1; + + return f; +} + FILE *tst_log_open(const struct tst_suite *suite, const char *path, enum tst_log_fmt format) { @@ -212,6 +342,9 @@ FILE *tst_log_open(const struct tst_suite *suite, const char *path, case TST_LOG_HTML: return open_html(suite, path); break; + case TST_LOG_JSON: + return open_json(suite, path); + break; default: return NULL; } @@ -222,8 +355,13 @@ FILE *tst_log_open(const struct tst_suite *suite, const char *path, static int close_html(FILE *f) { fprintf(f, " </table>n </body>n</html>n"); - fclose(f); - return 0; + return fclose(f); +} + +static int close_json(FILE *f) +{ + fprintf(f, "nt]n}n"); + return fclose(f); }
int tst_log_close(FILE *f, enum tst_log_fmt format) @@ -232,6 +370,9 @@ int tst_log_close(FILE *f, enum tst_log_fmt format) case TST_LOG_HTML: return close_html(f); break; + case TST_LOG_JSON: + return close_json(f); + break; default: return 1; } diff --git a/tests/framework/tst_test.c b/tests/framework/tst_test.c index f45a582..2cc94a5 100644 --- a/tests/framework/tst_test.c +++ b/tests/framework/tst_test.c @@ -43,8 +43,7 @@ int tst_warn(const char *fmt, ...) return ret; } -static int run_test(const struct tst_test *test, FILE *f, - enum tst_log_fmt format) +static int run_test(const struct tst_test *test, FILE *html, FILE *json) { struct tst_job job;
@@ -56,12 +55,14 @@ static int run_test(const struct tst_test *test, FILE *f, * child and parent and the lines in the resulting * file would be repeated several times. */ - fflush(f); + fflush(html); + fflush(json);
tst_job_run(&job); tst_job_wait(&job);
- tst_log_append(&job, f, format); + tst_log_append(&job, html, TST_LOG_HTML); + tst_log_append(&job, json, TST_LOG_JSON);
/* Free the test message store */ tst_msg_clear(&job.store); @@ -79,17 +80,19 @@ void tst_run_suite(const struct tst_suite *suite, const char *tst_name) fprintf(stderr, "Running e[1;37m%se[0mnn", suite->suite_name);
//TODO: - FILE *f = tst_log_open(suite, "log.html", TST_LOG_HTML); + FILE *html = tst_log_open(suite, "log.html", TST_LOG_HTML); + FILE *json = tst_log_open(suite, "log.json", TST_LOG_JSON);
for (i = 0; suite->tests[i].name != NULL; i++) { if (tst_name == NULL || !strcmp(tst_name, suite->tests[i].name)) { - ret = run_test(&suite->tests[i], f, TST_LOG_HTML); + ret = run_test(&suite->tests[i], html, json); counters[ret]++; counter++; } }
- tst_log_close(f, TST_LOG_HTML); + tst_log_close(html, TST_LOG_HTML); + tst_log_close(json, TST_LOG_JSON);
fprintf(stderr, "nSummary: succedded %u out of %u (%.2f%%)n", counters[0], counter, 100.00 * counters[0] / counter);
http://repo.or.cz/w/gfxprim.git/commit/7402c552f2c82fd3574b90cd95e720e2865fc...
commit 7402c552f2c82fd3574b90cd95e720e2865fc8b6 Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 22 16:08:20 2012 +0200
tests: Simplify malloc tracing logick.
diff --git a/tests/framework/test.c b/tests/framework/test.c index f460139..0c908f5 100644 --- a/tests/framework/test.c +++ b/tests/framework/test.c @@ -72,12 +72,16 @@ int temp_dir_fn(void)
int malloc_leak_fn(void) { - void *p; - + void *p, *q, *r; + + q = malloc(100); p = malloc(4); p = malloc(3); + r = malloc(20);
free(p); + free(q); + free(r);
tst_report(0, "Leaking 1 chunks 4 bytes total");
@@ -86,10 +90,19 @@ int malloc_leak_fn(void)
int malloc_ok_fn(void) { - void *p; + unsigned int perm[20] = { + 1, 3, 2, 6, 4, 5, 0, 9, 8, 14, + 7, 11, 13, 10, 12, 19, 17, 16, 15, 18, + };
- p = malloc(100); - free(p); + unsigned int i; + void *p[20]; + + for (i = 0; i < 20; i++) + p[i] = malloc((7 * i) % 127); + + for (i = 0; i < 20; i++) + free(p[perm[i]]);
return TST_SUCCESS; } diff --git a/tests/framework/tst_preload.c b/tests/framework/tst_preload.c index 1ba320e..86927aa 100644 --- a/tests/framework/tst_preload.c +++ b/tests/framework/tst_preload.c @@ -40,20 +40,12 @@ void tst_malloc_check_stop(void) check_malloc = 0; }
-#define MAX_CHUNKS 100 - -struct chunk { - void *ptr; - size_t size; - int cont; -}; - -struct chunk chunks[MAX_CHUNKS + 1]; static size_t cur_size = 0; static unsigned int cur_chunks = 0; static size_t total_size = 0; static unsigned int total_chunks = 0;
+ void tst_malloc_check_report(struct malloc_stats *stats) { stats->lost_size = cur_size; @@ -62,43 +54,51 @@ void tst_malloc_check_report(struct malloc_stats *stats) stats->total_chunks = total_chunks; }
+#define MAX_CHUNKS 100 + +struct chunk { + void *ptr; + size_t size; + int cont; +}; + +static struct chunk chunks[MAX_CHUNKS]; +static unsigned int chunks_top = 0; + static void add_chunk(size_t size, void *ptr) { - int i; - - for (i = 0; i < MAX_CHUNKS; i++) { - if (chunks[i].size == 0) { - chunks[i].size = size; - chunks[i].ptr = ptr; - cur_size += size; - cur_chunks++; - total_size += size; - total_chunks++; - return; - } + if (chunks_top >= MAX_CHUNKS) { + tst_warn("Not enough chunks (%i) for malloc() tracing", + MAX_CHUNKS); + return; }
- tst_warn("Not enough chunks (%i) for malloc() tracing", MAX_CHUNKS); + /* Store chunk */ + chunks[chunks_top].size = size; + chunks[chunks_top].ptr = ptr; + chunks_top++; + + /* Update global stats */ + cur_size += size; + cur_chunks++; + total_size += size; + total_chunks++; }
static void rem_chunk(void *ptr) { - int i; - - for (i = 0; i < MAX_CHUNKS; i++) { - /* Nothing interesting in the rest of the array */ - if (chunks[i].size == 0 && chunks[i].cont == 0) - break; + unsigned int i;
+ for (i = 0; i < chunks_top; i++) { if (chunks[i].ptr == ptr) { + + /* Update global stats */ cur_size -= chunks[i].size; cur_chunks--; - chunks[i].size = 0; - chunks[i].ptr = NULL; + /* Replace found chunk with top one */ + chunks[i] = chunks[--chunks_top]; - if (chunks[i+1].size != 0 || chunks[i+1].cont != 0) - chunks[i].cont = 1; return; } }
http://repo.or.cz/w/gfxprim.git/commit/7b51e7842889c3eb0ecf06dc9586d1acb4bfb...
commit 7b51e7842889c3eb0ecf06dc9586d1acb4bfbce6 Author: Cyril Hrubis metan@ucw.cz Date: Wed Aug 22 13:46:08 2012 +0200
tests: Add allocation with barriers.
diff --git a/tests/framework/Makefile b/tests/framework/Makefile index 64186ca..529919e 100644 --- a/tests/framework/Makefile +++ b/tests/framework/Makefile @@ -14,8 +14,8 @@ APPS=test
ALL+=libtst_preload.so
-libtst_preload.so: tst_preload.o - gcc -Wl,-soname -Wl,tst_preload.so --shared -ldl -fPIC $< -o $@ +libtst_preload.so: tst_preload.o tst_alloc_barriers.o + gcc -Wl,-soname -Wl,tst_preload.so --shared -ldl -fPIC $^ -o $@
CLEAN+=libtst_preload.so
diff --git a/tests/framework/test.c b/tests/framework/test.c index 69e50eb..f460139 100644 --- a/tests/framework/test.c +++ b/tests/framework/test.c @@ -25,6 +25,7 @@ #include <stdio.h>
#include "tst_test.h" +#include "tst_alloc_barriers.h"
int success_fn(void) { @@ -103,6 +104,24 @@ int double_free(void) return TST_SUCCESS; }
+int barrier_allocation(void) +{ + char *buf = tst_alloc_barrier_right(31); + + int i; + + for (i = 0; i < 31; i++) + buf[i] = 0; + + tst_report(0, "About to use address after the buffer with barrier"); + + buf[31] = 0; + + tst_report(0, "This is not printed at all"); + + return TST_SUCCESS; +} + const struct tst_suite suite = { .suite_name = "Testing Framework Example", .tests = { @@ -115,6 +134,7 @@ const struct tst_suite suite = { {.name = "Mem Leak test", .tst_fn = malloc_leak_fn, .flags = TST_MALLOC_CHECK}, {.name = "Mem Ok test", .tst_fn = malloc_ok_fn, .flags = TST_MALLOC_CHECK}, {.name = "Double free()", .tst_fn = double_free}, + {.name = "Barrier allocation", .tst_fn = barrier_allocation}, {.name = NULL}, } }; diff --git a/tests/framework/tst_alloc_barriers.c b/tests/framework/tst_alloc_barriers.c new file mode 100644 index 0000000..c5aa7ad --- /dev/null +++ b/tests/framework/tst_alloc_barriers.c @@ -0,0 +1,102 @@ +/***************************************************************************** + * 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-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <stdio.h> +#include <sys/mman.h> +#include <malloc.h> +#include <unistd.h> + +#include "tst_alloc_barriers.h" + +void *tst_alloc_barrier_right(size_t size) +{ + size_t pagesize = sysconf(_SC_PAGESIZE); + size_t pages = size/pagesize + !!(size%pagesize) + 1; + + char *buf = memalign(pagesize, pages * pagesize); + + if (buf == NULL) + return NULL; + + /* + * Turn off read/write acces on the last page. The buffer starts + * somewhere in the first page so that the end is exactly before the + * start of the last page. + */ + if (mprotect(buf + pagesize * (pages - 1), pagesize, PROT_NONE)) { + perror("mprotect"); + free(buf); + return NULL; + } + + return buf + (pagesize - size%pagesize); +} + +void tst_free_barrier_right(void *ptr, size_t size) +{ + size_t pagesize = sysconf(_SC_PAGESIZE); + size_t pages = size/pagesize + !!(size%pagesize); + void *start = (char*)ptr - (pagesize - size%pagesize); + + /* Reset the memory protection back to RW */ + if (mprotect(start + pagesize * pages, pagesize, PROT_READ | PROT_WRITE)) { + perror("mprotect"); + } + + free(start); +} + +void *tst_alloc_barrier_left(size_t size) +{ + size_t pagesize = sysconf(_SC_PAGESIZE); + size_t pages = size/pagesize + !!(size%pagesize) + 1; + + char *buf = memalign(pagesize, pages * pagesize); + + if (buf == NULL) + return NULL; + + /* + * Turn off read/write acces on the first page, the buffer starts right + * after it. + */ + if (mprotect(buf, pagesize, PROT_NONE)) { + perror("mprotect"); + free(buf); + return NULL; + } + + return buf + pagesize; +} + +void tst_free_barrier_left(void *ptr, size_t size __attribute__((unused))) +{ + size_t pagesize = sysconf(_SC_PAGESIZE); + void *start = ptr - pagesize; + + /* Reset the memory protection back to RW */ + if (mprotect(start, pagesize, PROT_READ | PROT_WRITE)) { + perror("mprotect"); + } + + free(start); +} diff --git a/tests/framework/tst_alloc_barriers.h b/tests/framework/tst_alloc_barriers.h new file mode 100644 index 0000000..dc6b12d --- /dev/null +++ b/tests/framework/tst_alloc_barriers.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * 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-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +/* + + This code could create a buffer with either left or right barrier. Barrier 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 + +/* + * Allocate memory with a barrier 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); + +/* + * Free allocated buffer. + */ +void tst_free_barrier_right(void *ptr, size_t size); + +/* + * Allocate memory with barrier 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); + +/* + * Free allocated buffer. + */ +void tst_free_barrier_left(void *ptr, size_t size); + +#endif /* TST_ALLOC_BARRIERS_H */
-----------------------------------------------------------------------
Summary of changes: tests/framework/Makefile | 4 +- tests/framework/test.c | 43 +++++- .../framework/tst_alloc_barriers.c | 95 ++++++++------ .../framework/tst_alloc_barriers.h | 43 +++--- tests/framework/tst_log.c | 145 +++++++++++++++++++- tests/framework/tst_preload.c | 64 +++++----- tests/framework/tst_test.c | 17 ++- 7 files changed, 302 insertions(+), 109 deletions(-) copy libs/filters/GP_Dither.c => tests/framework/tst_alloc_barriers.c (50%) copy include/loaders/GP_GIF.h => tests/framework/tst_alloc_barriers.h (65%)
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.