[LTP] [PATCH v2] lib: Do not fail a test if oom score cannot be adjusted.
xuyang2018.jy@fujitsu.com
xuyang2018.jy@fujitsu.com
Thu Dec 23 02:17:24 CET 2021
Hi Petr, All
> Hi Cyril, all,
>
>> From: Petr Vorel<pvorel@suse.cz>
>
>> Setting value< 0 in /proc/*/oom_score_adj requires CAP_SYS_RESOURCE or
>> CAP_SYS_ADMIN.
Here will mislead user.
Since the default oom_score_adj value is 0, so we can not set a value < 0.
The value of /proc/<pid>/oom_score_adj may be reduced no lower than the
last value set by a CAP_SYS_RESOURCE process. To reduce the value any
lower requires CAP_SYS_RESOURCE.
Also looks man 7 capabilities, CAP_SYS_ADMIN doesn't have this cap and I
have do a test to verify this
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include "tst_test.h"
#include "tst_capability.h"
static void run(void)
{
FILE *f;
f = fopen("/proc/self/oom_score_adj", "w");
if (!f)
tst_res(TFAIL, "non-exist");
if (fprintf(f, "%d", -200) <= 0)
tst_res(TFAIL, "write failed");
if (fclose(f))
tst_res(TFAIL, "close %d",errno);
tst_res(TPASS, "write pass");
}
static struct tst_test test = {
.test_all = run,
.caps = (struct tst_cap []) {
TST_CAP(TST_CAP_REQ, CAP_SYS_ADMIN),
TST_CAP(TST_CAP_DROP, CAP_SYS_RESOURCE),
{}
},
};
It still fails if we only have CAP_SYS_ADMIN.
Best Regards
Yang Xu
However setting the library process score is a best
>> effort operation, so let's skip it silently when the user is not
>> privileged to do so.
> +1
>
> LGTM, thanks for this version, I'm for merging it.
>
> Also tested locally and on CI, working as expected.
> https://github.com/pevik/ltp/runs/4607602484?check_suite_focus=true
>
> Kind regards,
> Petr
More information about the ltp
mailing list