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
77 clean nuke:V:
88 rm -f *.[$OS] [$OS].out $LIB
99
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+
libbt/test/ai.c+4−9
@@ -19,7 +19,7 @@ rstate(void) · 18 unmodified lines
1919 int
2020 pstate(int state)
2121 {
22− print("\t%s\n", btstatenames[state]);
22+ print(" -> %s\n", btstatenames[state]);
2323 return state;
2424 }
2525
@@ -54,14 +54,10 @@ afind(void *a) · 28 unmodified lines
5454 int
5555 amove(void *a)
5656 {
57− Point p, t;
5857 Agent *agent = a;
5958
6059 print("move");
6160
62− p = agent->pos;
63− t = agent->target;
64−
6561 if((abs(agent->pos.x - agent->target.x) + abs(agent->pos.y - agent->target.y)) < 2)
6662 return pstate(TASKSUCCESS);
6763
@@ -90,7 +86,7 @@ amove(void *a) · 22 unmodified lines
9086
9187 /* simulate hitting an enemy */
9288 int
93−ahit(void*)
89+ahit(void *a)
9490 {
9591 print("hit");
9692
@@ -169,12 +165,11 @@ main(int argc, char *argv[]) · 72 unmodified lines
169165 usage();
170166 }ARGEND
171167
172− #include <pool.h>
173− mainmem->flags = POOL_ANTAGONISM|POOL_PARANOIA;
174−
175168 fmtinstall('P', Pfmt);
176169 fmtinstall('T', btfmt);
177170
171+ alarm(5000);
172+
178173 srand(truerand());
179174
180175 test_bt();
libbt/test/bt.c+3−1
@@ -109,7 +109,7 @@ test_bt(void) · 108 unmodified lines
109109 while(a.hunger > 0){
110110 bttick(root, &a);
111111 print("hunger=%d food=%d\n", a.hunger, a.food);
112− sleep(200);
112+ sleep(10);
113113 }
114114 }
115115
@@ -128,6 +128,8 @@ main(int argc, char *argv[]) · 12 unmodified lines
128128 usage();
129129 }ARGEND
130130
131+ alarm(5000);
132+
131133 srand(truerand());
132134
133135 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+
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+}
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
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+
libbt/test/mkfile+1−0
@@ -6,3 +6,4 @@ CFLAGS=-N $CFLAGS -I.. · 5 unmodified lines
66 LIB=../libbt.$O.a
77
88 </sys/src/cmd/mkmany
9+