Unified · Split
| @@ -7,3 +7,12 @@ · 6 unmodified lines | ||
| 7 | 7 | clean nuke:V: |
| 8 | 8 | rm -f *.[$OS] [$OS].out $LIB |
| 9 | 9 | |
| 10 | +test:QV: | |
| 11 | + cd test | |
| 12 | + mk -f mk.p9p clean | |
| 13 | + mk -f mk.p9p all | |
| 14 | + for t in $O.*; do | |
| 15 | + echo $t... | |
| 16 | + ./$t | |
| 17 | + done | |
| 18 | + | |
| @@ -19,7 +19,7 @@ rstate(void) · 18 unmodified lines | ||
| 19 | 19 | int |
| 20 | 20 | pstate(int state) |
| 21 | 21 | { |
| 22 | − print("\t%s\n", btstatenames[state]); | |
| 22 | + print(" -> %s\n", btstatenames[state]); | |
| 23 | 23 | return state; |
| 24 | 24 | } |
| 25 | 25 | |
| @@ -54,14 +54,10 @@ afind(void *a) · 28 unmodified lines | ||
| 54 | 54 | int |
| 55 | 55 | amove(void *a) |
| 56 | 56 | { |
| 57 | − Point p, t; | |
| 58 | 57 | Agent *agent = a; |
| 59 | 58 | |
| 60 | 59 | print("move"); |
| 61 | 60 | |
| 62 | − p = agent->pos; | |
| 63 | − t = agent->target; | |
| 64 | − | |
| 65 | 61 | if((abs(agent->pos.x - agent->target.x) + abs(agent->pos.y - agent->target.y)) < 2) |
| 66 | 62 | return pstate(TASKSUCCESS); |
| 67 | 63 | |
| @@ -90,7 +86,7 @@ amove(void *a) · 22 unmodified lines | ||
| 90 | 86 | |
| 91 | 87 | /* simulate hitting an enemy */ |
| 92 | 88 | int |
| 93 | −ahit(void*) | |
| 89 | +ahit(void *a) | |
| 94 | 90 | { |
| 95 | 91 | print("hit"); |
| 96 | 92 | |
| @@ -169,12 +165,11 @@ main(int argc, char *argv[]) · 72 unmodified lines | ||
| 169 | 165 | usage(); |
| 170 | 166 | }ARGEND |
| 171 | 167 | |
| 172 | − #include <pool.h> | |
| 173 | − mainmem->flags = POOL_ANTAGONISM|POOL_PARANOIA; | |
| 174 | − | |
| 175 | 168 | fmtinstall('P', Pfmt); |
| 176 | 169 | fmtinstall('T', btfmt); |
| 177 | 170 | |
| 171 | + alarm(5000); | |
| 172 | + | |
| 178 | 173 | srand(truerand()); |
| 179 | 174 | |
| 180 | 175 | test_bt(); |
| @@ -109,7 +109,7 @@ test_bt(void) · 108 unmodified lines | ||
| 109 | 109 | while(a.hunger > 0){ |
| 110 | 110 | bttick(root, &a); |
| 111 | 111 | print("hunger=%d food=%d\n", a.hunger, a.food); |
| 112 | − sleep(200); | |
| 112 | + sleep(10); | |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| @@ -128,6 +128,8 @@ main(int argc, char *argv[]) · 12 unmodified lines | ||
| 128 | 128 | usage(); |
| 129 | 129 | }ARGEND |
| 130 | 130 | |
| 131 | + alarm(5000); | |
| 132 | + | |
| 131 | 133 | srand(truerand()); |
| 132 | 134 | |
| 133 | 135 | test_bt(); |
| @@ -0,0 +1,82 @@ | ||
| 1 | +#include <u.h> | |
| 2 | +#include <libc.h> | |
| 3 | +#include <bio.h> | |
| 4 | + | |
| 5 | +#include <bt.h> | |
| 6 | + | |
| 7 | +static unsigned long | |
| 8 | +memuse(void) | |
| 9 | +{ | |
| 10 | + unsigned long b; | |
| 11 | + | |
| 12 | + b = 0; | |
| 13 | +#ifdef __linux__ | |
| 14 | + int fd = open("/proc/self/status", OREAD); | |
| 15 | + if(fd == -1) | |
| 16 | + return 0; | |
| 17 | + | |
| 18 | + Biobuf rb; | |
| 19 | + if(Binit(&rb, fd, OREAD) != 0){ | |
| 20 | + close(fd); | |
| 21 | + return 0; | |
| 22 | + } | |
| 23 | + | |
| 24 | + char *line; | |
| 25 | + | |
| 26 | + while((line = Brdstr(&rb, '\n', 1)) != nil){ | |
| 27 | + if(strncmp(line, "VmRSS:", 6) == 0){ | |
| 28 | + /* in kB */ | |
| 29 | + b = strtoul(line+6, nil, 10); | |
| 30 | + b *= 1000; | |
| 31 | + free(line); | |
| 32 | + break; | |
| 33 | + } | |
| 34 | + free(line); | |
| 35 | + } | |
| 36 | + | |
| 37 | + Bterm(&rb); | |
| 38 | + close(fd); | |
| 39 | +#endif | |
| 40 | + | |
| 41 | + return b; | |
| 42 | +} | |
| 43 | + | |
| 44 | +static int | |
| 45 | +nop(void *a) | |
| 46 | +{ | |
| 47 | +} | |
| 48 | + | |
| 49 | +BehaviorNode* | |
| 50 | +mkbt(void) | |
| 51 | +{ | |
| 52 | + BehaviorNode *one, *two, *three; | |
| 53 | + BehaviorNode *root; | |
| 54 | + | |
| 55 | + one = btleaf("one", nop); | |
| 56 | + two = btleaf("two", nop); | |
| 57 | + three = btleaf("three", nop); | |
| 58 | + | |
| 59 | + root = btsequence("root", one, two, three, nil); | |
| 60 | + | |
| 61 | + return root; | |
| 62 | +} | |
| 63 | + | |
| 64 | +void | |
| 65 | +main(int argc, char *argv[]) | |
| 66 | +{ | |
| 67 | + int n; | |
| 68 | + | |
| 69 | + ARGBEGIN{ | |
| 70 | + default: | |
| 71 | + sysfatal("no argumnts"); | |
| 72 | + }ARGEND | |
| 73 | + | |
| 74 | + n = 100000; | |
| 75 | + | |
| 76 | + while(n-- > 0) | |
| 77 | + mkbt(); | |
| 78 | + | |
| 79 | + print("%lud\n", memuse()); | |
| 80 | + | |
| 81 | + exits(nil); | |
| 82 | +} | |
| @@ -0,0 +1,11 @@ | ||
| 1 | +<$PLAN9/src/mkhdr | |
| 2 | + | |
| 3 | +# plan9port is too dumb to clear OFILES for us | |
| 4 | +OFILES= | |
| 5 | +TARG=`ls *.c | sed 's/\.c//g'` | |
| 6 | + | |
| 7 | +CFLAGS=$CFLAGS -I.. | |
| 8 | +LIB=../libbt.$O.a | |
| 9 | + | |
| 10 | +<$PLAN9/src/mkmany | |
| 11 | + | |
| @@ -6,3 +6,4 @@ CFLAGS=-N $CFLAGS -I.. · 5 unmodified lines | ||
| 6 | 6 | LIB=../libbt.$O.a |
| 7 | 7 | |
| 8 | 8 | </sys/src/cmd/mkmany |
| 9 | + | |