Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: jonathan.cavitt@intel.com, saurabhg.gupta@intel.com,
	alex.zuo@intel.com, kamil.konieczny@linux.intel.com,
	vinay.belgaumkar@intel.com
Subject: [PATCH v7 4/4] tests/intel/xe_sysfs_scheduler: Assert sysfs params are restored
Date: Mon, 18 Nov 2024 18:05:11 +0000	[thread overview]
Message-ID: <20241118180511.64212-5-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20241118180511.64212-1-jonathan.cavitt@intel.com>

The xe_sysfs_scheduler tests modify various sysfs parameters.  At the
end of the test, the sysfs parameters are restored, but we do not
currently assert that the restoration process completes successfully.
Assert the restoration is successful.

Additionally, when the tests fail, it is possible that the various
modified sysfs parameters may be left in modified states, which can
cause future tests to behave unpredictably.  At the end of the test,
attempt to restore all modified sysfs parameters to their original
values, aborting all tests if this is unsuccessful.

Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
 tests/intel/xe_sysfs_scheduler.c | 82 ++++++++++++++++++++++++++++----
 1 file changed, 72 insertions(+), 10 deletions(-)

diff --git a/tests/intel/xe_sysfs_scheduler.c b/tests/intel/xe_sysfs_scheduler.c
index 947dbdbc9b..9e04b5c418 100644
--- a/tests/intel/xe_sysfs_scheduler.c
+++ b/tests/intel/xe_sysfs_scheduler.c
@@ -107,10 +107,19 @@ static void test_min_max(int xe, int engine, const char **property,
 
 	/* Reset property, max, min to original values */
 	igt_sysfs_printf(engine, property[0], "%d", store);
+	igt_sysfs_scanf(engine, property[0], "%u", &set);
+	igt_assert_eq(set, store);
+
 	igt_sysfs_printf(engine, property[1], "%d", default_min);
+	igt_sysfs_scanf(engine, property[1], "%u", &set);
+	igt_assert_eq(set, default_min);
+
 	igt_sysfs_printf(engine, property[2], "%d", default_max);
+	igt_sysfs_scanf(engine, property[2], "%u", &set);
+	igt_assert_eq(set, default_max);
 }
 
