[LTP] mem/min_free_kbytes: Fix incorrect pass/fail accounting

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Wed Jul 8 17:25:34 CEST 2026


Hi Sachin,

On Wed, 08 Jul 2026 18:12:05 +0530, Sachin Sant wrote:
> mem/min_free_kbytes: Fix incorrect pass/fail accounting

> @@ -57,8 +57,7 @@ static void min_free_kbytes_test(void)
>  	pid = SAFE_FORK();
>  	if (pid == 0) {
>  		/* startup the check monitor */
> -		check_monitor();
> -		exit(0);
> +		exit(check_monitor());
>  	}

> +	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
> +		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
> +			tst_res(TFAIL, "MemFree dropped below min_free_kbytes");
> +		else
> +			tst_res(TFAIL, "check_monitor child failed: %s",
> +				tst_strstatus(status));
> +	} else {
> +		tst_res(TPASS, "min_free_kbytes test pass");
> +	}

The fix works in practice, but the design trades one problem for another:
encoding pass/fail as a child exit code and interpreting it in the parent
is explicitly the pattern LTP asks to avoid.

The test already sets .forks_child = 1, so the framework's shared-memory
result propagation is active.  tst_res() calls made inside check_monitor()
are automatically visible to the parent's result accounting -- no exit-code
relay needed.

> -static void check_monitor(void)
> +static int check_monitor(void)
>  {
> +	int violated = 0;

The 'violated' flag is fine for deciding when to emit the TINFO line, but
the TPASS/TFAIL themselves should be emitted by the child rather than
signalled through exit():

  if (violated)
      tst_res(TFAIL, "MemFree dropped below min_free_kbytes");
  else
      tst_res(TPASS, "min_free_kbytes test pass");

With that, check_monitor() returns void and the child exits 0 always.
The parent's wait block only needs to guard against truly unexpected
termination (signal, unknown non-zero exit), and must not re-emit a
TPASS/TFAIL for the violation outcome:

  SAFE_KILL(pid, SIGUSR1);
  SAFE_WAITPID(pid, &status, WUNTRACED | WCONTINUED);

  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
      tst_res(TFAIL, "check_monitor child failed: %s",
          tst_strstatus(status));
  /* pass/fail already reported by the child */

This also solves the original double-accounting bug because the parent
no longer emits any result for the monitor outcome at all.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer


More information about the ltp mailing list