diff options
| author | Mark Brown <broonie@kernel.org> | 2026-10-01 15:39:05 +0100 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2026-10-01 15:39:05 +0100 |
| commit | f988a4e74b84aff868a2dd9f8c734716db12815d (patch) | |
| tree | 5733435d58dc4172fc2098523839ddd6c391f06b /tools/testing/selftests | |
| parent | bbfd5527b72274c67cdcabc032e675c2f6675b23 (diff) | |
| parent | b39049c04ce69cbc039a4b002c911d7a9768a213 (diff) | |
| download | linux-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.c | 45 | ||||
| -rw-r--r-- | tools/testing/selftests/cgroup/settings | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/cgroup/test_cpu.c | 5 | ||||
| -rwxr-xr-x | tools/testing/selftests/cgroup/with_stress.sh | 2 |
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)) |
