Message ID | 20180620121446.31470-6-info@marcellobauer.com |
---|---|
State | Accepted |
Headers | show |
Series | coreboot test intergration | expand |
On 20/06/18 13:14, Marcello Sylvester Bauer wrote: > Note: boolean remove_timestamp has been added as argument. > > Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> > --- > src/lib/include/fwts_log_scan.h | 4 ++ > src/lib/src/fwts_klog.c | 79 +-------------------------------- > src/lib/src/fwts_log_scan.c | 98 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 103 insertions(+), 78 deletions(-) > > diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h > index e08d0aac..31fa3f7e 100644 > --- a/src/lib/include/fwts_log_scan.h > +++ b/src/lib/include/fwts_log_scan.h > @@ -38,8 +38,12 @@ typedef struct { > bool compiled_ok; > } fwts_log_pattern; > > +typedef void (*fwts_log_progress_func)(fwts_framework *fw, int percent); > +typedef void (*fwts_log_scan_func)(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors); > + > void fwts_log_free(fwts_list *list); > fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new); > char *fwts_log_remove_timestamp(char *text); > +int fwts_log_scan(fwts_framework *fw, fwts_list *log, fwts_log_scan_func callback, fwts_log_progress_func progress, void *private, int *errors, bool remove_timestamp); > > #endif > diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c > index 25491815..94195261 100644 > --- a/src/lib/src/fwts_klog.c > +++ b/src/lib/src/fwts_klog.c > @@ -93,84 +93,7 @@ int fwts_klog_scan(fwts_framework *fw, > void *private, > int *match) > { > - typedef struct { > - char *line; > - int repeated; > - } klog_reduced_item; > - > - char *prev; > - fwts_list_link *item; > - fwts_list *klog_reduced; > - int i; > - > - *match = 0; > - > - if (!klog) > - return FWTS_ERROR; > - > - if ((klog_reduced = fwts_list_new()) == NULL) > - return FWTS_ERROR; > - > - /* > - * Form a reduced log by stripping out repeated kernel warnings > - */ > - i = 0; > - fwts_list_foreach(item, klog) { > - char *newline = fwts_klog_remove_timestamp(fwts_list_data(char *, item)); > - if (progress_func && ((i % 25) == 0)) > - progress_func(fw, 50 * i / fwts_list_len(klog)); > - if (*newline) { > - bool matched = false; > - fwts_list_link *l; > - fwts_list_foreach(l, klog_reduced) { > - char *line; > - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, l); > - > - line = fwts_klog_remove_timestamp(reduced->line); > - if (strcmp(newline, line) == 0) { > - reduced->repeated++; > - matched = true; > - break; > - } > - } > - if (!matched) { > - klog_reduced_item *new; > - > - if ((new = calloc(1, sizeof(klog_reduced_item))) == NULL) { > - fwts_list_free(klog_reduced, free); > - return FWTS_ERROR; > - } > - new->line = fwts_list_data(char *, item); > - new->repeated = 0; > - > - fwts_list_append(klog_reduced, new); > - } > - } > - i++; > - } > - > - prev = ""; > - > - i = 0; > - fwts_list_foreach(item, klog_reduced) { > - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, item); > - char *line = reduced->line; > - > - if ((line[0] == '<') && (line[2] == '>')) > - line += 3; > - > - scan_func(fw, line, reduced->repeated, prev, private, match); > - if (progress_func && ((i % 25) == 0)) > - progress_func(fw, (50+(50 * i)) / fwts_list_len(klog_reduced)); > - prev = line; > - i++; > - } > - if (progress_func) > - progress_func(fw, 100); > - > - fwts_list_free(klog_reduced, free); > - > - return FWTS_OK; > + return fwts_log_scan(fw, klog, scan_func, progress_func, private, match, true); > } > > char *fwts_klog_unique_label(const char *str) > diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c > index f6050fbc..9b9e9457 100644 > --- a/src/lib/src/fwts_log_scan.c > +++ b/src/lib/src/fwts_log_scan.c > @@ -107,3 +107,101 @@ char *fwts_log_remove_timestamp(char *text) > > return ptr; > } > + > +int fwts_log_scan(fwts_framework *fw, > + fwts_list *log, > + fwts_log_scan_func scan_func, > + fwts_log_progress_func progress_func, > + void *private, > + int *match, > + bool remove_timestamp) > +{ > + typedef struct { > + char *line; > + int repeated; > + } log_reduced_item; > + > + char *prev; > + fwts_list_link *item; > + fwts_list *log_reduced; > + int i; > + char *newline = NULL; > + > + *match = 0; > + > + if (!log) > + return FWTS_ERROR; > + > + if ((log_reduced = fwts_list_new()) == NULL) > + return FWTS_ERROR; > + > + /* > + * Form a reduced log by stripping out repeated warnings > + */ > + i = 0; > + fwts_list_foreach(item, log) { > + if (remove_timestamp) { > + newline = fwts_log_remove_timestamp(fwts_list_data(char *, item)); > + } else { > + newline = fwts_list_data(char *, item); > + } > + > + if (progress_func && ((i % 25) == 0)) > + progress_func(fw, 50 * i / fwts_list_len(log)); > + if (*newline) { > + bool matched = false; > + fwts_list_link *l; > + fwts_list_foreach(l, log_reduced) { > + char *line; > + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, l); > + > + if (remove_timestamp) > + line = fwts_log_remove_timestamp(reduced->line); > + else > + line = reduced->line; > + > + if (strcmp(newline, line) == 0) { > + reduced->repeated++; > + matched = true; > + break; > + } > + } > + if (!matched) { > + log_reduced_item *new; > + > + if ((new = calloc(1, sizeof(log_reduced_item))) == NULL) { > + fwts_list_free(log_reduced, free); > + return FWTS_ERROR; > + } > + new->line = fwts_list_data(char *, item); > + new->repeated = 0; > + > + fwts_list_append(log_reduced, new); > + } > + } > + i++; > + } > + > + prev = ""; > + > + i = 0; > + fwts_list_foreach(item, log_reduced) { > + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, item); > + char *line = reduced->line; > + > + if ((line[0] == '<') && (line[2] == '>')) > + line += 3; > + > + scan_func(fw, line, reduced->repeated, prev, private, match); > + if (progress_func && ((i % 25) == 0)) > + progress_func(fw, (50+(50 * i)) / fwts_list_len(log_reduced)); > + prev = line; > + i++; > + } > + if (progress_func) > + progress_func(fw, 100); > + > + fwts_list_free(log_reduced, free); > + > + return FWTS_OK; > +} > Acked-by: Colin Ian King <colin.king@canonical.com>
On 2018-06-20 05:14 AM, Marcello Sylvester Bauer wrote: > Note: boolean remove_timestamp has been added as argument. > > Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> > --- > src/lib/include/fwts_log_scan.h | 4 ++ > src/lib/src/fwts_klog.c | 79 +-------------------------------- > src/lib/src/fwts_log_scan.c | 98 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 103 insertions(+), 78 deletions(-) > > diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h > index e08d0aac..31fa3f7e 100644 > --- a/src/lib/include/fwts_log_scan.h > +++ b/src/lib/include/fwts_log_scan.h > @@ -38,8 +38,12 @@ typedef struct { > bool compiled_ok; > } fwts_log_pattern; > > +typedef void (*fwts_log_progress_func)(fwts_framework *fw, int percent); > +typedef void (*fwts_log_scan_func)(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors); > + > void fwts_log_free(fwts_list *list); > fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new); > char *fwts_log_remove_timestamp(char *text); > +int fwts_log_scan(fwts_framework *fw, fwts_list *log, fwts_log_scan_func callback, fwts_log_progress_func progress, void *private, int *errors, bool remove_timestamp); > > #endif > diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c > index 25491815..94195261 100644 > --- a/src/lib/src/fwts_klog.c > +++ b/src/lib/src/fwts_klog.c > @@ -93,84 +93,7 @@ int fwts_klog_scan(fwts_framework *fw, > void *private, > int *match) > { > - typedef struct { > - char *line; > - int repeated; > - } klog_reduced_item; > - > - char *prev; > - fwts_list_link *item; > - fwts_list *klog_reduced; > - int i; > - > - *match = 0; > - > - if (!klog) > - return FWTS_ERROR; > - > - if ((klog_reduced = fwts_list_new()) == NULL) > - return FWTS_ERROR; > - > - /* > - * Form a reduced log by stripping out repeated kernel warnings > - */ > - i = 0; > - fwts_list_foreach(item, klog) { > - char *newline = fwts_klog_remove_timestamp(fwts_list_data(char *, item)); > - if (progress_func && ((i % 25) == 0)) > - progress_func(fw, 50 * i / fwts_list_len(klog)); > - if (*newline) { > - bool matched = false; > - fwts_list_link *l; > - fwts_list_foreach(l, klog_reduced) { > - char *line; > - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, l); > - > - line = fwts_klog_remove_timestamp(reduced->line); > - if (strcmp(newline, line) == 0) { > - reduced->repeated++; > - matched = true; > - break; > - } > - } > - if (!matched) { > - klog_reduced_item *new; > - > - if ((new = calloc(1, sizeof(klog_reduced_item))) == NULL) { > - fwts_list_free(klog_reduced, free); > - return FWTS_ERROR; > - } > - new->line = fwts_list_data(char *, item); > - new->repeated = 0; > - > - fwts_list_append(klog_reduced, new); > - } > - } > - i++; > - } > - > - prev = ""; > - > - i = 0; > - fwts_list_foreach(item, klog_reduced) { > - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, item); > - char *line = reduced->line; > - > - if ((line[0] == '<') && (line[2] == '>')) > - line += 3; > - > - scan_func(fw, line, reduced->repeated, prev, private, match); > - if (progress_func && ((i % 25) == 0)) > - progress_func(fw, (50+(50 * i)) / fwts_list_len(klog_reduced)); > - prev = line; > - i++; > - } > - if (progress_func) > - progress_func(fw, 100); > - > - fwts_list_free(klog_reduced, free); > - > - return FWTS_OK; > + return fwts_log_scan(fw, klog, scan_func, progress_func, private, match, true); > } > > char *fwts_klog_unique_label(const char *str) > diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c > index f6050fbc..9b9e9457 100644 > --- a/src/lib/src/fwts_log_scan.c > +++ b/src/lib/src/fwts_log_scan.c > @@ -107,3 +107,101 @@ char *fwts_log_remove_timestamp(char *text) > > return ptr; > } > + > +int fwts_log_scan(fwts_framework *fw, > + fwts_list *log, > + fwts_log_scan_func scan_func, > + fwts_log_progress_func progress_func, > + void *private, > + int *match, > + bool remove_timestamp) > +{ > + typedef struct { > + char *line; > + int repeated; > + } log_reduced_item; > + > + char *prev; > + fwts_list_link *item; > + fwts_list *log_reduced; > + int i; > + char *newline = NULL; > + > + *match = 0; > + > + if (!log) > + return FWTS_ERROR; > + > + if ((log_reduced = fwts_list_new()) == NULL) > + return FWTS_ERROR; > + > + /* > + * Form a reduced log by stripping out repeated warnings > + */ > + i = 0; > + fwts_list_foreach(item, log) { > + if (remove_timestamp) { > + newline = fwts_log_remove_timestamp(fwts_list_data(char *, item)); > + } else { > + newline = fwts_list_data(char *, item); > + } > + > + if (progress_func && ((i % 25) == 0)) > + progress_func(fw, 50 * i / fwts_list_len(log)); > + if (*newline) { > + bool matched = false; > + fwts_list_link *l; > + fwts_list_foreach(l, log_reduced) { > + char *line; > + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, l); > + > + if (remove_timestamp) > + line = fwts_log_remove_timestamp(reduced->line); > + else > + line = reduced->line; > + > + if (strcmp(newline, line) == 0) { > + reduced->repeated++; > + matched = true; > + break; > + } > + } > + if (!matched) { > + log_reduced_item *new; > + > + if ((new = calloc(1, sizeof(log_reduced_item))) == NULL) { > + fwts_list_free(log_reduced, free); > + return FWTS_ERROR; > + } > + new->line = fwts_list_data(char *, item); > + new->repeated = 0; > + > + fwts_list_append(log_reduced, new); > + } > + } > + i++; > + } > + > + prev = ""; > + > + i = 0; > + fwts_list_foreach(item, log_reduced) { > + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, item); > + char *line = reduced->line; > + > + if ((line[0] == '<') && (line[2] == '>')) > + line += 3; > + > + scan_func(fw, line, reduced->repeated, prev, private, match); > + if (progress_func && ((i % 25) == 0)) > + progress_func(fw, (50+(50 * i)) / fwts_list_len(log_reduced)); > + prev = line; > + i++; > + } > + if (progress_func) > + progress_func(fw, 100); > + > + fwts_list_free(log_reduced, free); > + > + return FWTS_OK; > +} > Acked-by: Alex Hung <alex.hung@canonical.com>
diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h index e08d0aac..31fa3f7e 100644 --- a/src/lib/include/fwts_log_scan.h +++ b/src/lib/include/fwts_log_scan.h @@ -38,8 +38,12 @@ typedef struct { bool compiled_ok; } fwts_log_pattern; +typedef void (*fwts_log_progress_func)(fwts_framework *fw, int percent); +typedef void (*fwts_log_scan_func)(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors); + void fwts_log_free(fwts_list *list); fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new); char *fwts_log_remove_timestamp(char *text); +int fwts_log_scan(fwts_framework *fw, fwts_list *log, fwts_log_scan_func callback, fwts_log_progress_func progress, void *private, int *errors, bool remove_timestamp); #endif diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c index 25491815..94195261 100644 --- a/src/lib/src/fwts_klog.c +++ b/src/lib/src/fwts_klog.c @@ -93,84 +93,7 @@ int fwts_klog_scan(fwts_framework *fw, void *private, int *match) { - typedef struct { - char *line; - int repeated; - } klog_reduced_item; - - char *prev; - fwts_list_link *item; - fwts_list *klog_reduced; - int i; - - *match = 0; - - if (!klog) - return FWTS_ERROR; - - if ((klog_reduced = fwts_list_new()) == NULL) - return FWTS_ERROR; - - /* - * Form a reduced log by stripping out repeated kernel warnings - */ - i = 0; - fwts_list_foreach(item, klog) { - char *newline = fwts_klog_remove_timestamp(fwts_list_data(char *, item)); - if (progress_func && ((i % 25) == 0)) - progress_func(fw, 50 * i / fwts_list_len(klog)); - if (*newline) { - bool matched = false; - fwts_list_link *l; - fwts_list_foreach(l, klog_reduced) { - char *line; - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, l); - - line = fwts_klog_remove_timestamp(reduced->line); - if (strcmp(newline, line) == 0) { - reduced->repeated++; - matched = true; - break; - } - } - if (!matched) { - klog_reduced_item *new; - - if ((new = calloc(1, sizeof(klog_reduced_item))) == NULL) { - fwts_list_free(klog_reduced, free); - return FWTS_ERROR; - } - new->line = fwts_list_data(char *, item); - new->repeated = 0; - - fwts_list_append(klog_reduced, new); - } - } - i++; - } - - prev = ""; - - i = 0; - fwts_list_foreach(item, klog_reduced) { - klog_reduced_item *reduced = fwts_list_data(klog_reduced_item *, item); - char *line = reduced->line; - - if ((line[0] == '<') && (line[2] == '>')) - line += 3; - - scan_func(fw, line, reduced->repeated, prev, private, match); - if (progress_func && ((i % 25) == 0)) - progress_func(fw, (50+(50 * i)) / fwts_list_len(klog_reduced)); - prev = line; - i++; - } - if (progress_func) - progress_func(fw, 100); - - fwts_list_free(klog_reduced, free); - - return FWTS_OK; + return fwts_log_scan(fw, klog, scan_func, progress_func, private, match, true); } char *fwts_klog_unique_label(const char *str) diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c index f6050fbc..9b9e9457 100644 --- a/src/lib/src/fwts_log_scan.c +++ b/src/lib/src/fwts_log_scan.c @@ -107,3 +107,101 @@ char *fwts_log_remove_timestamp(char *text) return ptr; } + +int fwts_log_scan(fwts_framework *fw, + fwts_list *log, + fwts_log_scan_func scan_func, + fwts_log_progress_func progress_func, + void *private, + int *match, + bool remove_timestamp) +{ + typedef struct { + char *line; + int repeated; + } log_reduced_item; + + char *prev; + fwts_list_link *item; + fwts_list *log_reduced; + int i; + char *newline = NULL; + + *match = 0; + + if (!log) + return FWTS_ERROR; + + if ((log_reduced = fwts_list_new()) == NULL) + return FWTS_ERROR; + + /* + * Form a reduced log by stripping out repeated warnings + */ + i = 0; + fwts_list_foreach(item, log) { + if (remove_timestamp) { + newline = fwts_log_remove_timestamp(fwts_list_data(char *, item)); + } else { + newline = fwts_list_data(char *, item); + } + + if (progress_func && ((i % 25) == 0)) + progress_func(fw, 50 * i / fwts_list_len(log)); + if (*newline) { + bool matched = false; + fwts_list_link *l; + fwts_list_foreach(l, log_reduced) { + char *line; + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, l); + + if (remove_timestamp) + line = fwts_log_remove_timestamp(reduced->line); + else + line = reduced->line; + + if (strcmp(newline, line) == 0) { + reduced->repeated++; + matched = true; + break; + } + } + if (!matched) { + log_reduced_item *new; + + if ((new = calloc(1, sizeof(log_reduced_item))) == NULL) { + fwts_list_free(log_reduced, free); + return FWTS_ERROR; + } + new->line = fwts_list_data(char *, item); + new->repeated = 0; + + fwts_list_append(log_reduced, new); + } + } + i++; + } + + prev = ""; + + i = 0; + fwts_list_foreach(item, log_reduced) { + log_reduced_item *reduced = fwts_list_data(log_reduced_item *, item); + char *line = reduced->line; + + if ((line[0] == '<') && (line[2] == '>')) + line += 3; + + scan_func(fw, line, reduced->repeated, prev, private, match); + if (progress_func && ((i % 25) == 0)) + progress_func(fw, (50+(50 * i)) / fwts_list_len(log_reduced)); + prev = line; + i++; + } + if (progress_func) + progress_func(fw, 100); + + fwts_list_free(log_reduced, free); + + return FWTS_OK; +}
Note: boolean remove_timestamp has been added as argument. Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com> --- src/lib/include/fwts_log_scan.h | 4 ++ src/lib/src/fwts_klog.c | 79 +-------------------------------- src/lib/src/fwts_log_scan.c | 98 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 78 deletions(-)