----- "Caspar Zhang" <[email protected]> wrote:

> ----- "Garrett Cooper" <[email protected]> wrote:
> 
> > On Tue, Nov 9, 2010 at 7:32 PM, Caspar Zhang <[email protected]>
> > wrote:
> > > Hi all,
> > >
> > > I met a strange error (only) in RHEL4, syscalls/sysconf
> > > failed the last test case because of the variable `actual'
> > > was not evaluated by `errno':
> > >
> > > sysconf01   56  TFAIL  :  sysconf correctly failed, but expected
> > errno (22) != actual (0)
> > >
> > > I remov the var `actual' and use `errno' directly, seems it
> > > works. Re-test under RHEL4/5/6 and all of them pass the test.
> > >
> > > I have no idea why errno value couldn't be assigned to
> > > `actual', either not sure whether my patch works on other
> > > non-Red Hat distos. Please have a look at this patch if
> > > you want, thanks.
> > >
> > > Signed-off-by: Caspar Zhang <[email protected]>
> > >
> > > ---
> > >  testcases/kernel/syscalls/sysconf/sysconf01.c |    9 ++++-----
> > >  1 files changed, 4 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/testcases/kernel/syscalls/sysconf/sysconf01.c
> > b/testcases/kernel/syscalls/sysconf/sysconf01.c
> > > index 783c6f5..42246f0 100644
> > > --- a/testcases/kernel/syscalls/sysconf/sysconf01.c
> > > +++ b/testcases/kernel/syscalls/sysconf/sysconf01.c
> > > @@ -153,19 +153,18 @@ int main()
> > >
> > >        /* 56 */
> > >        {
> > > -               int retval, actual;
> > > +               int retval;
> > >                errno = 0;
> > >                retval = sysconf(INVAL_FLAG);
> > > -               actual = errno;
> > >                if (retval != -1) {
> > >                        tst_resm(TFAIL,
> > >                                 "sysconf succeeded for invalid
> flag
> > (%i), "
> > >                                 " retval=%d errno=%d: %s",
> > > -                                INVAL_FLAG, retval, actual,
> > strerror(actual));
> > > -               } else if (actual != EINVAL) {
> > > +                                INVAL_FLAG, retval, errno,
> > strerror(errno));
> > > +               } else if (errno != EINVAL) {
> > >                        tst_resm(TFAIL,
> > >                                 "sysconf correctly failed, but
> > expected "
> > > -                                "errno (%i) != actual (%i)",
> > EINVAL, actual);
> > > +                                "errno (%i) != actual (%i)",
> > EINVAL, errno);
> > >                } else
> > >                        tst_resm(TPASS, "The invalid sysconf key
> was
> > trapped "
> > >                                        "appropriately");
> > 
> > Hmmm... well, for starters the definitions aren't the same:
> > 
> >            extern int * __error();
> >            #define errno (* __error())
> > 
> > I wonder if that has to do something with it... try out the
> following
> > program:
> > 
> > #define _GNU_SOURCE 1
> > #include <errno.h>
> > #include <stdio.h>
> > 
> > int
> > main(void)
> > {
> >     open(NULL, 0);
> >     int actual = errno;
> >     printf("%i %d %i %d\n", actual, actual, errno, errno);
> >     return (0);
> > }
> 
> I've tried a similar simple program before in RHEL4, it worked
> out that actual == errno. But when turned to the program in
> this testcase, it always gave the error result.

Sorry I made a mistake.

My reproducer is:

#define _GNU_SOURCE 1
#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int main()
{
        int retval;
        errno = 0;
        retval = sysconf(-1);
        printf("errno=%d\n", errno);
        return 0;
}

This failure was caused by -O2 option. Nothing to do
with `actual' variable.

Here is the gas diff of with/without -O2 option:

--- with-O2.s   2010-11-10 02:01:45.000000000 -0500
+++ without-O2.s        2010-11-10 02:01:53.000000000 -0500
@@ -1,9 +1,8 @@
        .file   "main.c"
-       .section        .rodata.str1.1,"aMS",@progbits,1
+       .section        .rodata
 .LC0:
        .string "errno=%d\n"
        .text
-       .p2align 2,,3
 .globl main
        .type   main, @function
 main:
@@ -11,19 +10,28 @@
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
-       subl    $16, %esp
+       movl    $0, %eax
+       addl    $15, %eax
+       addl    $15, %eax
+       shrl    $4, %eax
+       sall    $4, %eax
+       subl    %eax, %esp
        call    __errno_location
-       subl    $12, %esp
        movl    $0, (%eax)
+       subl    $12, %esp
        pushl   $-1
        call    sysconf
+       addl    $16, %esp
+       movl    %eax, -4(%ebp)
+       subl    $8, %esp
+       subl    $8, %esp
        call    __errno_location
-       popl    %eax
-       popl    %edx
-       pushl   $0
+       addl    $8, %esp
+       pushl   (%eax)
        pushl   $.LC0
        call    printf
-       xorl    %eax, %eax
+       addl    $16, %esp
+       movl    $0, %eax
        leave
        ret
        .size   main, .-main


> 
> > 
> > It spit out this on FreeBSD at least:
> > 
> > $ gcc -Wall -o test_errno_assignment test_errno_assignment.c
> > $ ./test_errno_assignment
> > 14 14 14 14
> > 
> > HTH,
> > -Garrett
> 
> -- 
> Quality Assurance Associate (Kernel) in
> Red Hat Software (Beijing) Co., R&D Branch
> 
> TEL: +86-10-62608150
> WEB: http://www.redhat.com/

-- 
Quality Assurance Associate (Kernel) in
Red Hat Software (Beijing) Co., R&D Branch

TEL: +86-10-62608150
WEB: http://www.redhat.com/

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to