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 c5456e61ba0c97fa143aca16463e9bd6d8e05468 (commit) from c6ff6eadd9601eb33b28a9999b5fab6d3221ed44 (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/c5456e61ba0c97fa143aca16463e9bd6d8e05...
commit c5456e61ba0c97fa143aca16463e9bd6d8e05468 Author: Cyril Hrubis metan@ucw.cz Date: Sun Aug 12 11:30:54 2012 +0200
tests: Add first simple html export.
diff --git a/tests/framework/Makefile b/tests/framework/Makefile index 901a4fe..64186ca 100644 --- a/tests/framework/Makefile +++ b/tests/framework/Makefile @@ -8,7 +8,7 @@ LDFLAGS+=-L. LDLIBS+=-ltst_preload -ldl CFLAGS+=
-test: tst_test.o tst_job.o tst_msg.o +test: tst_test.o tst_job.o tst_msg.o tst_log.o
APPS=test
diff --git a/tests/framework/test.c b/tests/framework/test.c index f3d5356..ddc1573 100644 --- a/tests/framework/test.c +++ b/tests/framework/test.c @@ -112,12 +112,12 @@ int main(void) { fprintf(stderr, "(Listing testsuite tests)n"); tst_list_suite(&suite); + + fprintf(stderr, "n(Running selected test)n"); + tst_run_suite(&suite, "Sigsegv test");
fprintf(stderr, "n(Running whole suite)n"); tst_run_suite(&suite, NULL);
- fprintf(stderr, "n(Running selected test)n"); - tst_run_suite(&suite, "Sigsegv test"); - return 0; } diff --git a/tests/framework/tst_log.c b/tests/framework/tst_log.c new file mode 100644 index 0000000..7277d3a --- /dev/null +++ b/tests/framework/tst_log.c @@ -0,0 +1,158 @@ +/***************************************************************************** + * 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 "tst_test.h" +#include "tst_job.h" +#include "tst_msg.h" +#include "tst_log.h" + +static const char *ret_to_bg_color(enum tst_ret ret) +{ + switch (ret) { + case TST_SUCCESS: + return "#008000"; + case TST_INTERR: + return "#800000"; + case TST_SIGSEGV: + return "#e00000"; + case TST_TIMEOUT: + return "#800080"; + case TST_MEMLEAK: + return "#a0a000"; + case TST_FAILED: + return "#e00000"; + case TST_MAX: + break; + } + + return "#000000"; +} + +static const char *ret_to_str(enum tst_ret ret) +{ + switch (ret) { + case TST_SUCCESS: + return "Success"; + case TST_INTERR: + return "Internal Error"; + case TST_SIGSEGV: + return "Segmentation Fault"; + case TST_TIMEOUT: + return "Timeout"; + case TST_MEMLEAK: + return "Memory Leak"; + case TST_FAILED: + return "Failed"; + case TST_MAX: + break; + } + + return "Unknown"; +} + +static int append_html(struct tst_job *job, FILE *f) +{ + const char *padd = " "; + + fprintf(f, "%s<tr>n", padd); + fprintf(f, "%s <td colspan=2 bgcolor="#ccccee">%s</td>n", padd, job->test->name); + fprintf(f, "%s <td bgcolor="%s"><font color="white">%s</td>n", padd, + ret_to_bg_color(job->result), ret_to_str(job->result)); + + struct tst_msg *msg; + + for (msg = job->store.first; msg != NULL; msg = msg->next) { + fprintf(f, "%s<tr>", padd); + fprintf(f, "%s <td colspan="3" bgcolor="#eeeeee">", padd); + fprintf(f, "%s %s", padd, msg->msg); + fprintf(f, "%s </td>", padd); + fprintf(f, "%s</tr>", padd); + } + + fprintf(f, "%s</tr>n", padd); + + 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; + default: + return 1; + } + + return 1; +} + +FILE *open_html(const struct tst_suite *suite, const char *path) +{ + FILE *f; + + f = fopen(path, "w"); + + if (f == NULL) + return NULL; + + fprintf(f, "<html>n <head>n </head>n <body>n <table>n"); + + fprintf(f, " <tr><td colspan="3" bgcolor="#bbbbff"><b>%s" + "</b></td></tr>n", suite->suite_name); + + return f; +} + +FILE *tst_log_open(const struct tst_suite *suite, const char *path, + enum tst_log_fmt format) +{ + switch (format) { + case TST_LOG_HTML: + return open_html(suite, path); + break; + default: + return NULL; + } + + return NULL; +} + +static int close_html(FILE *f) +{ + fprintf(f, " </table>n </body>n</html>n"); + fclose(f); + return 0; +} + +int tst_log_close(FILE *f, enum tst_log_fmt format) +{ + switch (format) { + case TST_LOG_HTML: + return close_html(f); + break; + default: + return 1; + } + + return 1; +} diff --git a/tests/framework/tst_test.c b/tests/framework/tst_log.h similarity index 56% copy from tests/framework/tst_test.c copy to tests/framework/tst_log.h index d04caf5..413c854 100644 --- a/tests/framework/tst_test.c +++ b/tests/framework/tst_log.h @@ -20,70 +20,30 @@ * * *****************************************************************************/
-#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdarg.h> - -#include "tst_job.h" -#include "tst_test.h" - -int tst_warn(const char *fmt, ...) -{ - va_list va; - int ret; - - va_start(va, fmt); - ret = vfprintf(stderr, fmt, va); - va_end(va); + /* + + Logs finished job result into the file.
- return ret; -} - -static int run_test(const struct tst_test *test) -{ - struct tst_job job; + */
- job.test = test; +#ifndef TST_LOG_H +#define TST_LOG_H
- tst_job_run(&job); - tst_job_wait(&job); - - /* Free the test message store */ - tst_msg_clear(&job.store); - - return job.result; -} - -void tst_run_suite(const struct tst_suite *suite, const char *tst_name) -{ - unsigned int i; - unsigned int counters[TST_MAX] = {}; - unsigned int counter = 0; - int ret; +#include <stdio.h>
- fprintf(stderr, "Running e[1;37m%se[0mnn", suite->suite_name); +struct tst_suite; +struct tst_job;
- 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]); - counters[ret]++; - counter++; - } - } +enum tst_log_fmt { + TST_LOG_HTML, + TST_LOG_JSON, +};
- fprintf(stderr, "nSummary: succedded %u out of %u (%.2f%%)n", - counters[0], counter, 100.00 * counters[0] / counter); -} +FILE *tst_log_open(const struct tst_suite *suite, const char *path, + enum tst_log_fmt format);
-void tst_list_suite(const struct tst_suite *suite) -{ - int i; +int tst_log_append(struct tst_job *job, FILE *f, enum tst_log_fmt format);
- fprintf(stderr, "Testsuite: e[1;37m%se[0mnn", suite->suite_name); +int tst_log_close(FILE *f, enum tst_log_fmt format);
- for (i = 0; suite->tests[i].name != NULL; i++) - fprintf(stderr, "Test: e[1;37m%se[0mn", suite->tests[i].name); -} +#endif /* TST_LOG_H */ diff --git a/tests/framework/tst_test.c b/tests/framework/tst_test.c index d04caf5..f45a582 100644 --- a/tests/framework/tst_test.c +++ b/tests/framework/tst_test.c @@ -27,6 +27,7 @@ #include <string.h> #include <stdarg.h>
+#include "tst_log.h" #include "tst_job.h" #include "tst_test.h"
@@ -42,15 +43,26 @@ int tst_warn(const char *fmt, ...) return ret; } -static int run_test(const struct tst_test *test) +static int run_test(const struct tst_test *test, FILE *f, + enum tst_log_fmt format) { struct tst_job job;
job.test = test;
+ /* + * Flush the file before forking, otherwise + * there would be a copy of its buffers in both + * child and parent and the lines in the resulting + * file would be repeated several times. + */ + fflush(f); + tst_job_run(&job); tst_job_wait(&job);
+ tst_log_append(&job, f, format); + /* Free the test message store */ tst_msg_clear(&job.store);
@@ -66,14 +78,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); + 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]); + ret = run_test(&suite->tests[i], f, TST_LOG_HTML); counters[ret]++; counter++; } }
+ tst_log_close(f, TST_LOG_HTML); + fprintf(stderr, "nSummary: succedded %u out of %u (%.2f%%)n", counters[0], counter, 100.00 * counters[0] / counter); }
-----------------------------------------------------------------------
Summary of changes: tests/framework/Makefile | 2 +- tests/framework/test.c | 6 +- tests/framework/tst_log.c | 158 ++++++++++++++++++++ .../GP_Backends.h => tests/framework/tst_log.h | 41 +++--- tests/framework/tst_test.c | 21 +++- 5 files changed, 201 insertions(+), 27 deletions(-) create mode 100644 tests/framework/tst_log.c copy include/backends/GP_Backends.h => tests/framework/tst_log.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.