summaryrefslogtreecommitdiff
path: root/test/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'test/stdlib')
-rw-r--r--test/stdlib/Makefile73
-rw-r--r--test/stdlib/testatexit.c74
-rw-r--r--test/stdlib/teston_exit.c75
3 files changed, 221 insertions, 1 deletions
diff --git a/test/stdlib/Makefile b/test/stdlib/Makefile
index 4d365609b..209c43b5b 100644
--- a/test/stdlib/Makefile
+++ b/test/stdlib/Makefile
@@ -25,6 +25,8 @@ TARGETS=testmalloc testmalloc_glibc
TARGETS+=mallocbug mallocbug_glibc
TARGETS+=teststrtol teststrtol_glibc teststrtol_diff
TARGETS+=qsort qsort_glibc qsort_diff
+TARGETS+=teston_exit teston_exit_glibc teston_exit_diff
+TARGETS+=testatexit testatexit_glibc testatexit_diff
all: $(TARGETS)
@@ -162,7 +164,76 @@ qsort_diff: qsort_glibc qsort
-diff -u qsort_glibc.out qsort.out
-@ echo " "
+teston_exit: teston_exit.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC)
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs uClibc: "
+ -@ echo " "
+ $(CC) $(CFLAGS) -c $< -o $@.o
+ $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -$(LDD) $@
+ ls -l $@
+ -./$@ > $@.out
+ -@ echo " "
+
+teston_exit_glibc: teston_exit.c Makefile
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs GNU libc: "
+ -@ echo " "
+ $(HOST_CC) $(GLIBC_CFLAGS) -c $< -o $@.o
+ $(HOST_CC) $(GLIBC_LDFLAGS) $@.o -o $@
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -$(LDD) $@
+ ls -l $@
+ -./$@ > $@.out
+ -@ echo " "
+
+teston_exit_diff: teston_exit_glibc teston_exit
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Diffing output: "
+ -@ echo " "
+ -diff -u teston_exit_glibc.out teston_exit.out
+ -@ echo " "
+
+testatexit: testatexit.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC)
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs uClibc: "
+ -@ echo " "
+ $(CC) $(CFLAGS) -c $< -o $@.o
+ $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -$(LDD) $@
+ ls -l $@
+ -./$@ > $@.out
+ -@ echo " "
+
+testatexit_glibc: testatexit.c Makefile
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Compiling vs GNU libc: "
+ -@ echo " "
+ $(HOST_CC) $(GLIBC_CFLAGS) -c $< -o $@.o
+ $(HOST_CC) $(GLIBC_LDFLAGS) $@.o -o $@
+ $(STRIPTOOL) -x -R .note -R .comment $@
+ -$(LDD) $@
+ ls -l $@
+ -./$@ > $@.out
+ -@ echo " "
+
+testatexit_diff: testatexit_glibc testatexit
+ -@ echo "-------"
+ -@ echo " "
+ -@ echo "Diffing output: "
+ -@ echo " "
+ -diff -u testatexit_glibc.out testatexit.out
+ -@ echo " "
+
+
clean:
- rm -f *.[oa] *~ core $(TARGETS) teststrtol_glibc.out teststrtol.out
+ rm -f *.[oa] *~ core $(TARGETS) *.out
diff --git a/test/stdlib/testatexit.c b/test/stdlib/testatexit.c
new file mode 100644
index 000000000..374f7b8aa
--- /dev/null
+++ b/test/stdlib/testatexit.c
@@ -0,0 +1,74 @@
+/*
+ * This test program will register the maximum number of exit functions
+ * with atexit(). When this program exits, each exit function should get
+ * called in the reverse order in which it was registered. (If the system
+ * supports more than 25 exit functions, the function names will loop, but
+ * the effect will be the same. Feel free to add more functions if desired)
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef void (*vfuncp) (void);
+
+/* All functions call exit(), in order to test that exit functions can call
+ * exit() without screwing everything up. :)
+ */
+static void exitfunc0(void) { printf("Executing exitfunc0.\n"); exit(0);}
+static void exitfunc1(void) { printf("Executing exitfunc1.\n"); exit(0);}
+static void exitfunc2(void) { printf("Executing exitfunc2.\n"); exit(0);}
+static void exitfunc3(void) { printf("Executing exitfunc3.\n"); exit(0);}
+static void exitfunc4(void) { printf("Executing exitfunc4.\n"); exit(0);}
+static void exitfunc5(void) { printf("Executing exitfunc5.\n"); exit(0);}
+static void exitfunc6(void) { printf("Executing exitfunc6.\n"); exit(0);}
+static void exitfunc7(void) { printf("Executing exitfunc7.\n"); exit(0);}
+static void exitfunc8(void) { printf("Executing exitfunc8.\n"); exit(0);}
+static void exitfunc9(void) { printf("Executing exitfunc9.\n"); exit(0);}
+static void exitfunc10(void) { printf("Executing exitfunc10.\n"); exit(0);}
+static void exitfunc11(void) { printf("Executing exitfunc11.\n"); exit(0);}
+static void exitfunc12(void) { printf("Executing exitfunc12.\n"); exit(0);}
+static void exitfunc13(void) { printf("Executing exitfunc13.\n"); exit(0);}
+static void exitfunc14(void) { printf("Executing exitfunc14.\n"); exit(0);}
+static void exitfunc15(void) { printf("Executing exitfunc15.\n"); exit(0);}
+static void exitfunc16(void) { printf("Executing exitfunc16.\n"); exit(0);}
+static void exitfunc17(void) { printf("Executing exitfunc17.\n"); exit(0);}
+static void exitfunc18(void) { printf("Executing exitfunc18.\n"); exit(0);}
+static void exitfunc19(void) { printf("Executing exitfunc19.\n"); exit(0);}
+static void exitfunc20(void) { printf("Executing exitfunc20.\n"); exit(0);}
+static void exitfunc21(void) { printf("Executing exitfunc21.\n"); exit(0);}
+static void exitfunc22(void) { printf("Executing exitfunc22.\n"); exit(0);}
+static void exitfunc23(void) { printf("Executing exitfunc23.\n"); exit(0);}
+static void exitfunc24(void) { printf("Executing exitfunc24.\n"); exit(0);}
+
+static vfuncp func_table[] =
+ {
+ exitfunc0, exitfunc1, exitfunc2, exitfunc3, exitfunc4,
+ exitfunc5, exitfunc6, exitfunc7, exitfunc8, exitfunc9,
+ exitfunc10, exitfunc11, exitfunc12, exitfunc13, exitfunc14,
+ exitfunc15, exitfunc16, exitfunc17, exitfunc18, exitfunc19,
+ exitfunc20, exitfunc21, exitfunc22, exitfunc23, exitfunc24
+ };
+
+/* glibc dynamically adds exit functions, so it will keep adding until
+ * it runs out of memory! So this will limit the number of exit functions
+ * we add in the loop below. uClibc has a set limit (currently 20), so the
+ * loop will go until it can't add any more (so it should not hit this limit).
+ */
+#define ATEXIT_LIMIT 20
+
+int
+main ( void )
+{
+ int i = 0;
+ int count = 0;
+ int numfuncs = sizeof(func_table)/sizeof(vfuncp);
+
+ /* loop until no more can be added */
+ while(count < ATEXIT_LIMIT && atexit(func_table[i]) >= 0) {
+ printf("Registered exitfunc%d with atexit()\n", i);
+ count++;
+ i = (i+1) % numfuncs;
+ }
+ printf("%d functions registered with atexit.\n", count);
+ /* implicit exit */
+}
+
diff --git a/test/stdlib/teston_exit.c b/test/stdlib/teston_exit.c
new file mode 100644
index 000000000..ddfe506a4
--- /dev/null
+++ b/test/stdlib/teston_exit.c
@@ -0,0 +1,75 @@
+/*
+ * This test program will register the maximum number of exit functions
+ * with on_exit(). When this program exits, each exit function should get
+ * called in the reverse order in which it was registered. (If the system
+ * supports more than 25 exit functions, the function names will loop, but
+ * the effect will be the same. Feel free to add more functions if desired)
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef void (*efuncp) (int, void *);
+
+/* All functions call exit(), in order to test that exit functions can call
+ * exit() without screwing everything up. The value passed in through arg gets
+ * used as the next exit status.
+ */
+static void exitfunc0(int status, void *arg) { printf("Executing exitfunc0 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc1(int status, void *arg) { printf("Executing exitfunc1 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc2(int status, void *arg) { printf("Executing exitfunc2 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc3(int status, void *arg) { printf("Executing exitfunc3 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc4(int status, void *arg) { printf("Executing exitfunc4 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc5(int status, void *arg) { printf("Executing exitfunc5 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc6(int status, void *arg) { printf("Executing exitfunc6 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc7(int status, void *arg) { printf("Executing exitfunc7 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc8(int status, void *arg) { printf("Executing exitfunc8 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc9(int status, void *arg) { printf("Executing exitfunc9 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc10(int status, void *arg) { printf("Executing exitfunc10 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc11(int status, void *arg) { printf("Executing exitfunc11 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc12(int status, void *arg) { printf("Executing exitfunc12 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc13(int status, void *arg) { printf("Executing exitfunc13 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc14(int status, void *arg) { printf("Executing exitfunc14 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc15(int status, void *arg) { printf("Executing exitfunc15 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc16(int status, void *arg) { printf("Executing exitfunc16 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc17(int status, void *arg) { printf("Executing exitfunc17 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc18(int status, void *arg) { printf("Executing exitfunc18 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc19(int status, void *arg) { printf("Executing exitfunc19 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc20(int status, void *arg) { printf("Executing exitfunc20 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc21(int status, void *arg) { printf("Executing exitfunc21 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc22(int status, void *arg) { printf("Executing exitfunc22 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc23(int status, void *arg) { printf("Executing exitfunc23 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+static void exitfunc24(int status, void *arg) { printf("Executing exitfunc24 (status=%d, arg=%d)\n", status, (int)arg); exit((int)arg);}
+
+static efuncp func_table[] =
+ {
+ exitfunc0, exitfunc1, exitfunc2, exitfunc3, exitfunc4,
+ exitfunc5, exitfunc6, exitfunc7, exitfunc8, exitfunc9,
+ exitfunc10, exitfunc11, exitfunc12, exitfunc13, exitfunc14,
+ exitfunc15, exitfunc16, exitfunc17, exitfunc18, exitfunc19,
+ exitfunc20, exitfunc21, exitfunc22, exitfunc23, exitfunc24
+ };
+
+/* glibc dynamically adds exit functions, so it will keep adding until
+ * it runs out of memory! So this will limit the number of exit functions
+ * we add in the loop below. uClibc has a set limit (currently 20), so the
+ * loop will go until it can't add any more (so it should not hit this limit).
+ */
+#define ON_EXIT_LIMIT 20
+
+int
+main ( void )
+{
+ int i = 0;
+ int count = 0;
+ int numfuncs = sizeof(func_table)/sizeof(efuncp);
+
+ /* loop until no more can be added */
+ while(count < ON_EXIT_LIMIT && on_exit(func_table[i], (void *)count) >= 0) {
+ count++;
+ printf("Registered exitfunc%d with on_exit()\n", i);
+ i = (i+1) % numfuncs;
+ }
+ printf("%d functions registered with on_exit.\n", count);
+ exit(count);
+}
+