This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

memcheck tests patches


Hi Guys,

  I have applied the following patches to the memcheck tests.  The
  effect is to mark the blkarg.c test as an expected failure, since at
  the moment access to the stack are not being marked as allowable.  I
  also took the opportunity to tidy up the code slightly.

Cheers
	Nick


1999-02-03  Nick Clifton  <nickc@cygnus.com>

	* execute/memcheck/blkarg.c (foo): Use 10 leading arguments in
	order to force structure S onto the stack even on the alpha.
	(test): Pass 10 leading arguments to function foo as well as the
	structure S.

	* execute/memcheck/blkarg.x: New file: Expected failure for all
	targets. 

	* execute/memcheck/driver.c (main): Use exit or abort to terminate
	program execution.


Index: blkarg.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/gcc.c-torture/execute/memcheck/blkarg.c,v
retrieving revision 1.2
diff -p -r1.2 blkarg.c
*** blkarg.c	1998/12/16 22:16:55	1.2
--- blkarg.c	1999/02/03 18:27:29
***************
*** 23,46 ****
  int expect_error = 0;
  
  /* Must be BLKmode.  Using only two fields gets TImode on Alpha.  */
! struct S {
    unsigned long long ll;
!   long xx, yy;
  };
- 
- unsigned long long x = 0x12345689ULL;
- #define I2	42
  
! /* Leading six arguments force X into stack on both Alpha and MIPS.  */
  
  static int first_time = 1;
! int foo (int a1, int a2, int a3, int a4, int a5, int a6, struct S s) {
!   if (a1 != 1 || a2 != 2 || a3 != 3 || a4 != 4 || a5 != 5 || a6 != 6)
      abort ();
    if (first_time)
      {
        if (s.ll != x || s.xx != I2 || s.yy != 0)
  	abort ();
        first_time = 0;
      }
    else
--- 23,54 ----
  int expect_error = 0;
  
  /* Must be BLKmode.  Using only two fields gets TImode on Alpha.  */
! struct S
! {
    unsigned long long ll;
!   long               xx;
!   long               yy;
  };
  
! unsigned long long   x = 0x12345689ULL;
! #define I2	     42
  
  static int first_time = 1;
! 
! /* Leading ten arguments force struct S onto the stack on both Alpha and MIPS.  */
! int
! foo (int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10,
!      struct S s)
! {
!   if (a1 != 1 || a2 != 2 || a3 != 3 || a4 != 4 || a5 != 5 || a6 != 6 || a7 != 7
!       || a8 != 8 || a9 !=9 || a10 != 10)
      abort ();
+   
    if (first_time)
      {
        if (s.ll != x || s.xx != I2 || s.yy != 0)
  	abort ();
+       
        first_time = 0;
      }
    else
*************** int foo (int a1, int a2, int a3, int a4,
*** 48,63 ****
        if (s.ll != 0 || s.xx != 0 || s.yy != 0)
  	abort ();
      }
    return 0;
  }
  
! void test ()
  {
!   foo (1, 2, 3, 4, 5, 6, (struct S) { x, I2 });
!   foo (1, 2, 3, 4, 5, 6, (struct S) { 0 });
  }
  
! void setup () /* NOCHECK */
  {
    mark_region (&x, sizeof (x), ACCESS_RO);
    mark_region (&first_time, sizeof (first_time), ACCESS_RW);
--- 56,74 ----
        if (s.ll != 0 || s.xx != 0 || s.yy != 0)
  	abort ();
      }
+   
    return 0;
  }
  
! void
! test ()
  {
!   foo (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, (struct S) { x, I2 });
!   foo (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, (struct S) { 0 });
  }
  
