On Mon, Aug 04, 2025 at 08:29:42PM -0700, Tiffany Yang ynaffit@google.com wrote:
+static int test_cgfreezer_time_empty(const char *root) +{
- int ret = KSFT_FAIL;
- char *cgroup = NULL;
- long prev, curr;
- int i;
- cgroup = cg_name(root, "cg_time_test_empty");
- if (!cgroup)
goto cleanup;
- /*
* 1) Create an empty cgroup and check that its freeze time
* is 0.
*/
- if (cg_create(cgroup))
goto cleanup;
- curr = cg_check_freezetime(cgroup);
- if (curr) {
if (curr < 0)
ret = KSFT_SKIP;
else
debug("Expect time (%ld) to be 0\n", curr);
goto cleanup;
- }
if (curr < 0) { ret = KSFT_SKIP; goto cleanup; } if (curr > 0) { debug("Expect time (%ld) to be 0\n", curr); goto cleanup; }
I might like the version with less indentation and explicit guards. It's only minor stylistic issue.
- /*
* 2) Freeze the cgroup. Check that its freeze time is
* larger than 0.
*/
- if (cg_freeze_nowait(cgroup, true))
goto cleanup;
- prev = curr;
- curr = cg_check_freezetime(cgroup);
- if (curr <= prev) {
Here and...
debug("Expect time (%ld) > 0\n", curr);
goto cleanup;
- }
- /*
* 3) Sleep for 100 us. Check that the freeze time is at
* least 100 us larger than it was at 2).
*/
- usleep(100);
- prev = curr;
- curr = cg_check_freezetime(cgroup);
- if ((curr - prev) < 100) {
...here I'm slightly worried it may cause test flakiness on systems with too coarse clock granularity.
Is the first check anyhow meaningful? (I think it's only as strong as checking return value of the preceding write(2) to cgroup.freeze.)
Would it compromise your use case if the latter check was at least 1000 μs (based on other usleeps in cgroup selftests)? (Ditto for other 100 μs checks.)
Or does anything guarantee the minimal precision in common selftest environments?
Thanks, Michal