summaryrefslogtreecommitdiffstats
path: root/regress/lib/libpthread/stack/stack.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2012-08-04 21:55:22 +0000
committerguenther <guenther@openbsd.org>2012-08-04 21:55:22 +0000
commitc187d9299cfbb775a9a0666fd2b5209a3820d443 (patch)
treebdeefe347ca1c4818b5bca1cf7d9b1d6995000c7 /regress/lib/libpthread/stack/stack.c
parentPCI_PRODUCT_ATI_RADEON_X1250 -> PCI_PRODUCT_ATI_RADEON_X1250_{1,2} (diff)
downloadwireguard-openbsd-c187d9299cfbb775a9a0666fd2b5209a3820d443.tar.xz
wireguard-openbsd-c187d9299cfbb775a9a0666fd2b5209a3820d443.zip
Add a test for caching of stacks with the default attributes
Diffstat (limited to 'regress/lib/libpthread/stack/stack.c')
-rw-r--r--regress/lib/libpthread/stack/stack.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/regress/lib/libpthread/stack/stack.c b/regress/lib/libpthread/stack/stack.c
index e11d512f1fb..32435b95800 100644
--- a/regress/lib/libpthread/stack/stack.c
+++ b/regress/lib/libpthread/stack/stack.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stack.c,v 1.2 2012/02/19 06:49:26 guenther Exp $ */
+/* $OpenBSD: stack.c,v 1.3 2012/08/04 21:55:22 guenther Exp $ */
/* PUBLIC DOMAIN Feb 2012 <guenther@openbsd.org> */
/* Test the handling of the pthread_attr_t stack attributes */
@@ -16,6 +16,15 @@
#define LARGE_SIZE (1024 * 1024)
+/* thread main for plain location tests */
+void *
+tmain0(void *arg)
+{
+ int s;
+
+ return (&s);
+}
+
/* thread main for testing a large buffer on the stack */
void *
tmain1(void *arg)
@@ -85,6 +94,26 @@ main(void)
ASSERT(size2 == size);
+ /* create a thread with the default stack attr so we can test reuse */
+ CHECKr(pthread_create(&t, NULL, &tmain0, NULL));
+ sleep(1);
+ CHECKr(pthread_join(t, &addr));
+
+ /*
+ * verify that the stack has *not* been freed: we expect it to be
+ * cached for reuse. This is unportable for the same reasons as
+ * the mquery() test below. :-/
+ */
+ *(int *)addr = 100;
+
+
+ /* do the above again and make sure the stack got reused */
+ CHECKr(pthread_create(&t, NULL, &tmain0, NULL));
+ sleep(1);
+ CHECKr(pthread_join(t, &addr2));
+ ASSERT(addr == addr2);
+
+
/*
* increase the stacksize, then verify that the change sticks,
* and that a large buffer fits on the resulting thread's stack