! void
! setup () /* NOCHECK */
  {
    mark_region (&x, sizeof (x), ACCESS_RO);
    mark_region (&first_time, sizeof (first_time), ACCESS_RW);


*** /dev/null	Tue May  5 13:32:27 1998
--- blkarg.x	Wed Feb  3 10:23:28 1999
***************
*** 0 ****
--- 1,9 ----
+ # The memeory checking code does not mark the stack as readable or writable
+ # so this test fails.  Ideally the memory checking library ought to 
+ # cooperate with the host OS to mark the stack as it is used or individual
+ # function prologues and epilogues ought to mark their pieces of stack as 
+ # writable and readable-after-written.
+ 
+ set torture_execute_xfail "*-*-*"
+ 
+ return 0


Index: driver.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/gcc.c-torture/execute/memcheck/driver.c,v
retrieving revision 1.2
diff -p -r1.2 driver.c
*** driver.c	1998/12/16 22:16:56	1.2
--- driver.c	1999/02/03 18:23:58
*************** int verbose = 0;
*** 9,15 ****
  int debug = 0;
  int bad_accesses = 0;
  
! const char *const memory_use_strings[] = {
  #define INIT(x)		[x] = #x
    INIT (MEMORY_USE_BAD),
    INIT (MEMORY_USE_DONT),
--- 9,16 ----
  int debug = 0;
  int bad_accesses = 0;
  
! const char *const memory_use_strings[] =
! {
  #define INIT(x)		[x] = #x
    INIT (MEMORY_USE_BAD),
    INIT (MEMORY_USE_DONT),
*************** const char *const memory_use_strings[] =
*** 23,32 ****
  /* This won't be used for any really huge test cases, so a simple
     linked list is adequate.  We won't even worry about overlapping
     regions; the matching entry that comes up first wins.  */
! const char *const access_mode_strings[] = {
    "none", "ro", "wo", "rw",
  };
! struct access_node {
    struct access_node *next;
    const void *addr;
    size_t sz;
--- 24,35 ----
  /* This won't be used for any really huge test cases, so a simple
     linked list is adequate.  We won't even worry about overlapping
     regions; the matching entry that comes up first wins.  */
! const char *const access_mode_strings[] =
! {
    "none", "ro", "wo", "rw",
  };
! struct access_node
! {
    struct access_node *next;
    const void *addr;
    size_t sz;
*************** struct access_node {
*** 35,41 ****
  
  static struct access_node *access_list;
  
! void mark_region (const void *addr, size_t sz, enum access_mode mode)
  {
    struct access_node *a;
    if (debug)
--- 38,45 ----
  
  static struct access_node *access_list;
  
! void
! mark_region (const void *addr, size_t sz, enum access_mode mode)
  {
    struct access_node *a;
    if (debug)
*************** void mark_region (const void *addr, size
*** 50,56 ****
  }
  
  void report_bad_access (void *, size_t, enum memory_use_mode) NOCHECK;
! void report_bad_access (void *addr, size_t sz, enum memory_use_mode mode)
  {
    if (++bad_accesses > 100)
      bad_accesses = 100;
--- 54,61 ----
  }
  
  void report_bad_access (void *, size_t, enum memory_use_mode) NOCHECK;
! void
! report_bad_access (void *addr, size_t sz, enum memory_use_mode mode)
  {
    if (++bad_accesses > 100)
      bad_accesses = 100;
*************** void report_bad_access (void *addr, size
*** 72,79 ****
  }
  
  int verify1 (void *, size_t, enum access_mode, struct access_node *) NOCHECK;
! int verify1 (void *addr, size_t sz, enum access_mode mode,
! 	     struct access_node *a)
  {
    while (a && (addr + sz <= a->addr || addr >= a->addr + a->sz))
      a = a->next;
--- 77,85 ----
  }
  
  int verify1 (void *, size_t, enum access_mode, struct access_node *) NOCHECK;
! int
! verify1 (void *addr, size_t sz, enum access_mode mode,
! 	 struct access_node *a)
  {
    while (a && (addr + sz <= a->addr || addr >= a->addr + a->sz))
      a = a->next;
*************** int verify1 (void *addr, size_t sz, enum
*** 99,106 ****
  }
  
  int verify_range_permission (void *, size_t, enum access_mode) NOCHECK;
! 
! int verify_range_permission (void *addr, size_t sz, enum access_mode mode)
  {
    if (debug)
      printf ("verify_range_permission (%p, %ld, %s)\n", addr, (long) sz,
--- 105,112 ----
  }
  
  int verify_range_permission (void *, size_t, enum access_mode) NOCHECK;
! int
! verify_range_permission (void *addr, size_t sz, enum access_mode mode)
  {
    if (debug)
      printf ("verify_range_permission (%p, %ld, %s)\n", addr, (long) sz,
*************** int verify_range_permission (void *addr,
*** 109,116 ****
  }
  
  void chkr_check_addr (void *, size_t, int) NOCHECK;
! 
! void chkr_check_addr (void *addr, size_t sz, int mode)
  {
    switch (mode)
      {
--- 115,122 ----
  }
  
  void chkr_check_addr (void *, size_t, int) NOCHECK;
! void
! chkr_check_addr (void *addr, size_t sz, int mode)
  {
    switch (mode)
      {
*************** void chkr_check_addr (void *addr, size_t
*** 146,152 ****
  }
  
  void copy1 (void *, void *, size_t, struct access_node *) NOCHECK;
! void copy1 (void *dest, void *src, size_t sz, struct access_node *a)
  {
    while (a && (src + sz <= a->addr || src >= a->addr + a->sz))
      a = a->next;
--- 152,159 ----
  }
  
  void copy1 (void *, void *, size_t, struct access_node *) NOCHECK;
! void
! copy1 (void *dest, void *src, size_t sz, struct access_node *a)
  {
    while (a && (src + sz <= a->addr || src >= a->addr + a->sz))
      a = a->next;
*************** void copy1 (void *dest, void *src, size_
*** 178,184 ****
  }
  
  void chkr_copy_bitmap (void *, void *, size_t) NOCHECK;
! void chkr_copy_bitmap (void *dest, void *src, size_t sz)
  {
    if (verify_range_permission (dest, sz, MEMORY_USE_WO) == 0)
      report_bad_access (dest, sz, MEMORY_USE_WO);
--- 185,192 ----
  }
  
  void chkr_copy_bitmap (void *, void *, size_t) NOCHECK;
! void
! chkr_copy_bitmap (void *dest, void *src, size_t sz)
  {
    if (verify_range_permission (dest, sz, MEMORY_USE_WO) == 0)
      report_bad_access (dest, sz, MEMORY_USE_WO);
*************** void chkr_copy_bitmap (void *dest, void 
*** 186,207 ****
  }
  
  void chkr_set_right (void *, size_t, enum access_mode) NOCHECK;
! void chkr_set_right (void *addr, size_t sz, enum access_mode mode)
  {
    mark_region (addr, sz, mode);
  }
  
  int main () NOCHECK;
! int main ()
  {
    setup ();
    test ();
    bad_accesses = !!bad_accesses; /* get 0 or 1 */
!   /* Return 0 if got expected results, 1 otherwise.  */
!   return !(bad_accesses == expect_error);
  }
  
! struct malloc_node {
    struct malloc_node *next;
    void *addr;
    size_t sz;
--- 194,223 ----
  }
  
  void chkr_set_right (void *, size_t, enum access_mode) NOCHECK;
! void
! chkr_set_right (void *addr, size_t sz, enum access_mode mode)
  {
    mark_region (addr, sz, mode);
  }
  
  int main () NOCHECK;
! int
! main ()
  {
    setup ();
    test ();
    bad_accesses = !!bad_accesses; /* get 0 or 1 */
!   
!   if (bad_accesses == expect_error)
!     exit (0);
!   else
!     abort ();
!   
!   return 0;
  }
  
! struct malloc_node
! {
    struct malloc_node *next;
    void *addr;
    size_t sz;
*************** struct malloc_node {
*** 209,215 ****
  };
  static struct malloc_node *malloc_list;
  
! void *c_malloc (size_t sz)
  {
    void *p;
    struct malloc_node *m;
--- 225,232 ----
  };
  static struct malloc_node *malloc_list;
  
! void *
! c_malloc (size_t sz)
  {
    void *p;
    struct malloc_node *m;
*************** void *c_malloc (size_t sz)
*** 238,244 ****
    return p;
  }
  
! void c_free (void *p)
  {
    struct malloc_node *m;
    if (p == 0)
--- 255,262 ----
    return p;
  }
  
! void
! c_free (void *p)
  {
    struct malloc_node *m;
    if (p == 0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]