+#define MAX_GTS 8
 igt_main
 {
 	static const struct {
@@ -126,10 +135,14 @@ igt_main
 				      {"timeslice_duration_us", "timeslice_duration_min", "timeslice_duration_max"},
 				      {"job_timeout_ms", "job_timeout_min", "job_timeout_max"},
 	};
+
+	unsigned int store[MAX_GTS][3][3];
 	int count = sizeof(property) / sizeof(property[0]);
+	int gt_count = 0;
 	int xe = -1;
 	int sys_fd;
 	int gt;
+	int engines_fd[MAX_GTS], gt_fd[MAX_GTS];
 
 	igt_fixture {
 		xe = drm_open_driver(DRIVER_XE);
@@ -138,28 +151,77 @@ igt_main
 		sys_fd = igt_sysfs_open(xe);
 		igt_require(sys_fd != -1);
 		close(sys_fd);
+
+		xe_for_each_gt(xe, gt) {
+			int *list, size;
+			igt_require(gt_count < MAX_GTS);
+
+			gt_fd[gt_count] = xe_sysfs_gt_open(xe, gt);
+			igt_require(gt_fd[gt_count] != -1);
+			engines_fd[gt_count] = openat(gt_fd[gt_count], "engines", O_RDONLY);
+			igt_require(engines_fd[gt_count] != -1);
+
+			list = igt_sysfs_get_engine_list(engines_fd[gt_count], &size);
+			igt_require(size > 0);
+
+			for (int i = 0; i < size; i++) {
+				for (int j = 0; j < count; j++) {
+					const char **pl = property[j];
+					for (int k = 0; k < 3; k++) {
+						unsigned int *loc = &store[i][j][k];
+
+						igt_require(igt_sysfs_scanf(list[i], pl[k],
+									    "%u", loc) == 1);
+					}
+				}
+			}
+
+			igt_sysfs_free_engine_list(list, size);
+			gt_count++;
+		}
 	}
 
 	for (int i = 0; i < count; i++) {
 		for (typeof(*tests) *t = tests; t->name; t++) {
 			igt_subtest_with_dynamic_f("%s-%s", property[i][0], t->name) {
+				int j = 0;
 				xe_for_each_gt(xe, gt) {
-					int engines_fd = -1;
-					int gt_fd = -1;
+					int e = engines_fd[j];
 
-					gt_fd = xe_sysfs_gt_open(xe, gt);
-					igt_require(gt_fd != -1);
-					engines_fd = openat(gt_fd, "engines", O_RDONLY);
-					igt_require(engines_fd != -1);
-
-					igt_sysfs_engines(xe, engines_fd, 0, 0, property[i], t->fn);
-					close(engines_fd);
-					close(gt_fd);
+					igt_sysfs_engines(xe, e, 0, 0, property[i], t->fn);
+					j++;
 				}
 			}
 		}
 	}
+
 	igt_fixture {
+		for (int gtn = gt_count - 1; gtn >= 0; gtn--) {
+			int *list, size;
+			list = igt_sysfs_get_engine_list(engines_fd[gtn], &size);
+
+			for (int i = size - 1; i >= 0; i--) {
+				int e = list[i];
+				for (int j = count - 1; j >= 0; j--) {
+					const char **pl = property[j];
+					for (int k = 2; k >= 0; k--) {
+						unsigned int read = UINT_MAX;
+						unsigned int val = store[i][j][k];
+
+						igt_assert_lte(0, igt_sysfs_printf(e, pl[k],
+									           "%u", val));
+						igt_sysfs_scanf(e, pl[k], "%u", &read);
+						igt_abort_on_f(read != val,
+							       "%s not restored!\n", pl[k]);
+					}
+				}
+			}
+
+			igt_sysfs_free_engine_list(list, size);
+			close(engines_fd[gtn]);
+			close(gt_fd[gtn]);
+		}
+				
 		xe_device_put(xe);
 		close(xe);
 	}
-- 
2.43.0


  parent reply	other threads:[~2024-11-18 18:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-18 18:05 [PATCH v7 0/4] test/intel/xe_sysfs: Restore sysfs params correctly Jonathan Cavitt
2024-11-18 18:05 ` [PATCH v7 1/4] lib/igt_sysfs: Add engine list helpers Jonathan Cavitt
2024-11-26 17:06   ` Kamil Konieczny
2024-12-02 16:32     ` Cavitt, Jonathan
2024-11-18 18:05 ` [PATCH v7 2/4] tests/intel/xe_sysfs*: Restore values on test failure Jonathan Cavitt
2024-11-26 16:55   ` Kamil Konieczny
2024-12-02 15:13     ` Cavitt, Jonathan
2024-11-18 18:05 ` [PATCH v7 3/4] tests/intel/xe_sysfs_timeslice_duration: Restore preempt timeout Jonathan Cavitt
2024-11-18 18:05 ` Jonathan Cavitt [this message]
2024-11-26 17:15   ` [PATCH v7 4/4] tests/intel/xe_sysfs_scheduler: Assert sysfs params are restored Kamil Konieczny
2024-11-19  3:20 ` ✓ CI.xeBAT: success for test/intel/xe_sysfs: Restore sysfs params correctly Patchwork
2024-11-19  3:34 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-11-19 16:34 ` ✗ CI.xeFULL: " 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=20241118180511.64212-5-jonathan.cavitt@intel.com \
    --to=jonathan.cavitt@intel.com \
    --cc=alex.zuo@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=saurabhg.gupta@intel.com \
    --cc=vinay.belgaumkar@intel.com \
    /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