From: Ken Raeburn Date: Tue, 3 Aug 2004 20:55:32 +0000 (+0000) Subject: * Makefile.in, t_rcache.c: New files X-Git-Tag: krb5-1.4-beta1~172 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b2b3c578722f6ff770d22af78136168eeac70a7b;p=krb5.git * Makefile.in, t_rcache.c: New files git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16636 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/tests/threads/ChangeLog b/src/tests/threads/ChangeLog new file mode 100644 index 000000000..b4c90abb3 --- /dev/null +++ b/src/tests/threads/ChangeLog @@ -0,0 +1,4 @@ +2004-08-03 Ken Raeburn + + * Makefile.in, t_rcache.c: New files. + diff --git a/src/tests/threads/Makefile.in b/src/tests/threads/Makefile.in new file mode 100644 index 000000000..dfcc03127 --- /dev/null +++ b/src/tests/threads/Makefile.in @@ -0,0 +1,39 @@ +thisconfigdir=./.. +myfulldir=tests/threads +mydir=threads +BUILDTOP=$(REL)..$(S).. +PROG_LIBPATH=-L$(TOPLIBD) +PROG_RPATH=$(KRB5_LIBDIR) + +RUN_SETUP = @KRB5_RUN_ENV@ + +SRCS=$(srcdir)/t_rcache.c + +all:: + +N = 4 +run-t_rcache: t_rcache + $(RUN_SETUP) ./t_rcache -n $(N) + +t_rcache: t_rcache.o $(KRB5_BASE_DEPLIBS) + $(CC_LINK) -o t_rcache t_rcache.o $(KRB5_BASE_LIBS) -lpthread + +syms: syms.o + $(CC_LINK) -o syms syms.o + +run-syms: syms + $(RUN_SETUP) ./syms + +check-unix:: run-t_rcache + +install:: + +clean:: + $(RM) t_rcache.o t_rcache + +# +++ Dependency line eater +++ +# +# Makefile dependencies follow. This must be the last section in +# the Makefile.in file +# + diff --git a/src/tests/threads/t_rcache.c b/src/tests/threads/t_rcache.c new file mode 100644 index 000000000..251c872af --- /dev/null +++ b/src/tests/threads/t_rcache.c @@ -0,0 +1,143 @@ +#include +#include +#include +#include "k5-int.h" +#include + +krb5_context ctx; +krb5_rcache rcache; +krb5_data piece = { .data = "hello", .length = 5 }; +time_t end_time; +const char *prog; + +struct tinfo { + time_t now; + unsigned long my_ctime; + unsigned int my_cusec; + unsigned int total; + int idx; +}; + +#undef INIT_ONCE + +static void try_one (struct tinfo *t) +{ + krb5_donot_replay r; + krb5_error_code err; + char buf[100], buf2[100]; + krb5_rcache my_rcache; + + sprintf(buf, "host/all-in-one.mit.edu/%p@ATHENA.MIT.EDU", buf); + r.server = buf; + r.client = (t->my_cusec & 7) + "abcdefgh@ATHENA.MIT.EDU"; + if (t->now != t->my_ctime) { + if (t->my_ctime != 0) { + sprintf(buf2, "%3d: %ld %5d\n", t->idx, t->my_ctime, t->my_cusec); + printf("%s", buf2); + } + t->my_ctime = t->now; + t->my_cusec = 1; + } else + t->my_cusec++; + r.ctime = t->my_ctime; + r.cusec = t->my_cusec; +#ifndef INIT_ONCE + err = krb5_get_server_rcache(ctx, &piece, &my_rcache); + if (err) { + com_err(prog, err, "getting replay cache"); + exit(1); + } +#else + my_rcache = rcache; +#endif + err = krb5_rc_store(ctx, my_rcache, &r); + if (err) { + com_err(prog, err, "storing in replay cache"); + exit(1); + } +#ifndef INIT_ONCE + krb5_rc_close(ctx, my_rcache); +#endif +} + +static void *run_a_loop (void *x) +{ + struct tinfo t = { 0 }; +/* int chr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"[(*(int*)x) % 27]; */ + + t.now = time(0); + t.idx = *(int *)x; + while (t.now != time(0)) + ; + t.now = time(0); + while (t.now < end_time) { + t.now = time(0); + try_one(&t); + t.total++; +/* printf("%c", chr); */ + fflush(stdout); + } + printf("thread %p total %u\n", &t, t.total); + *(int*)x = t.total; + return 0; +} + +int main (int argc, char *argv[]) +{ + int n; + krb5_error_code err; + int interval = 20 /* 5 * 60 */; + + prog = argv[0]; + unlink("/var/tmp/rc_hello_7882"); + unlink("/var/tmp/hello_7882"); + n = 2; + err = krb5_init_context(&ctx); + if (err) { + com_err(prog, err, "initializing context"); + return 1; + } +#ifdef INIT_ONCE + err = krb5_get_server_rcache(ctx, &piece, &rcache); + if (err) { + com_err(prog, err, "getting replay cache"); + return 1; + } +#endif + end_time = time(0) + interval; +#undef DIRECT +#ifdef DIRECT + { + int zero = 0; + run_a_loop(&zero); + } +#else + { + int i, *ip; + + ip = malloc(sizeof(int) * n); + if (ip == 0 && n > 0) { + perror("malloc"); + exit(1); + } + for (i = 0; i < n; i++) + ip[i] = i; + + for (i = 0; i < n; i++) { + pthread_t new_thread; + int perr; + perr = pthread_create(&new_thread, 0, run_a_loop, &ip[i]); + if (perr) { + errno = perr; + perror("pthread_create"); + exit(1); + } + } + while (time(0) < end_time + 1) + sleep(1); + for (i = 0; i < n; i++) + printf("thread %d total %5d\n", i, ip[i]); + } +#endif + return 0; +}