summaryrefslogtreecommitdiff
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2026-10-01 15:39:05 +0100
committerMark Brown <broonie@kernel.org>2026-10-01 15:39:05 +0100
commitf988a4e74b84aff868a2dd9f8c734716db12815d (patch)
tree5733435d58dc4172fc2098523839ddd6c391f06b /tools/testing/selftests
parentbbfd5527b72274c67cdcabc032e675c2f6675b23 (diff)
parentb39049c04ce69cbc039a4b002c911d7a9768a213 (diff)
downloadlinux-next-f988a4e74b84aff868a2dd9f8c734716db12815d.tar.gz
linux-next-f988a4e74b84aff868a2dd9f8c734716db12815d.zip
Merge branch 'for-next' of https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/cgroup/lib/cgroup_util.c45
-rw-r--r--tools/testing/selftests/cgroup/settings1
-rw-r--r--tools/testing/selftests/cgroup/test_cpu.c5
-rwxr-xr-xtools/testing/selftests/cgroup/with_stress.sh2
4 files changed, 43 insertions, 10 deletions
diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testing/selftests/cgroup/lib/cgroup_util.c
index 2596c12cd864..cd73471e13d7 100644
--- a/tools/testing/selftests/cgroup/lib/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c
@@ -24,20 +24,43 @@ bool cg_test_v1_named;
/* Returns read len on success, or -errno on failure. */
ssize_t read_text(const char *path, char *buf, size_t max_len)
{
- ssize_t len;
+ size_t total = 0;
+ ssize_t len, ret;
int fd;
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
- len = read(fd, buf, max_len - 1);
-
- if (len >= 0)
- buf[len] = 0;
+ /*
+ * A single read() is not enough. procfs and sysfs are backed by
+ * seq_file, and seq_read_iter() copies out at most one internal
+ * buffer (PAGE_SIZE) per call, leaving the rest for the next read().
+ * Reading only once therefore silently drops everything past the
+ * first page, no matter how big the caller's buffer is.
+ *
+ * Loop until the buffer is full or EOF. A full buffer still means
+ * the file may be longer than max_len, but that is now limited by
+ * the caller's buffer rather than by a page of seq_file output.
+ */
+ while (total < max_len - 1) {
+ len = read(fd, buf + total, max_len - 1 - total);
+ if (len < 0) {
+ if (errno == EINTR)
+ continue;
+ ret = -errno;
+ goto out;
+ }
+ if (!len)
+ break;
+ total += len;
+ }
+ buf[total] = 0;
+ ret = total;
+out:
close(fd);
- return len < 0 ? -errno : len;
+ return ret;
}
/* Returns written len on success, or -errno on failure. */
@@ -279,6 +302,16 @@ static int cg_find_root(char *root, size_t len, const char *controller,
options = strtok(NULL, delim);
strtok(NULL, delim);
strtok(NULL, delim);
+
+ /*
+ * A mount entry is "device mountpoint type options freq
+ * passno". A field can only be missing if the last entry was
+ * cut short by the buffer being too small for the file, and
+ * there is no complete entry left to look at.
+ */
+ if (!mount || !type || !options)
+ break;
+
if (strcmp(type, "cgroup") == 0) {
if (!controller || !strstr(options, controller))
continue;
diff --git a/tools/testing/selftests/cgroup/settings b/tools/testing/selftests/cgroup/settings
new file mode 100644
index 000000000000..6091b45d226b
--- /dev/null
+++ b/tools/testing/selftests/cgroup/settings
@@ -0,0 +1 @@
+timeout=120
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index 735a53bb222b..3456e3e988c6 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -835,9 +835,8 @@ int main(int argc, char *argv[])
if (cg_find_unified_root(root, sizeof(root), NULL))
ksft_exit_skip("cgroup v2 isn't mounted\n");
- if (cg_read_strstr(root, "cgroup.subtree_control", "cpu"))
- if (cg_write(root, "cgroup.subtree_control", "+cpu"))
- ksft_exit_skip("Failed to set cpu controller\n");
+ if (cg_write(root, "cgroup.subtree_control", "+cpu"))
+ ksft_exit_skip("Failed to set cpu controller\n");
ksft_set_plan(ARRAY_SIZE(tests));
for (i = 0; i < ARRAY_SIZE(tests); i++) {
diff --git a/tools/testing/selftests/cgroup/with_stress.sh b/tools/testing/selftests/cgroup/with_stress.sh
index e28c35008f5b..a95fb3874644 100755
--- a/tools/testing/selftests/cgroup/with_stress.sh
+++ b/tools/testing/selftests/cgroup/with_stress.sh
@@ -87,7 +87,7 @@ time=0
start=$(date +%s)
while [ $time -lt $duration ] ; do
- $*
+ "$@"
rc=$?
[ $rc -eq 0 ] || break
time=$(($(date +%s) - $start))