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 7064952e38373799deaae59b2ea67093d75b3709 (commit) from d87921f9670a726993a5bfd756e3ae09a3ba83ed (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/7064952e38373799deaae59b2ea67093d75b3...
commit 7064952e38373799deaae59b2ea67093d75b3709 Author: Cyril Hrubis metan@ucw.cz Date: Sun Nov 25 20:26:58 2012 +0100
tests: framework: Create JSON log to HTML converter.
Create JSON to HTML log converted and remove the C implementation.
diff --git a/tests/framework/Makefile b/tests/framework/Makefile index a688952..44ed5e1 100644 --- a/tests/framework/Makefile +++ b/tests/framework/Makefile @@ -20,7 +20,7 @@ libtst_preload.so: tst_preload.o tst_alloc_barriers.o tst_preload_FILE.o libtst.a: tst_suite.o tst_job.o tst_msg.o tst_log.o tst_main.o tst_timespec.o ar rcs $@ $^
-CLEAN+=libtst_preload.so libtst.a log.html log.json +CLEAN+=libtst_preload.so libtst.a log.json
include $(TOPDIR)/app.mk include $(TOPDIR)/post.mk diff --git a/tests/framework/json_parse.py b/tests/framework/json_parse.py deleted file mode 100755 index b3e0833..0000000 --- a/tests/framework/json_parse.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# -# Sample python code to print testsuite name and test results from the JSON logfile -# - -import json - -# -# Create classes from JSON dictionary -# -class TestResult: - def __init__(self, test_result): - self.name = test_result["Test Name"] - self.result = test_result["Test Result"] - self.reports = test_result["Test Reports"] - self.cpu_time = test_result["CPU Time"] - self.run_time = test_result["Run Time"] - - if ("Malloc Stats" in test_result): - self.malloc_stats = 1 - - def __str__(self): - return "Test '%s' ended with '%s' (CPU %is) (TIME %is)" % - (self.name, self.result, self.cpu_time, self.run_time) - - -class TestSuite: - def __init__(self, testsuite_result): - self.name = testsuite_result["Suite Name"] - self.test_results = [] - - for test_result in testsuite_result["Test Results"]: - self.test_results.append(TestResult(test_result)) - - def __str__(self): - ret = 'tt' + self.name + 'nn' - - max_len = 0 - for i in self.test_results: - max_len = max(max_len, len(i.name)) - - for i in self.test_results: - ret += i.name - - padds = (max_len - len(i.name)) - - while padds > 0: - ret += ' ' - padds-=1 - - ret += " | %.3fs/%.3fs | %sn" % - (i.cpu_time, i.run_time, i.result) - - for j in i.reports: - ret += " (%s)n" % j - - return ret - -def main(): - # parse JSON - f = open('log.json') - data = json.load(f) - f.close() - - # convert to python objects - test_suite = TestSuite(data) - - print(test_suite) - -if __name__ == '__main__': - main() diff --git a/tests/framework/log2html.py b/tests/framework/log2html.py new file mode 100755 index 0000000..c417daa --- /dev/null +++ b/tests/framework/log2html.py @@ -0,0 +1,289 @@ +#!/usr/bin/env python + +# +# Script to convert testsuite JSON log into html page +# + +import json + +# +# Test result to html color dict +# +html_colors = { + 'Success': '#008000', + 'Skipped': '#888888', + 'Untested': '#0000bb', + 'Internal Error': '#800000', + 'Segmentation Fault': '#e00000', + 'Timeout': '#800080', + 'Aborted': '#e00000', + 'FP Exception': '#e00000', + 'Memory Leak': '#a0a000', + 'Failed': '#e00000' +} + +# +# Convert bytes to human-readable string +# +def bytes_conv(size): + if (size < 512): + return "%iB" % (size) + + if (size < 1024 * 512): + return "%.2fkB" % (float(size) / 1024) + + if (size < 1024 * 1024 * 512): + return "%.2fMB" % (float(size) / 1024 / 1024) + + return "%.2fGB" % (float(size) / 1024 / 1024 / 1024) + +# +# Malloc statistics Class created from JSON dict +# +class MallocStats: + def __init__(self, malloc_stats): + self.total_size = malloc_stats["Total Size"] + self.total_chunks = malloc_stats["Total Chunks"] + self.max_size = malloc_stats["Max Size"] + self.max_chunks = malloc_stats["Max Chunks"] + self.lost_size = malloc_stats["Lost Size"] + self.lost_chunks = malloc_stats["Lost Chunks"] + + def html(self): + print(' <tr>') + print(' <td bgcolor="#ffffcc" colspan="3">') + print(' <center>') + print(' <table>') + + # Table header + print(' <tr>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Total size</small>') + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Total chunks</small>') + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Max size</small>') + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Max chunks</small>') + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Lost size</small>') + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <small>Lost chunks</small>') + print(' </td>') + + print(' </tr>') + + # Malloc data + print(' <tr>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.total_size)) + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.total_chunks)) + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.max_size)) + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.max_chunks)) + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.lost_size)) + print(' </td>') + + print(' <td bgcolor="#ffffaa">') + print(' <center><small>%s</small></center>' % + bytes_conv(self.lost_chunks)) + print(' </td>') + + print(' </tr>') + + print(' </table>') + print(' </center>') + print(' </td>') + print(' </tr>') + +# +# Benchmark statistics Class created from JSON dict +# +class BenchmarkData: + def __init__(self, bench_data): + self.time_mean = bench_data["Time Mean"] + self.time_variance = bench_data["Time Variance"] + self.iterations = bench_data["Iterations"] + + def html(self): + print(' <tr>') + print(' <td bgcolor="#fd8" colspan="3">') + print(' <center>') + print(' <table>') + + # Table header + print(' <tr>') + + print(' <td colspan="2" bgcolor="#fb2">') + print(' <center><small>Benchmark data</small></center>') + print(' </td>') + + print(' </tr>') + + print(' <tr>') + + print(' <td bgcolor="#fc4">') + print(' <center><small>Iterations</small></center>') + print(' </td>') + + print(' <td bgcolor="#fc4">') + print(' <center><small>Mean ∓ Variance</small></center>') + print(' </td>') + + print(' </tr>') + + # Benchmark data + print(' <tr>') + + print(' <td bgcolor="#fc4">') + print(' <small>%i</small>' % (self.iterations)) + print(' </td>') + + print(' <td bgcolor="#fc4">') + print(' <small>%.6fs ∓ %.6fs</small>' % + (self.time_mean, self.time_variance)) + print(' </td>') + + print(' </tr>') + + print(' </table>') + print(' </center>') + print(' </td>') + print(' </tr>') + +# +# Test Result Class created from JSON dict +# +class TestResult: + def __init__(self, test_result): + self.name = test_result["Test Name"] + self.result = test_result["Test Result"] + self.reports = test_result["Test Reports"] + self.cpu_time = test_result["CPU Time"] + self.run_time = test_result["Run Time"] + self.test_reports = test_result["Test Reports"] + + if ("Malloc Stats" in test_result): + self.malloc_stats = MallocStats(test_result["Malloc Stats"]) + + if ("Benchmark" in test_result): + self.bench_data = BenchmarkData(test_result["Benchmark"]) + + def html(self, bg_color): + # Print test result + print(' <tr>') + + print(' <td bgcolor="%s">%s </td>' % (bg_color, self.name)) + + print(' <td bgcolor="%s">' % (bg_color)) + print(' <center><small><font color="#222">') + print(' %.3fs %.3fs' % (self.run_time, self.cpu_time)) + print(' </font></small></center>') + print(' </td>') + + print(' <td bgcolor="%s">' % (html_colors[self.result])) + print(' <center><font color="white"> %s </center>' % + (self.result)) + print(' </td>') + + print(' </tr>') + + # Add malloc statistics, if present + if (hasattr(self, 'malloc_stats')): + self.malloc_stats.html() + + # And benchmark data + if (hasattr(self, 'bench_data')): + self.bench_data.html() + + # And test messages + if (self.test_reports): + print(' <tr>') + print(' <td colspan="3" bgcolor="#eeeeee">') + + for msg in self.test_reports: + print(' <small>%s</small><br>' % (msg)) + + if (self.test_reports): + print(' </td>') + print(' </tr>') + +class TestSuite: + def __init__(self, testsuite_result): + self.suite_name = testsuite_result["Suite Name"] + self.test_results = [] + + for test_result in testsuite_result["Test Results"]: + self.test_results.append(TestResult(test_result)) + + def html(self): + print('<html>') + print(' <head>') + print(' </head>') + print(' <body>') + + print(' <table bgcolor="#99a">') + print(' <tr>') + print(' <td colspan="3" bgcolor="#bbbbff">'); + print(' <center><b>%s</b></center>' % (self.suite_name)) + print(' </td>') + print(' </tr>') + + flag = False; + + for tst in self.test_results: + if (flag): + bg_color = '#ccccee' + else: + bg_color = '#ddddee' + + flag = not flag + + tst.html(bg_color) + + print(' </table>') + + print(' </body>') + print('</html>') + +def main(): + # parse JSON + f = open('log.json') + data = json.load(f) + f.close() + + # convert to python objects + test_suite = TestSuite(data) + + test_suite.html() + +if __name__ == '__main__': + main() diff --git a/tests/framework/tst_log.c b/tests/framework/tst_log.c index cc86b6f..a7cf9ec 100644 --- a/tests/framework/tst_log.c +++ b/tests/framework/tst_log.c @@ -30,36 +30,6 @@ #include "tst_timespec.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_SKIPPED: - return "#888888"; - case TST_UNTESTED: - return "#0000bb"; - case TST_INTERR: - return "#800000"; - case TST_SIGSEGV: - return "#e00000"; - case TST_TIMEOUT: - return "#800080"; - case TST_ABORTED: - return "#e00000"; - case TST_FPE: - return "#e00000"; - 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) { @@ -90,210 +60,6 @@ static const char *ret_to_str(enum tst_ret ret) return "Unknown"; }
-static void bytes_human_readable(FILE *f, size_t bytes) -{ - if (bytes < 512) { - fprintf(f, "%zuB", bytes); - return; - } - - if (bytes < 1024 * 512) { - fprintf(f, "%.2fkB", (float)bytes / 1024); - return; - } - - if (bytes < 1024 * 1024 * 512) { - fprintf(f, "%.2fMB", (float)bytes / 1024 / 1024); - return; - } - - fprintf(f, "%.2fGB", (float)bytes / 1024 / 1024 / 1024); -} - -static void malloc_stats_html(struct tst_job *job, FILE *f, const char *padd) -{ - /* Create innter table */ - fprintf(f, "%s<tr>n", padd); - fprintf(f, "%s <td bgcolor="#ffffcc" colspan="3">n", padd); - fprintf(f, "%s <center>n", padd); - fprintf(f, "%s <table>n", padd); - - /* Create header */ - fprintf(f, "%s <tr>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Total size</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Total chunks</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Max size</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Max chunks</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Lost size</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <small>Lost chunks</small>n", padd); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s </tr>n", padd); - - /* Create data */ - fprintf(f, "%s <tr>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>", padd); - bytes_human_readable(f, job->malloc_stats.total_size); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>%u</small></center>n", - padd, job->malloc_stats.total_chunks); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>", padd); - bytes_human_readable(f, job->malloc_stats.max_size); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>%u</small></center>n", - padd, job->malloc_stats.max_chunks); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>", padd); - bytes_human_readable(f, job->malloc_stats.lost_size); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#ffffaa">n", padd); - fprintf(f, "%s <center><small>%u</small></center>n", - padd, job->malloc_stats.lost_chunks); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s </tr>n", padd); - - fprintf(f, "%s </table>n", padd); - fprintf(f, "%s </center>n", padd); - fprintf(f, "%s </td>n", padd); - fprintf(f, "%s</tr>n", padd); -} - -static void benchmark_stats_html(struct tst_job *job, FILE *f, const char *padd) -{ - /* Create innter table */ - fprintf(f, "%s<tr>n", padd); - fprintf(f, "%s <td bgcolor="#fd8" colspan="3">n", padd); - fprintf(f, "%s <center>n", padd); - fprintf(f, "%s <table>n", padd); - - /* Create header */ - fprintf(f, "%s <tr>n", padd); - - fprintf(f, "%s <td colspan="2" bgcolor="#fb2">n", padd); - fprintf(f, "%s <center><small>Benchmark data", padd); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s </tr>n", padd); - fprintf(f, "%s <tr>n", padd); - - fprintf(f, "%s <td bgcolor="#fc4">n", padd); - fprintf(f, "%s <center><small>Iterations", padd); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#fc4">n", padd); - fprintf(f, "%s <center><small>Mean ∓ Variance", padd); - fprintf(f, "</small></center>n"); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s </tr>n", padd); - - /* Create data */ - fprintf(f, "%s <tr>n", padd); - - fprintf(f, "%s <td bgcolor="#fc4">n", padd); - fprintf(f, "%s <center>%i</center>n", padd, job->bench_iter); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s <td bgcolor="#fc4">n", padd); - fprintf(f, "%s <center>%i.%06is ∓ %i.%06is</center>n", padd, - (int)job->bench_mean.tv_sec, (int)job->bench_mean.tv_nsec/1000, - (int)job->bench_var.tv_sec, (int)job->bench_var.tv_nsec/1000); - fprintf(f, "%s </td>n", padd); - - fprintf(f, "%s </tr>n", padd); - - fprintf(f, "%s </table>n", padd); - fprintf(f, "%s </center>n", padd); - fprintf(f, "%s </td>n", padd); - fprintf(f, "%s</tr>n", padd); -} - -static int append_html(struct tst_job *job, FILE *f) -{ - const char *padd = " "; - int sec, nsec; - static int hack_counter = 0; - const char *bgcol; - - timespec_diff(&sec, &nsec, &job->start_time, &job->stop_time); - - if (hack_counter) - bgcol = "#ccccee"; - else - bgcol = "#ddddee"; - - fprintf(f, "%s<tr>n", padd); - fprintf(f, "%s <td bgcolor="%s">%s </td>n", - padd, bgcol, job->test->name); - fprintf(f, "%s <td bgcolor="%s">n", padd, bgcol); - fprintf(f, "%s <center><small><font color="#222">%i.%03is %i.%03is" - "</font></small></center>n", padd, sec, nsec/1000000, - (int)job->cpu_time.tv_sec, (int)job->cpu_time.tv_nsec/1000000); - fprintf(f, "%s </td>n", padd); - fprintf(f, "%s <td bgcolor="%s"><center><font color="white">" - " %s </td></center>n", padd, - ret_to_bg_color(job->result), ret_to_str(job->result)); - - struct tst_msg *msg; - - /* If calculated include malloc report */ - if (job->test->flags & TST_CHECK_MALLOC) - malloc_stats_html(job, f, padd); - - if (job->bench_iter) - benchmark_stats_html(job, f, padd); - - for (msg = job->store.first; msg != NULL; msg = msg->next) { - fprintf(f, "%s<tr>n", padd); - fprintf(f, "%s <td colspan="3" bgcolor="#eeeeee">n", padd); - fprintf(f, "%s <small>%s</small>n", - padd, msg->msg); - fprintf(f, "%s </td>n", padd); - fprintf(f, "%s</tr>n", padd); - } - - fprintf(f, "%s</tr>n", padd); - - hack_counter = !hack_counter; - - return 0; -} - static int append_msg_json(struct tst_job *job, FILE *f) { struct tst_msg *msg; @@ -391,9 +157,6 @@ static int append_json(struct tst_job *job, FILE *f) 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; @@ -404,30 +167,6 @@ int tst_log_append(struct tst_job *job, FILE *f, enum tst_log_fmt format) 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 bgcolor="#99a">n"); - - fprintf(f, " <tr><td colspan="3" bgcolor="#bbbbff"><center><b>%s" - "</b></center></td></tr>n", suite->suite_name); - - fprintf(f, " <tr>n"); - fprintf(f, " <td bgcolor="#eee"><center>Test Name</center></td>n"); - fprintf(f, " <td bgcolor="#eee"><center>Time/CPU</center></td>n"); - fprintf(f, " <td bgcolor="#eee"><center>Result</center></td>n"); - fprintf(f, " </tr>n"); - - return f; -} - static void write_system_info_json(FILE *f) { struct utsname buf; @@ -487,9 +226,6 @@ 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; case TST_LOG_JSON: return open_json(suite, path); break; @@ -500,12 +236,6 @@ FILE *tst_log_open(const struct tst_suite *suite, const char *path, return NULL; }
-static int close_html(FILE *f) -{ - fprintf(f, " </table>n </body>n</html>n"); - return fclose(f); -} - static int close_json(FILE *f) { fprintf(f, "nt]n}n"); @@ -515,9 +245,6 @@ static int close_json(FILE *f) int tst_log_close(FILE *f, enum tst_log_fmt format) { switch (format) { - case TST_LOG_HTML: - return close_html(f); - break; case TST_LOG_JSON: return close_json(f); break; diff --git a/tests/framework/tst_log.h b/tests/framework/tst_log.h index 413c854..28fecf1 100644 --- a/tests/framework/tst_log.h +++ b/tests/framework/tst_log.h @@ -35,7 +35,6 @@ struct tst_suite; struct tst_job;
enum tst_log_fmt { - TST_LOG_HTML, TST_LOG_JSON, };
diff --git a/tests/framework/tst_suite.c b/tests/framework/tst_suite.c index 1c0440b..e929225 100644 --- a/tests/framework/tst_suite.c +++ b/tests/framework/tst_suite.c @@ -115,7 +115,7 @@ static void test_job_report(const struct tst_job *job) "------------------------- n"); }
-static int run_test(const struct tst_test *test, FILE *html, FILE *json) +static int run_test(const struct tst_test *test, FILE *json) { struct tst_job job;
@@ -127,7 +127,6 @@ static int run_test(const struct tst_test *test, FILE *html, FILE *json) * child and parent and the lines in the resulting * file would be repeated several times. */ - fflush(html); fflush(json);
tst_job_run(&job); @@ -136,7 +135,6 @@ static int run_test(const struct tst_test *test, FILE *html, FILE *json) /* report result into stdout */ test_job_report(&job);
- tst_log_append(&job, html, TST_LOG_HTML); tst_log_append(&job, json, TST_LOG_JSON);
/* Free the test message store */ @@ -155,12 +153,11 @@ 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 *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], html, json); + ret = run_test(&suite->tests[i], json); counters[ret]++; if (ret != TST_SKIPPED) @@ -168,7 +165,6 @@ void tst_run_suite(const struct tst_suite *suite, const char *tst_name) } }
- tst_log_close(html, TST_LOG_HTML); tst_log_close(json, TST_LOG_JSON);
float percents;
-----------------------------------------------------------------------
Summary of changes: tests/framework/Makefile | 2 +- tests/framework/json_parse.py | 72 ---------- tests/framework/log2html.py | 289 +++++++++++++++++++++++++++++++++++++++++ tests/framework/tst_log.c | 273 -------------------------------------- tests/framework/tst_log.h | 1 - tests/framework/tst_suite.c | 8 +- 6 files changed, 292 insertions(+), 353 deletions(-) delete mode 100755 tests/framework/json_parse.py create mode 100755 tests/framework/log2html.py
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.