This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 1/7] stdlib: Adjust tst-qsort{2} to libsupport


	* stdlib/tst-qsort.c: Use libsupport.
	* stdlib/tst-qsort2.c: Likewise.
---
 stdlib/tst-qsort.c  | 45 ++++++++++++++++++++++-----------------------
 stdlib/tst-qsort2.c | 44 +++++++++++++++++++++-----------------------
 2 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/stdlib/tst-qsort.c b/stdlib/tst-qsort.c
index 2b26e74d0b..c3230fd10e 100644
--- a/stdlib/tst-qsort.c
+++ b/stdlib/tst-qsort.c
@@ -3,6 +3,8 @@
 #include <stdlib.h>
 #include <tst-stack-align.h>
 
+#include <support/check.h>
+
 struct big { char c[4 * 1024]; };
 
 struct big *array;
@@ -10,7 +12,7 @@ struct big *array_end;
 
 static int align_check;
 
-int
+static int
 compare (void const *a1, void const *b1)
 {
   struct big const *a = a1;
@@ -19,37 +21,34 @@ compare (void const *a1, void const *b1)
   if (!align_check)
     align_check = TEST_STACK_ALIGN () ? -1 : 1;
 
-  if (! (array <= a && a < array_end
-	 && array <= b && b < array_end))
-    {
-      exit (EXIT_FAILURE);
-    }
-  return b->c[0] - a->c[0];
+  TEST_VERIFY_EXIT (array <= a && a < array_end
+		    && array <= b && b < array_end);
+
+  return (b->c[0] - a->c[0]) > 0;
 }
 
 int
-main (int argc, char **argv)
+do_test (void)
 {
-  size_t i;
-  size_t array_members = argv[1] ? atoi (argv[1]) : 50;
-  array = (struct big *) malloc (array_members * sizeof *array);
-  if (array == NULL)
+  const size_t sizes[] = { 8, 16, 24, 48, 96, 192, 384 };
+  const size_t sizes_len = sizeof (sizes) / sizeof (sizes[0]);
+
+  for (size_t s = 0; s < sizes_len; s++)
     {
-      puts ("no memory");
-      exit (EXIT_FAILURE);
-    }
+      array = (struct big *) malloc (sizes[s] * sizeof *array);
+      TEST_VERIFY_EXIT (array != NULL);
 
-  array_end = array + array_members;
-  for (i = 0; i < array_members; i++)
-    array[i].c[0] = i % 128;
+      array_end = array + sizes[s];
+      for (size_t i = 0; i < sizes[s]; i++)
+        array[i].c[0] = i % 128;
 
-  qsort (array, array_members, sizeof *array, compare);
+      qsort (array, sizes[s], sizeof *array, compare);
+      TEST_VERIFY_EXIT (align_check != -1);
 
-  if (align_check == -1)
-    {
-      puts ("stack not sufficiently aligned");
-      exit (EXIT_FAILURE);
+      free (array);
     }
 
   return 0;
 }
+
+#include <support/test-driver.c>
diff --git a/stdlib/tst-qsort2.c b/stdlib/tst-qsort2.c
index 10d16852b0..595875dcae 100644
--- a/stdlib/tst-qsort2.c
+++ b/stdlib/tst-qsort2.c
@@ -1,11 +1,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-char *array;
-char *array_end;
-size_t member_size;
+#include <support/check.h>
 
-int
+static char *array;
+static char *array_end;
+static size_t member_size;
+
+static int
 compare (const void *a1, const void *b1)
 {
   const char *a = a1;
@@ -25,7 +27,7 @@ compare (const void *a1, const void *b1)
   return 0;
 }
 
-int
+static int
 test (size_t nmemb, size_t size)
 {
   array = malloc (nmemb * size);
@@ -66,24 +68,20 @@ test (size_t nmemb, size_t size)
   return 0;
 }
 
-int
-main (int argc, char **argv)
+static int
+do_test (void)
 {
-  int ret = 0;
-  if (argc >= 3)
-    ret |= test (atoi (argv[1]), atoi (argv[2]));
-  else
-    {
-      ret |= test (10000, 1);
-      ret |= test (200000, 2);
-      ret |= test (2000000, 3);
-      ret |= test (2132310, 4);
-      ret |= test (1202730, 7);
-      ret |= test (1184710, 8);
-      ret |= test (272710, 12);
-      ret |= test (14170, 32);
-      ret |= test (4170, 320);
-    }
+  test (10000, 1);
+  test (200000, 2);
+  test (2000000, 3);
+  test (2132310, 4);
+  test (1202730, 7);
+  test (1184710, 8);
+  test (272710, 12);
+  test (14170, 32);
+  test (4170, 320);
 
-  return ret;
+  return 0;
 }
+
+#include <support/test-driver.c>
-- 
2.17.1


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