<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 20, 2022 at 6:40 PM Richard Palethorpe <<a href="mailto:rpalethorpe@suse.de">rpalethorpe@suse.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>> writes:<br>
<br>
> On Thu, Oct 20, 2022 at 5:30 PM Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>> wrote:<br>
><br>
> Richard Palethorpe <<a href="mailto:rpalethorpe@suse.de" target="_blank">rpalethorpe@suse.de</a>> wrote:<br>
> <br>
> > -static struct itimerval *value;<br>
> > +static struct itimerval *value, *ovalue;<br>
> > +<br>
> > +static struct tcase {<br>
> > + int which;<br>
> > + struct itimerval **val;<br>
> > + struct itimerval **oval;<br>
> > + int exp_errno;<br>
><br>
> There is a whitespace error here (see checkpatch/make check)<br>
><br>
> yes, thanks.<br>
><br>
> <br>
> <br>
> > +} tcases[] = {<br>
> > + {ITIMER_REAL, &value, &ovalue, EFAULT},<br>
> > + {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},<br>
> > + {-ITIMER_PROF, &value, &ovalue, EINVAL},<br>
> > +};<br>
><br>
> Why do we need value and ovalue in the struct?<br>
><br>
> Becuase it does not allow parsing an invalid pointer address<br>
> from a structure, we have to give a valid address which pointer<br>
> to save an invalid address. Otherwise segement fault will<br>
> be hit in execution.<br>
><br>
> On the other side, it also does not allow to initializer element<br>
> is not constant in structure. So the two-level pointer is only the<br>
> way I can make all things comprised here.<br>
<br>
I'm not sure what you mean and I don't understand why we need this<br>
struct at all. The following works and produces better output:<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Ok, I got your point. Previously I was stuck in thinking about how to keep</div>the unified tcase struct for error testing.<div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Seems I should give up the fixed mindset.</div><div class="gmail_default" style="font-size:small"><br></div>static struct tcase {<br> <span class="gmail_default" style="font-size:small"> ...</span><br>} tcases[] = {<br> <span class="gmail_default" style="font-size:small"> ...</span><br>};<br><div class="gmail_default" style="font-size:small"></div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
@@ -20,17 +20,6 @@<br>
<br>
static struct itimerval *value, *ovalue;<br>
<br>
-static struct tcase {<br>
- int which;<br>
- struct itimerval **val;<br>
- struct itimerval **oval;<br>
- int exp_errno;<br>
-} tcases[] = {<br>
- {ITIMER_REAL, &value, &ovalue, EFAULT},<br>
- {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},<br>
- {-ITIMER_PROF, &value, &ovalue, EINVAL},<br>
-};<br>
-<br>
static int sys_setitimer(int which, void *new_value, void *old_value)<br>
{<br>
return tst_syscall(__NR_setitimer, which, new_value, old_value);<br>
@@ -38,13 +27,17 @@ static int sys_setitimer(int which, void *new_value, void *old_value)<br>
<br>
static void verify_setitimer(unsigned int i)<br>
{<br>
- struct tcase *tc = &tcases[i];<br>
-<br>
- if (tc->exp_errno == EFAULT)<br>
- *(tc->oval) = (struct itimerval *)-1;<br>
-<br>
- TST_EXP_FAIL(sys_setitimer(tc->which, *(tc->val), *(tc->oval)),<br>
- tc->exp_errno);<br>
+ switch (i) {<br>
+ case 0:<br>
+ TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT);<br>
+ break;<br>
+ case 1:<br>
+ TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT);<br>
+ break;<br>
+ case 2:<br>
+ TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL);<br>
+ break;<br>
+ }<br>
}<br>
<br>
static void setup(void)<br>
@@ -56,7 +49,7 @@ static void setup(void)<br>
}<br>
<br>
static struct tst_test test = {<br>
- .tcnt = ARRAY_SIZE(tcases),<br>
+ .tcnt = 3,<br>
.test = verify_setitimer,<br>
.setup = setup,<br>
.bufs = (struct tst_buffers[]) {<br>
<br>
This prints<br>
<br>
setitimer02.c:32: TPASS: sys_setitimer(ITIMER_REAL, value, (void *)-1) : EFAULT (14)<br>
setitimer02.c:35: TPASS: sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1) : EFAULT (14)<br>
setitimer02.c:38: TPASS: sys_setitimer(-ITIMER_PROF, value, ovalue) : EINVAL (22)<br>
<br>
instead of<br>
<br>
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)<br>
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)<br>
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EINVAL (22)<br>
<br>
The same values are passed to the syscall according to strace.<br>
<br>
-- <br>
Thank you,<br>
Richard.<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>