From 80104fc9739f5ea3ca6d0993ef531760b4d9b415 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 7 Dec 2003 04:26:41 +0000 Subject: [PATCH] Thread testing code for libcaps. --- test/caps/Makefile | 17 +++++++--- test/caps/thr1.c | 70 ++++++++++++++++++++++++++++++++++++++ test/caps/thr2.c | 69 ++++++++++++++++++++++++++++++++++++++ test/caps/thr3.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 test/caps/thr1.c create mode 100644 test/caps/thr2.c create mode 100644 test/caps/thr3.c diff --git a/test/caps/Makefile b/test/caps/Makefile index 9dfe2408da..ce82d2cdc2 100644 --- a/test/caps/Makefile +++ b/test/caps/Makefile @@ -1,12 +1,21 @@ -# $DragonFly: src/test/caps/Makefile,v 1.1 2003/11/24 21:15:59 dillon Exp $ +# $DragonFly: src/test/caps/Makefile,v 1.2 2003/12/07 04:26:41 dillon Exp $ # -TARGETS=/tmp/caps1 +TARGETS=/tmp/caps1 /tmp/thr1 /tmp/thr2 /tmp/thr3 -CFLAGS= -O2 -g -I/usr/src/lib +CFLAGS= -O2 -g -I/usr/src/lib -I/usr/src/lib/libcaps/${MACHINE_ARCH} -DSMP all: $(TARGETS) /tmp/caps1: caps1.c - $(CC) $(CFLAGS) caps1.c -llwkt -o /tmp/caps1 + $(CC) $(CFLAGS) caps1.c -lcaps -o /tmp/caps1 + +/tmp/thr1: thr1.c + $(CC) $(CFLAGS) thr1.c -lcaps -o /tmp/thr1 + +/tmp/thr2: thr2.c + $(CC) $(CFLAGS) thr2.c -lcaps -o /tmp/thr2 + +/tmp/thr3: thr3.c + $(CC) $(CFLAGS) thr3.c -lcaps -o /tmp/thr3 diff --git a/test/caps/thr1.c b/test/caps/thr1.c new file mode 100644 index 0000000000..08784a6236 --- /dev/null +++ b/test/caps/thr1.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2003 Matthew Dillon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/test/caps/thr1.c,v 1.1 2003/12/07 04:26:41 dillon Exp $ + */ +#include +#include + +extern int mp_lock; + +static void thread1(void *data); +static void thread2(void *data); + +int +main(int ac, char **av) +{ + thread_t td; + thread_t td1; + thread_t td2; + + uthread_init(); + td = curthread; + printf("mainthread %p crit_count %d nest %d mp_lock %d\n", + td, td->td_pri / TDPRI_CRIT, td->td_mpcount, mp_lock + ); + lwkt_create(thread1, NULL, &td1, NULL, 0, -1, "thread1"); + lwkt_create(thread2, NULL, &td2, NULL, 0, -1, "thread2"); + printf("thread #1 %p #2 %p\n", td1, td2); + printf("switching away from main (should come back before exit)\n"); + lwkt_switch(); + printf("Switched back to main, main Exiting\n"); + exit(1); +} + +void +thread1(void *data) +{ + printf("thread1 running\n"); + printf("thread1 exiting\n"); +} + +void +thread2(void *data) +{ + printf("thread2 running\n"); + printf("thread2 exiting\n"); +} + diff --git a/test/caps/thr2.c b/test/caps/thr2.c new file mode 100644 index 0000000000..81757470ae --- /dev/null +++ b/test/caps/thr2.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2003 Matthew Dillon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/test/caps/thr2.c,v 1.1 2003/12/07 04:26:41 dillon Exp $ + */ +#include +#include + +extern int mp_lock; + +static void thread1(void *data); +static void thread2(void *data); + +int +main(int ac, char **av) +{ + thread_t td; + thread_t td1; + thread_t td2; + + uthread_init(); + lwkt_create(thread1, NULL, &td1, NULL, 0, -1, "thread1"); + lwkt_create(thread2, NULL, &td2, NULL, 0, -1, "thread2"); + lwkt_switch(); + printf("Main Exiting\n"); + exit(1); +} + +void +thread1(void *data) +{ + int i; + for (i = 0; i < 1000000; ++i) + lwkt_switch(); + printf("done1\n"); +} + +void +thread2(void *data) +{ + int i; + for (i = 0; i < 1000000; ++i) + lwkt_switch(); + printf("done2\n"); + exit(0); +} + diff --git a/test/caps/thr3.c b/test/caps/thr3.c new file mode 100644 index 0000000000..2af6a216b7 --- /dev/null +++ b/test/caps/thr3.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2003 Matthew Dillon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/test/caps/thr3.c,v 1.1 2003/12/07 04:26:41 dillon Exp $ + */ +#include +#include + +extern int mp_lock; + +static void thread1(void *data); +static void thread2(void *data); + +int +main(int ac, char **av) +{ + thread_t td; + thread_t td1; + thread_t td2; + int tcpu; + + uthread_init(); + tcpu = caps_fork_vcpu(); + printf("caps_fork_vcpu %d\n", tcpu); + lwkt_create(thread1, NULL, &td1, NULL, 0, -1, "thread1"); + lwkt_create(thread2, NULL, &td2, NULL, 0, tcpu, "thread2"); + lwkt_deschedule_self(); + lwkt_switch(); + printf("Main thread resumed after all children exiting.\n"); + printf("Running test a second time to see if UPC_CONTROL_WAIT works\n"); + lwkt_create(thread1, NULL, &td1, NULL, 0, -1, "thread1"); + lwkt_create(thread2, NULL, &td2, NULL, 0, tcpu, "thread2"); + lwkt_deschedule_self(); + lwkt_switch(); + printf("Main thread resumed after second test, exiting\n"); + exit(0); +} + +void +thread1(void *data) +{ + int i; + + printf("start1 pri %d mp %d\n", curthread->td_pri, curthread->td_mpcount); + rel_mplock(); + for (i = 0; i < 100000000; ++i) + lwkt_switch(); + printf("done1 %d\n", (int)getpid()); +} + +void +thread2(void *data) +{ + int i; + + printf("start2 pri %d mp %d\n", curthread->td_pri, curthread->td_mpcount); + for (i = 0; i < 10000000; ++i) + lwkt_switch(); + printf("done2 %d\n", (int)getpid()); +} + -- 2.41.0