[LTP] [PATCH] syscalls/brk: add direct syscall tst_variant

Petr Vorel pvorel@suse.cz
Tue Dec 6 15:04:21 CET 2022


Hi Teo,

> Direct usage of brk is discouraged in favor of using malloc. Also, brk was
> removed from POSIX in POSIX.1-2001.
> In particular, the Musl libc's brk always returns -ENOMEM which causes
> the LTP tests to exit prematurely. Invoking the syscall directly allows
> them to properly validate brk behavior. Add a new test variant handling if
> the libc wrappers are not implemented and testing the direct syscall.

> Use tst_syscall() and handle the failure cases ourselves, as
> we don't depend on the libc to do it anymore.

> The patch also works around the dependency on sbrk to get the current break
> as it has the same issues. Instead, call tst_syscall(__NR_brk, 0) which
> always returns the current break.

> Update brk01 to use void* to unify it with brk02.
That brought warnings, see below.

...
> +++ b/testcases/kernel/syscalls/brk/brk02.c
> @@ -14,24 +14,51 @@
>  #include <unistd.h>
>  #include <sys/mman.h>
>  #include "tst_test.h"
> +#include "lapi/syscalls.h"
> +
> +inline void *brk_variants(void *addr)
> +{
> +	void *brk_addr;
> +	if (tst_variant) {
> +		brk_addr = (void *)tst_syscall(__NR_brk, addr);
> +	} else {
> +		brk_addr = (void *)brk(addr);

NOTE using pointer for brk() is problematic, there are complains:

brk02.c: In function ‘brk_variants’:
brk02.c:26:28: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
   26 |                 brk_addr = (void *)brk(addr);
         |                            ^

Not sure how to fix this. Problem is in both C files, on several places.

There are also code style problems (you can see it when running make check in
testcases/kernel/syscalls/brk/), but that's a minor detail.

Kind regards,
Petr


More information about the ltp mailing list