summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivmai <ivmai>2011-05-11 12:22:45 +0000
committerIvan Maidanski <ivmai@mail.ru>2011-07-25 16:03:26 +0400
commit93d66c013aa74b66e620f22d0feb2c5e96794138 (patch)
tree97b476491b808cef7d4d7f9e5ffc4f8ed56040b2
parent87f8fdf162ede4c5fd7fd506db659fcb9f6d7c9a (diff)
downloadlibatomic_ops-93d66c013aa74b66e620f22d0feb2c5e96794138.tar.gz
2011-05-11 Ivan Maidanski <ivmai@mail.ru>
* tests/test_malloc.c: Expand all tabs to spaces; remove trailing spaces at EOLn. * tests/test_malloc.c (LENGTH, LARGE): Rename to LIST_LENGTH and LARGE_OBJ_SIZE, respectively. * tests/test_malloc.c (MAX_NTHREADS, N_REVERSALS, LIST_LENGTH, LARGE_OBJ_SIZE): Do not define unless undefined. * tests/test_malloc.c (run_one_test): Recognize DEBUG_RUN_ONE_TEST macro.
-rw-r--r--ChangeLog11
-rw-r--r--tests/test_malloc.c73
2 files changed, 52 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 6323c0d..c864db2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-05-11 Ivan Maidanski <ivmai@mail.ru>
+
+ * tests/test_malloc.c: Expand all tabs to spaces; remove trailing
+ spaces at EOLn.
+ * tests/test_malloc.c (LENGTH, LARGE): Rename to LIST_LENGTH and
+ LARGE_OBJ_SIZE, respectively.
+ * tests/test_malloc.c (MAX_NTHREADS, N_REVERSALS, LIST_LENGTH,
+ LARGE_OBJ_SIZE): Do not define unless undefined.
+ * tests/test_malloc.c (run_one_test): Recognize DEBUG_RUN_ONE_TEST
+ macro.
+
2011-05-10 Ivan Maidanski <ivmai@mail.ru>
* tests/Makefile.am (EXTRA_DIST): Add list_atomic.c; update
diff --git a/tests/test_malloc.c b/tests/test_malloc.c
index 4026e62..4eb50a2 100644
--- a/tests/test_malloc.c
+++ b/tests/test_malloc.c
@@ -1,11 +1,11 @@
-/*
+/*
* Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
* Original Author: Hans Boehm
*
* This file may be redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2, or (at your option) any later version.
- *
+ *
* It is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License in the
@@ -21,19 +21,29 @@
#include <stdlib.h>
#include <stdio.h>
#include "atomic_ops_malloc.h"
-#define MAX_NTHREADS 100
-#define N_REVERSALS 1000 /* must be even */
-#define LENGTH 1000
+
+#ifndef MAX_NTHREADS
+# define MAX_NTHREADS 100
+#endif
+#ifndef N_REVERSALS
+# define N_REVERSALS 1000 /* must be even */
+#endif
+#ifndef LIST_LENGTH
+# define LIST_LENGTH 1000
+#endif
+#ifndef LARGE_OBJ_SIZE
+# define LARGE_OBJ_SIZE 200000
+#endif
#ifdef USE_STANDARD_MALLOC
# define AO_malloc(n) malloc(n)
# define AO_free(p) free(p)
-# define AO_malloc_enable_mmap()
+# define AO_malloc_enable_mmap()
#endif
typedef struct list_node {
- struct list_node *next;
- int data;
+ struct list_node *next;
+ int data;
} ln;
ln *cons(int d, ln *tail)
@@ -44,7 +54,7 @@ ln *cons(int d, ln *tail)
int * extras;
int i;
- if (my_extra > 100)
+ if (my_extra > 100)
extra = my_extra = 0;
else
++extra;
@@ -52,7 +62,7 @@ ln *cons(int d, ln *tail)
if (result == 0)
{
fprintf(stderr, "Out of memory\n");
- /* Normal for more than about 10 threads without mmap? */
+ /* Normal for more than about 10 threads without mmap? */
abort();
}
@@ -83,10 +93,10 @@ void check_list(ln *l, int m, int n)
for (p = l, i = m; p != 0; p = p -> next, ++i)
{
if (i != p -> data)
- {
- fprintf(stderr, "Found %d, expected %d\n", p -> data, i);
- abort();
- }
+ {
+ fprintf(stderr, "Found %d, expected %d\n", p -> data, i);
+ abort();
+ }
}
}
@@ -99,7 +109,7 @@ make_list(int m, int n)
}
/* Reverse list x, and concatenate it to y, deallocating no longer needed */
-/* nodes in x. */
+/* nodes in x. */
ln *
reverse(ln *x, ln *y)
{
@@ -113,34 +123,34 @@ reverse(ln *x, ln *y)
int dummy_test(void) { return 1; }
-#define LARGE 200000
-
void * run_one_test(void * arg) {
- ln * x = make_list(1, LENGTH);
+ ln * x = make_list(1, LIST_LENGTH);
int i;
- char *p = AO_malloc(LARGE);
+ char *p = AO_malloc(LARGE_OBJ_SIZE);
char *q;
if (0 == p) {
fprintf(stderr, "AO_malloc(%d) failed: This is normal without mmap\n",
- LARGE);
+ LARGE_OBJ_SIZE);
AO_free(p);
} else {
- p[0] = p[LARGE/2] = p[LARGE-1] = 'a';
- q = AO_malloc(LARGE);
- q[0] = q[LARGE/2] = q[LARGE-1] = 'b';
- if (p[0] != 'a' || p[LARGE/2] != 'a' || p[LARGE-1] != 'a') {
+ p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = 'a';
+ q = AO_malloc(LARGE_OBJ_SIZE);
+ q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = 'b';
+ if (p[0] != 'a' || p[LARGE_OBJ_SIZE/2] != 'a'
+ || p[LARGE_OBJ_SIZE-1] != 'a') {
fprintf(stderr, "First large allocation smashed\n");
abort();
}
AO_free(p);
- if (q[0] != 'b' || q[LARGE/2] != 'b' || q[LARGE-1] != 'b') {
+ if (q[0] != 'b' || q[LARGE_OBJ_SIZE/2] != 'b'
+ || q[LARGE_OBJ_SIZE-1] != 'b') {
fprintf(stderr, "Second large allocation smashed\n");
abort();
}
AO_free(q);
}
-# if 0 /* enable for debugging */
+# ifdef DEBUG_RUN_ONE_TEST
x = reverse(x, 0);
print_list(x);
x = reverse(x, 0);
@@ -149,7 +159,7 @@ void * run_one_test(void * arg) {
for (i = 0; i < N_REVERSALS; ++i) {
x = reverse(x, 0);
}
- check_list(x, 1, LENGTH);
+ check_list(x, 1, LIST_LENGTH);
return 0;
}
@@ -159,24 +169,23 @@ int main(int argc, char **argv) {
if (1 == argc) {
# if !defined(HAVE_MMAP)
- nthreads = 3;
+ nthreads = 3;
# else
nthreads = 10;
# endif
} else if (2 == argc) {
nthreads = atoi(argv[1]);
if (nthreads < 1 || nthreads > MAX_NTHREADS) {
- fprintf(stderr, "Invalid # of threads argument\n");
- exit(1);
+ fprintf(stderr, "Invalid # of threads argument\n");
+ exit(1);
}
} else {
fprintf(stderr, "Usage: %s [# of threads]\n", argv[0]);
exit(1);
}
printf("Performing %d reversals of %d element lists in %d threads\n",
- N_REVERSALS, LENGTH, nthreads);
+ N_REVERSALS, LIST_LENGTH, nthreads);
AO_malloc_enable_mmap();
run_parallel(nthreads, run_one_test, dummy_test, "AO_malloc/AO_free");
return 0;
}
-