[PATCH 07/20] fwts_log_scan: move fwts_log_scan_patterns

Marcello Sylvester Bauer info at marcellobauer.com
Wed Jun 20 12:14:33 UTC 2018


Note: log message name and fallback advice has been added as arguments.

Signed-off-by: Marcello Sylvester Bauer <info at marcellobauer.com>
---
 src/lib/include/fwts_log_scan.h |  1 +
 src/lib/src/fwts_klog.c         | 52 +++----------------------------------
 src/lib/src/fwts_log_scan.c     | 57 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 48 deletions(-)

diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h
index ac56dba2..0f03d336 100644
--- a/src/lib/include/fwts_log_scan.h
+++ b/src/lib/include/fwts_log_scan.h
@@ -46,5 +46,6 @@ 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);
 char *fwts_log_unique_label(const char *str, const char *label);
+void       fwts_log_scan_patterns(fwts_framework *fw, char *line, int repeated, char *prevline, void *private, int *errors, const char *name, const char *advice);
 
 #endif
diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index cfb76d7f..48ebf13b 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -113,55 +113,11 @@ void fwts_klog_scan_patterns(fwts_framework *fw,
 	void *private,
 	int *errors)
 {
-	fwts_log_pattern *pattern = (fwts_log_pattern *)private;
-	static char *advice =
-		"This is a bug picked up by the kernel, but as yet, the "
-		"firmware test suite has no diagnostic advice for this particular problem.";
-
-	FWTS_UNUSED(prevline);
-
-	while (pattern->pattern != NULL) {
-		bool matched = false;
-		switch (pattern->compare_mode) {
-		case FWTS_COMPARE_REGEX:
-			if (pattern->compiled_ok) {
-				int ret = regexec(&pattern->compiled, line, 0, NULL, 0);
-				if (!ret) {
-					/* A successful regular expression match! */
-					matched = true;
-				} else if (ret != REG_NOMATCH) {
-					char msg[1024];
-
-					regerror(ret, &pattern->compiled, msg, sizeof(msg));
-					fwts_log_info(fw, "regular expression engine error: %s.", msg);
-				}
-			}
-			break;
-		case FWTS_COMPARE_STRING:
-		default:
-			matched = (strstr(line, pattern->pattern) != NULL) ;
-			break;
-		}
+    static char *advice =
+        "This is a bug picked up by the kernel, but as yet, the "
+        "firmware test suite has no diagnostic advice for this particular problem.";
 
-		if (matched) {
-			if (pattern->level == LOG_LEVEL_INFO)
-				fwts_log_info(fw, "Kernel message: %s", line);
-			else {
-				fwts_failed(fw, pattern->level, pattern->label,
-					"%s Kernel message: %s", fwts_log_level_to_str(pattern->level), line);
-				fwts_error_inc(fw, pattern->label, errors);
-			}
-			if (repeated)
-				fwts_log_info(fw, "Message repeated %d times.", repeated);
-
-			if ((pattern->advice) != NULL && (*pattern->advice))
-				fwts_advice(fw, "%s", pattern->advice);
-			else
-				fwts_advice(fw, "%s", advice);
-			return;
-		}
-		pattern++;
-	}
+    fwts_log_scan_patterns(fw, line, repeated, prevline, private, errors, "Kernel", advice);
 }
 
 /*
diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c
index d9c2ac1e..40611a36 100644
--- a/src/lib/src/fwts_log_scan.c
+++ b/src/lib/src/fwts_log_scan.c
@@ -239,3 +239,60 @@ char *fwts_log_unique_label(const char *str, const char *label)
         *dst = '\0';
         return buffer;
 }
+
+void fwts_log_scan_patterns(fwts_framework *fw,
+        char *line,
+        int  repeated,
+        char *prevline,
+        void *private,
+        int *errors,
+        const char *name,
+        const char *advice)
+{
+        fwts_log_pattern *pattern = (fwts_log_pattern *)private;
+
+        FWTS_UNUSED(prevline);
+
+        while (pattern->pattern != NULL) {
+                bool matched = false;
+                switch (pattern->compare_mode) {
+                case FWTS_COMPARE_REGEX:
+                        if (pattern->compiled_ok) {
+                                int ret = regexec(&pattern->compiled, line, 0, NULL, 0);
+                                if (!ret) {
+                                        /* A successful regular expression match! */
+                                        matched = true;
+                                } else if (ret != REG_NOMATCH) {
+                                        char msg[1024];
+
+                                        regerror(ret, &pattern->compiled, msg, sizeof(msg));
+                                        fwts_log_info(fw, "regular expression engine error: %s.", msg);
+                                }
+                        }
+                        break;
+                case FWTS_COMPARE_STRING:
+                default:
+                        matched = (strstr(line, pattern->pattern) != NULL) ;
+                        break;
+                }
+
+                if (matched) {
+                        if (pattern->level == LOG_LEVEL_INFO)
+                                fwts_log_info(fw, "%s message: %s", name, line);
+                        else {
+                                fwts_failed(fw, pattern->level, pattern->label,
+                                        "%s %s message: %s", fwts_log_level_to_str(pattern->level), name, line);
+                                fwts_error_inc(fw, pattern->label, errors);
+                        }
+                        if (repeated)
+                                fwts_log_info(fw, "Message repeated %d times.", repeated);
+
+                        if ((pattern->advice) != NULL && (*pattern->advice))
+                                fwts_advice(fw, "%s", pattern->advice);
+                        else
+                                fwts_advice(fw, "%s", advice);
+                        return;
+                }
+                pattern++;
+        }
+}
-- 
2.16.4




More information about the fwts-devel mailing list