summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormostang.com!davidm <mostang.com!davidm>2004-01-21 06:36:35 +0000
committermostang.com!davidm <mostang.com!davidm>2004-01-21 06:36:35 +0000
commita54ee8800953d330752704157f58e8375d850b86 (patch)
tree9d650d04e39d9a5194485ba567c46b7347ecaca2
parentf928eec36a362d66cacef4d01fbe1cf7b7b4f93d (diff)
downloadlibunwind-a54ee8800953d330752704157f58e8375d850b86.tar.gz
(Logical change 1.157)
-rw-r--r--tests/forker.c76
-rw-r--r--tests/perf-startup19
-rw-r--r--tests/test-static-link-gen.c68
-rw-r--r--tests/test-static-link-loc.c100
4 files changed, 263 insertions, 0 deletions
diff --git a/tests/forker.c b/tests/forker.c
new file mode 100644
index 00000000..b03f86a7
--- /dev/null
+++ b/tests/forker.c
@@ -0,0 +1,76 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2004 Hewlett-Packard Co
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int
+main (int argc, char **argv, char **envp)
+{
+ char *program, **child_argv;
+ struct timeval start, stop;
+ double secs;
+ int status, i;
+ long count;
+ pid_t pid;
+
+ count = atol (argv[1]);
+ program = argv[2];
+
+ child_argv = alloca ((argc - 1) * sizeof (char *));
+ for (i = 0; i < argc - 2; ++i)
+ child_argv[i] = argv[2 + i];
+ child_argv[i] = NULL;
+
+ gettimeofday (&start, NULL);
+ for (i = 0; i < count; ++i)
+ {
+ pid = fork ();
+ if (pid == 0)
+ {
+ execve (program, child_argv, envp);
+ _exit (-1);
+ }
+ else
+ {
+ waitpid (pid, &status, 0);
+ if (!WIFEXITED (status) || WEXITSTATUS (status) != 0)
+ {
+ fprintf (stderr, "%s: child failed\n", argv[0]);
+ exit (-1);
+ }
+ }
+ }
+ gettimeofday (&stop, NULL);
+
+ secs = ((stop.tv_sec + 1e-6 * stop.tv_usec)
+ - (start.tv_sec + 1e-6 * start.tv_usec));
+ printf ("%lu nsec/execution\n",
+ (unsigned long) (1e9 * secs / (double) count));
+ return 0;
+}
diff --git a/tests/perf-startup b/tests/perf-startup
new file mode 100644
index 00000000..c3707487
--- /dev/null
+++ b/tests/perf-startup
@@ -0,0 +1,19 @@
+#!/bin/sh
+platform=$1
+LIBUNWIND=../src/.libs/libunwind.so
+LIBUNWIND_PLAT=../src/.libs/libunwind-$platform.so
+warmup=$(./forker 2000 /bin/true | cut -f1 -d' ')
+
+nsec1=$(./forker 2000 /bin/true | cut -f1 -d' ')
+echo -e \"/bin/true\""\t\t\t\t\t\t": $nsec1 nsec/execution
+
+nsec2=$(LD_PRELOAD=$LIBUNWIND ./forker 2000 /bin/true | cut -f1 -d' ')
+echo -e \"LD_PRELOAD=$LIBUNWIND /bin/true\""\t": $nsec2 nsec/execution
+
+nsec3=$(LD_PRELOAD=$LIBUNWIND_PLAT ./forker 2000 /bin/true | cut -f1 -d' ')
+echo -e \"LD_PRELOAD=$LIBUNWIND_PLAT /bin/true\""\t": $nsec3 nsec/execution
+
+echo
+
+echo -e "Overhead of preloading $LIBUNWIND\t: " $(($nsec2 - $nsec1)) nsec
+echo -e "Overhead of preloading $LIBUNWIND_PLAT\t: " $(($nsec3 - $nsec1)) nsec
diff --git a/tests/test-static-link-gen.c b/tests/test-static-link-gen.c
new file mode 100644
index 00000000..37ed1fe9
--- /dev/null
+++ b/tests/test-static-link-gen.c
@@ -0,0 +1,68 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2004 Hewlett-Packard Co
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+This file is part of libunwind.
+
+Copyright (c) 2003 Hewlett-Packard Co.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include <stdio.h>
+
+#include <libunwind.h>
+
+extern int verbose;
+
+static void *funcs[] =
+ {
+ (void *) &unw_get_reg,
+ (void *) &unw_get_fpreg,
+ (void *) &unw_set_reg,
+ (void *) &unw_set_fpreg,
+ (void *) &unw_resume,
+ (void *) &unw_create_addr_space,
+ (void *) &unw_destroy_addr_space,
+ (void *) &unw_get_accessors,
+ (void *) &unw_flush_cache,
+ (void *) &unw_set_caching_policy,
+ (void *) &unw_regname,
+ (void *) &unw_get_proc_info,
+ (void *) &unw_get_save_loc,
+ (void *) &unw_is_signal_frame,
+ (void *) &unw_get_proc_name
+ };
+
+int
+test_generic (void)
+{
+ ucontext_t uc;
+ unw_cursor_t c;
+
+ if (verbose)
+ printf (__FILE__": funcs[0]=%p\n", funcs[0]);
+
+#ifndef UNW_REMOTE_ONLY
+ unw_getcontext (&uc);
+ unw_init_local (&c, &uc);
+ unw_init_remote (&c, unw_local_addr_space, &uc);
+#endif
+ return unw_step (&c);
+}
diff --git a/tests/test-static-link-loc.c b/tests/test-static-link-loc.c
new file mode 100644
index 00000000..8db905b0
--- /dev/null
+++ b/tests/test-static-link-loc.c
@@ -0,0 +1,100 @@
+/* libunwind - a platform-independent unwind library
+ Copyright (C) 2004 Hewlett-Packard Co
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+
+This file is part of libunwind.
+
+Copyright (c) 2003 Hewlett-Packard Co.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+/* The purpose of this program is simply to link in all libunwind-API
+ functions both in their local-only and generic variants and to make
+ sure that the final result can be linked statically. */
+
+#include <stdio.h>
+
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+
+extern int test_generic (void);
+
+int verbose;
+
+#ifdef UNW_REMOTE_ONLY
+
+int
+test_local (void)
+{
+ return 0;
+}
+
+#else /* !UNW_REMOTE_ONLY */
+
+static void *funcs[] =
+ {
+ (void *) &unw_get_reg,
+ (void *) &unw_get_fpreg,
+ (void *) &unw_set_reg,
+ (void *) &unw_set_fpreg,
+ (void *) &unw_resume,
+ (void *) &unw_create_addr_space,
+ (void *) &unw_destroy_addr_space,
+ (void *) &unw_get_accessors,
+ (void *) &unw_flush_cache,
+ (void *) &unw_set_caching_policy,
+ (void *) &unw_regname,
+ (void *) &unw_get_proc_info,
+ (void *) &unw_get_save_loc,
+ (void *) &unw_is_signal_frame,
+ (void *) &unw_get_proc_name,
+ (void *) &_U_dyn_register,
+ (void *) &_U_dyn_cancel
+ };
+
+int
+test_local (void)
+{
+ ucontext_t uc;
+ unw_cursor_t c;
+
+ if (verbose)
+ printf (__FILE__": funcs[0]=%p\n", funcs[0]);
+
+ unw_getcontext (&uc);
+ unw_init_local (&c, &uc);
+ unw_init_remote (&c, unw_local_addr_space, &uc);
+ return unw_step (&c);
+}
+
+#endif /* !UNW_REMOTE_ONLY */
+
+int
+main (int argc, char **argv)
+{
+ if (argc > 1)
+ verbose = 1;
+
+ if (test_local () < 0)
+ return -1;
+ if (test_generic () < 0)
+ return -1;
+ return 0;
+}