From: Sobin Thomas <sobin.thomas@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: dominik.karol.piatkowski@intel.com, kamil.konieczny@intel.com
Subject: [PATCH i-g-t 1/1] tests/intel/xe_sysfs_scheduler: Add invalid string test for engine sysfs properties
Date: Thu, 10 Apr 2025 09:17:15 +0000 [thread overview]
Message-ID: <20250410091715.2611957-2-sobin.thomas@intel.com> (raw)
In-Reply-To: <20250410091715.2611957-1-sobin.thomas@intel.com>
This test validates that invalid string inputs are correctly rejected
by engine sysfs write. It ensures that the property values remain
unchanged when invalid inputs are provided.
v6: Fixed string termination logic in generate_random_string. (kamil)
v5: Fixed documentation and fixed error.
v4: Added subtests to test large (4k) random strings (kamil).
Replaced igt macro.
v3: Fixed the test logic. Fixed the tabs
v2: Added error check for return values for igt_sysfs_scanf and
igt_sysfs_printf. Removed the changes for fault injection in
tests/intel/xe_fault_injection.c
v1: Initial changes for checking error string.
Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
Reviewed-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@intel.com>
Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
---
tests/intel/xe_sysfs_scheduler.c | 99 ++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/tests/intel/xe_sysfs_scheduler.c b/tests/intel/xe_sysfs_scheduler.c
index 4fc764f82..faafabd29 100644
--- a/tests/intel/xe_sysfs_scheduler.c
+++ b/tests/intel/xe_sysfs_scheduler.c
@@ -15,6 +15,16 @@
* unrepresentable intervals.
* Test category: negative test
*
+ * SUBTEST: %s-invalid-string
+ * Description: Test to check if %s arg[1] schedule parameter checks for
+ * invalid string values.
+ * Test category: negative test
+ *
+ * SUBTEST: %s-invalid-large-string
+ * Description: Test to check if %s arg[1] schedule parameter checks for
+ * large invalid strings (4k).
+ * Test category: negative test
+ *
* SUBTEST: %s-min-max
* Description: Test to check if %s arg[1] schedule parameter checks for
* min max values.
@@ -39,6 +49,47 @@
#include "xe_drm.h"
#include "xe/xe_query.h"
+#define STR_LENGTH 4096
+
+/**
+ * generate_random_string:
+ * @str: pointer to string buffer that will be having random string generated.
+ * @length: length of string to generate.
+ *
+ * Generates random string that will always contain non-numerical characters.
+ */
+static void generate_random_string(char *str, size_t length)
+{
+ int type = 0;
+ int digit_count = 0;
+ int max_digits = length / 4;
+ int loop_count = length - 1;
+
+ for (size_t i = 0; i < loop_count; i++) {
+ if (digit_count >= max_digits)
+ type = rand() % 2;
+ else
+ type = rand() % 3;
+
+ switch (type) {
+ case 0:
+ str[i] = 'A' + (rand() % 26);
+ break;
+ case 1:
+ str[i] = 'a' + (rand() % 26);
+ break;
+ case 2:
+ str[i] = '0' + (rand() % 10);
+ digit_count++;
+ break;
+ default:
+ str[i] = '_';
+ break;
+ }
+ }
+ str[length - 1] = '\0';
+}
+
static void test_invalid(int xe, int engine, const char **property,
uint16_t class, int gt)
{
@@ -121,6 +172,52 @@ static void test_min_max(int xe, int engine, const char **property,
igt_assert_eq(set, default_max);
}
+static void test_invalid_string(int xe, int engine, const char **property,
+ uint16_t class, int gt)
+{
+ unsigned int saved, set;
+ static const char invalid_input[] = "999abc";
+
+ for (int i = 0; i < 3; i++) {
+ igt_assert_eq(igt_sysfs_scanf(engine, property[i], "%u", &saved), 1);
+ igt_info("Initial %s: %u\n", property[i], saved);
+ /* Assert if the invalid write is returning negative error */
+ igt_assert_lt(igt_sysfs_printf(engine, property[i], "%s",
+ invalid_input), 0);
+
+ igt_assert_eq(igt_sysfs_scanf(engine, property[i], "%u", &set), 1);
+ /* Check if the values are unchanged. */
+ igt_assert_eq(set, saved);
+ }
+}
+
+static void test_invalid_large_string(int xe, int engine, const char **property,
+ uint16_t class, int gt)
+{
+ unsigned int saved, set;
+ char *random_str;
+
+ random_str = (char *)malloc(sizeof(char) * (STR_LENGTH));
+ igt_assert_f(random_str, "Memory allocation failed\n");
+
+ generate_random_string(random_str, STR_LENGTH);
+ igt_debug("Generated random string: %.10s...\n", random_str);
+
+ for (int i = 0; i < 3; i++) {
+ igt_assert_eq(igt_sysfs_scanf(engine, property[i], "%u", &saved), 1);
+ igt_info("Initial %s: %u\n", property[i], saved);
+
+ /* Assert if the invalid write is returning negative error */
+ igt_assert_lt(igt_sysfs_printf(engine, property[i], "%s",
+ random_str), 0);
+
+ igt_assert_eq(igt_sysfs_scanf(engine, property[i], "%u", &set), 1);
+ /* Check if the values are unchanged. */
+ igt_assert_eq(set, saved);
+ }
+ free(random_str);
+}
+
#define MAX_GTS 8
igt_main
{
@@ -129,6 +226,8 @@ igt_main
void (*fn)(int, int, const char **, uint16_t, int);
} tests[] = {
{ "invalid", test_invalid },
+ { "invalid-string", test_invalid_string },
+ { "invalid-large-string", test_invalid_large_string },
{ "min-max", test_min_max },
{ }
};
--
2.34.1
next prev parent reply other threads:[~2025-04-10 9:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-10 9:17 [PATCH v6 i-g-t 0/1] tests/intel/xe_sysfs_scheduler: Add invalid string test for engine sysfs properties Sobin Thomas
2025-04-10 9:17 ` Sobin Thomas [this message]
2025-04-11 12:20 ` [PATCH i-g-t 1/1] " Kamil Konieczny
2025-04-10 10:59 ` ✓ i915.CI.BAT: success for tests/intel/xe_sysfs_scheduler: Add invalid string test for engine sysfs properties (rev4) Patchwork
2025-04-10 11:25 ` ✓ Xe.CI.BAT: " Patchwork
2025-04-10 17:41 ` ✗ i915.CI.Full: failure " Patchwork
2025-04-11 2:50 ` Thomas, Sobin
2025-04-14 10:05 ` ✗ Xe.CI.Full: " Patchwork
2025-04-14 10:53 ` Thomas, Sobin
-- strict thread matches above, loose matches on Subject: below --
2025-04-08 4:18 [PATCH v4 i-g-t 0/1] tests/intel/xe_sysfs_scheduler: Add invalid string test for engine sysfs properties Sobin Thomas
2025-04-08 4:18 ` [PATCH i-g-t 1/1] " Sobin Thomas
2025-04-08 9:32 ` Piatkowski, Dominik Karol
2025-03-31 14:27 [PATCH v2 " replace_with Sobin Thomas
2025-03-31 14:27 ` [PATCH " replace_with Sobin Thomas
2025-04-01 9:44 ` Piatkowski, Dominik Karol
2025-04-01 13:21 ` Kamil Konieczny
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=20250410091715.2611957-2-sobin.thomas@intel.com \
--to=sobin.thomas@intel.com \
--cc=dominik.karol.piatkowski@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.