History

fix up libbt tests, check memory use

mischief committed 9 years ago

Commit 3c495c31 parent f3b79a06 files · +110 −10Browse files

Unified · Split

6 files
  1. libbt/mk.p9p +9 −0
  2. libbt/test/ai.c +4 −9
  3. libbt/test/bt.c +3 −1
  4. libbt/test/memuse.c +82 −0
  5. libbt/test/mk.p9p +11 −0
  6. libbt/test/mkfile +1 −0
libbt/mk.p9p+9−0
@@ -7,3 +7,12 @@ · 6 unmodified lines
7clean nuke:V:7clean nuke:V:
8 rm -f *.[$OS] [$OS].out $LIB8 rm -f *.[$OS] [$OS].out $LIB
9 9
10test: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
libbt/test/ai.c+4−9
@@ -19,7 +19,7 @@ rstate(void) · 18 unmodified lines
19int19int
20pstate(int state)20pstate(int state)
21{21{
22 print("\t%s\n", btstatenames[state]);22 print(" -> %s\n", btstatenames[state]);
23 return state;23 return state;
24}24}
25 25
@@ -54,14 +54,10 @@ afind(void *a) · 28 unmodified lines
54int54int
55amove(void *a)55amove(void *a)
56{56{
57 Point p, t;
58 Agent *agent = a;57 Agent *agent = a;
59 58
60 print("move");59 print("move");
61 60
62 p = agent->pos;
63 t = agent->target;
64
65 if((abs(agent->pos.x - agent->target.x) + abs(agent->pos.y - agent->target.y)) < 2)61 if((abs(agent->pos.x - agent->target.x) + abs(agent->pos.y - agent->target.y)) < 2)
66 return pstate(TASKSUCCESS);62 return pstate(TASKSUCCESS);
67 63
@@ -90,7 +86,7 @@ amove(void *a) · 22 unmodified lines
90 86
91/* simulate hitting an enemy */87/* simulate hitting an enemy */
92int88int
93ahit(void*)89ahit(void *a)
94{90{
95 print("hit");91 print("hit");
96 92
@@ -169,12 +165,11 @@ main(int argc, char *argv[]) · 72 unmodified lines
169 usage();165 usage();
170 }ARGEND166 }ARGEND
171 167
172 #include <pool.h>
173 mainmem->flags = POOL_ANTAGONISM|POOL_PARANOIA;
174
175 fmtinstall('P', Pfmt);168 fmtinstall('P', Pfmt);
176 fmtinstall('T', btfmt);169 fmtinstall('T', btfmt);
177 170
171 alarm(5000);
172
178 srand(truerand());173 srand(truerand());
179 174
180 test_bt();175 test_bt();
libbt/test/bt.c+3−1
@@ -109,7 +109,7 @@ test_bt(void) · 108 unmodified lines
109 while(a.hunger > 0){109 while(a.hunger > 0){
110 bttick(root, &a);110 bttick(root, &a);
111 print("hunger=%d food=%d\n", a.hunger, a.food);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 usage();128 usage();
129 }ARGEND129 }ARGEND
130 130
131 alarm(5000);
132
131 srand(truerand());133 srand(truerand());
132 134
133 test_bt();135 test_bt();
libbt/test/memuse.c+82−0
@@ -0,0 +1,82 @@
1#include <u.h>
2#include <libc.h>
3#include <bio.h>
4
5#include <bt.h>
6
7static unsigned long
8memuse(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
44static int
45nop(void *a)
46{
47}
48
49BehaviorNode*
50mkbt(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
64void
65main(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}
libbt/test/mk.p9p+11−0
@@ -0,0 +1,11 @@
1<$PLAN9/src/mkhdr
2
3# plan9port is too dumb to clear OFILES for us
4OFILES=
5TARG=`ls *.c | sed 's/\.c//g'`
6
7CFLAGS=$CFLAGS -I..
8LIB=../libbt.$O.a
9
10<$PLAN9/src/mkmany
11
libbt/test/mkfile+1−0
@@ -6,3 +6,4 @@ CFLAGS=-N $CFLAGS -I.. · 5 unmodified lines
6LIB=../libbt.$O.a6LIB=../libbt.$O.a
7 7
8</sys/src/cmd/mkmany8</sys/src/cmd/mkmany
9