[LTP] Re [PATCH] syscalls/sched_setscheduler04: new test for sched_setscheduler()

zhaogongyi zhaogongyi@huawei.com
Wed Nov 16 03:23:33 CET 2022


Hi!

> 
> > > >> > +static void test_sched_setscheduler02(void) {
> > >> > +	pthread_t tid;
> > >> > +
> > >> > +	SAFE_PTHREAD_CREATE(&tid, NULL, thread_func, NULL);
> > >> > +	SAFE_PTHREAD_JOIN(tid, NULL);
> > >> > +}
> > >> > +
> > >> > +
> > >> > +static void run(void)
> > >> > +{
> > >> > +	sched_prio = sched_get_priority_min(SCHED_POLICY);
> > >>
> > >> This can go in the setup function.
> > >
> > > If move it to setup function, we run the test with option "-I 200",
> > > it will fail.
> >
> > Why?
> 
> sched_prio is a global variable, and it increase in any running loop, thus it
> will be out of range and report:
> 
> sched_setscheduler04.c:52: TPASS: param.sched_priority == sched_prio
> (99)
> sched_setscheduler04.c:53: TPASS: new_policy == EXP_POLICY (1)
> sched_setscheduler04.c:34: TINFO: Setting of tid: 70774
> sched_setscheduler04.c:40: TBROK: sched_setscheduler(70774, 1, ...)
> failed: EINVAL (22)
> 
> Summary:
> passed   196
> failed   0
> broken   1
> skipped  0
> warnings 0
> 
> 
> > >
> > >>
> > >> > +
> > >> > +	test_sched_setscheduler01();
> > >> > +	test_sched_setscheduler02();
> > >>
> > >> This should be replaced with .tcnt = 2 and .test. or else just
> > >> merge them into run.
> > >
> > > Agree, I will fix it int the next version.
> > >
> > >>
> > >> > +}
> > >> > +
> > >> > +static struct tst_test test = {
> > >> > +	.test_all = run,
> > >>
> > >> We probably need to ensure CAP_SYS_NICE. Full details are in 'man 7
> > >> sched'
> > >>
> > >> i.e. .caps = (struct tst_cap[]) {
> > >>   TST_CAP(TST_CAP_REQ, CAP_SYS_NICE),
> > >>    null
> > >> }
> > >>
> > >
> > > In this testcase, we just increase the priority, should we add the
> > > checking
> > of capability?
> >
> > For the test to run we need CAP_SYS_NICE. If you want to test that the
> > priority can only be set when CAP_SYS_NICE is available, then that is
> > a seperate test in my opinion.
> 
> Anybody can call nice() to increase the priority, i have test it with normal
> user and passed.
> 
> And if decrease the priority, the test will report EPERM when running with
> normal user.
> 

I have add a checking of capability in the v2 ptath, please see: https://patchwork.ozlabs.org/project/ltp/patch/20221116021651.21104-1-zhaogongyi@huawei.com/

Regards,
Gongyi


More information about the ltp mailing list