public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/3] runner: Refactor metadata parsing
Date: Mon,  1 Apr 2019 09:46:56 +0300	[thread overview]
Message-ID: <20190401064657.23322-2-arkadiusz.hiler@intel.com> (raw)
In-Reply-To: <20190401064657.23322-1-arkadiusz.hiler@intel.com>

To aid testing function parsing metadata.txt is split into outer helper
that operates on dirfd and inner function that operates on FILE*.

This allows us to test the parsing using fmemopen(), limiting the amount
of necessary boilerplate.

Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
---
 runner/executor.c     |  2 +-
 runner/resultgen.c    |  2 +-
 runner/runner_tests.c |  2 +-
 runner/settings.c     | 40 ++++++++++++++++++++++++++--------------
 runner/settings.h     |  4 +++-
 5 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/runner/executor.c b/runner/executor.c
index a40e2dd1..0e91b7ab 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -1112,7 +1112,7 @@ bool initialize_execute_state_from_resume(int dirfd,
 	memset(state, 0, sizeof(*state));
 	state->resuming = true;
 
-	if (!read_settings(settings, dirfd) ||
+	if (!read_settings_from_dir(settings, dirfd) ||
 	    !read_job_list(list, dirfd)) {
 		close(dirfd);
 		return false;
diff --git a/runner/resultgen.c b/runner/resultgen.c
index 73fda64f..40d1cfcc 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -1085,7 +1085,7 @@ struct json_object *generate_results_json(int dirfd)
 	init_settings(&settings);
 	init_job_list(&job_list);
 
-	if (!read_settings(&settings, dirfd)) {
+	if (!read_settings_from_dir(&settings, dirfd)) {
 		fprintf(stderr, "resultgen: Cannot parse settings\n");
 		return NULL;
 	}
diff --git a/runner/runner_tests.c b/runner/runner_tests.c
index e46568ac..06725536 100644
--- a/runner/runner_tests.c
+++ b/runner/runner_tests.c
@@ -680,7 +680,7 @@ igt_main
 				     "Opening %s/metadata.txt failed\n", dirname);
 			close(fd);
 
-			igt_assert_f(read_settings(&cmp_settings, dirfd), "Reading settings failed\n");
+			igt_assert_f(read_settings_from_dir(&cmp_settings, dirfd), "Reading settings failed\n");
 			assert_settings_equal(&settings, &cmp_settings);
 		}
 
diff --git a/runner/settings.c b/runner/settings.c
index e64244e6..20b21378 100644
--- a/runner/settings.c
+++ b/runner/settings.c
@@ -540,7 +540,7 @@ bool serialize_settings(struct settings *settings)
 #undef SERIALIZE_LINE
 }
 
-bool read_settings(struct settings *settings, int dirfd)
+bool read_settings_from_file(struct settings *settings, FILE *f)
 {
 #define PARSE_LINE(s, name, val, field, write) \
 	if (!strcmp(name, #field)) {	       \
@@ -551,20 +551,8 @@ bool read_settings(struct settings *settings, int dirfd)
 		continue;		       \
 	}
 
-	int fd;
-	FILE *f;
 	char *name = NULL, *val = NULL;
 
-	free_settings(settings);
-
-	if ((fd = openat(dirfd, settings_filename, O_RDONLY)) < 0)
-		return false;
-
-	f = fdopen(fd, "r");
-	if (!f) {
-		close(fd);
-		return false;
-	}
 
 	while (fscanf(f, "%ms : %ms", &name, &val) == 2) {
 		int numval = atoi(val);
@@ -592,9 +580,33 @@ bool read_settings(struct settings *settings, int dirfd)
 
 	free(name);
 	free(val);
-	fclose(f);
 
 	return true;
 
 #undef PARSE_LINE
 }
+
+bool read_settings_from_dir(struct settings *settings, int dirfd)
+{
+	int fd;
+	FILE *f;
+
+
+	free_settings(settings);
+
+	if ((fd = openat(dirfd, settings_filename, O_RDONLY)) < 0)
+		return false;
+
+	f = fdopen(fd, "r");
+	if (!f) {
+		close(fd);
+		return false;
+	}
+
+	if (!read_settings_from_file(settings, f))
+		return false;
+
+	fclose(f);
+
+	return true;
+}
diff --git a/runner/settings.h b/runner/settings.h
index 267d72cf..ae90897c 100644
--- a/runner/settings.h
+++ b/runner/settings.h
@@ -5,6 +5,7 @@
 #include <stddef.h>
 #include <sys/types.h>
 #include <regex.h>
+#include <stdio.h>
 
 enum {
 	LOG_LEVEL_NORMAL = 0,
@@ -114,6 +115,7 @@ char *absolute_path(char *path);
  */
 bool serialize_settings(struct settings *settings);
 
-bool read_settings(struct settings *settings, int dirfd);
+bool read_settings_from_file(struct settings *settings, FILE* f);
+bool read_settings_from_dir(struct settings *settings, int dirfd);
 
 #endif
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-04-01  6:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01  6:46 [igt-dev] [PATCH i-g-t 1/3] runner: Reinitialize compiled dmesg regexp each parsing session Arkadiusz Hiler
2019-04-01  6:46 ` Arkadiusz Hiler [this message]
2019-04-01 10:24   ` [igt-dev] [PATCH i-g-t 2/3] runner: Refactor metadata parsing Petri Latvala
2019-04-01  6:46 ` [igt-dev] [PATCH i-g-t 3/3] runner: Add --dmesg-warn-level switch Arkadiusz Hiler
2019-04-01 11:10   ` Petri Latvala
2019-04-01  7:20 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] runner: Reinitialize compiled dmesg regexp each parsing session Patchwork
2019-04-01  7:23 ` [igt-dev] [PATCH i-g-t 1/3] " Ser, Simon
2019-04-01  8:16 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/3] " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190401064657.23322-2-arkadiusz.hiler@intel.com \
    --to=arkadiusz.hiler@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox