[LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process

Li Wang liwang@redhat.com
Thu Feb 20 03:08:07 CET 2025


On Thu, Feb 20, 2025 at 12:45 AM Petr Vorel <pvorel@suse.cz> wrote:

> Hi Chunfu Wen,
>
> Besides Andrea's comments, there are other things to improve.
>
>
> > The test ensures that the process gets the correct signals in the
> correct order:
>
> > First, it should get SIGXCPU after reaching the soft CPU time limit64.
> > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL
>
> > Signed-off-by: chunfuwen <chwen@redhat.com>
> > ---
> > Changes in v2:
> > - Romove test descriptions and trailing line as suggested by Ricardo B.
> Marlière
> > - Added 2025 copyright as suggested by Ricardo B. Marlière
> > - Trim down include files as suggested by Ricardo B. Marlière
> > - Create new lapi/resource.h residing struct rlimit64 as suggested by
> Andrea
> > - Move setrlimit_u64() syscalls definitions into lapi/resource.h as
> suggested by Andrea
> > - Skip  SAFE_* variants as suggested by Andrea
> > - use tst_buffers when passing the pointeras suggested by Andrea
> > - Link to v1:
> https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/
> > ---
> >  include/lapi/resource.h                       |  26 ++++
> >  .../kernel/syscalls/setrlimit/setrlimit07.c   | 127 ++++++++++++++++++
> >  2 files changed, 153 insertions(+)
> >  create mode 100644 include/lapi/resource.h
> >  create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c
>
> > diff --git a/include/lapi/resource.h b/include/lapi/resource.h
> > new file mode 100644
> > index 000000000..3310bc934
> > --- /dev/null
> > +++ b/include/lapi/resource.h
> > @@ -0,0 +1,26 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved.
> > + * Author: Chunfu Wen <chwen@redhat.com>
> > + */
> > +
> > +#ifndef LAPI_RESOURCE_H__
> > +#define LAPI_RESOURCE_H__
> > +
> There should be at the top
>
> #include "config.h"
> otherwise #ifndef HAVE_STRUCT_RLIMIT64 is always false.
>
> > +#define _GNU_SOURCE
> > +
> > +#include "lapi/syscalls.h"
>
> This should include some header, I guess:
> #include <sys/resource.h>
>
> because there is already a check.
> AC_CHECK_TYPES([struct rlimit64],,,[
> #define _LARGEFILE64_SOURCE
> #include <sys/resource.h>
> ])
>
> NOTE: we prefer to uses libc headers instead of kernel headers if possible
> (e.g. not using <linux/resource.h>) due libc and kernel headers conflicts.
> https://sourceware.org/glibc/wiki/Synchronizing_Headers
>
> > +
> > +#ifndef HAVE_STRUCT_RLIMIT64
> > +struct rlimit64 {
> > +        uint64_t rlim_cur;
> > +        uint64_t rlim_max;
> > +};
> > +#endif
> > +
> > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim)
> > +{
> > +        return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL);
> I suppose using raw syscall is really needed, right?
>

Yes, using the raw syscall for prlimit64 is necessary in this case.

>From what I know, Chufu is working oin an environment where glibc's
wrapper might interfere, using tst_syscall(__NR_prlimit64, ...) ensures
that the raw syscall is executed without relying on glibc behavior.

@chuwen, this new case is quite similar to setrlimit06.c, maybe we
can combine into one and use .test_variants to traverse all syscalls.
e.g. syscalls/stime/stime_var.h.


-- 
Regards,
Li Wang


More information about the ltp mailing list