Skip to content

Commit 3c052c3

Browse files
committed
Exclude black box tests from generated docs
1 parent b70229d commit 3c052c3

27 files changed

+529
-482
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ jobs:
8989
odin build ./try_mbox/ -build-mode:lib -vet -strict-style -o:${{ matrix.opt }}
9090
fi
9191
92-
- name: Test try_mbox
93-
shell: bash
94-
run: |
95-
if [ "${{ matrix.opt }}" = "none" ]; then
96-
odin test ./try_mbox/ -vet -strict-style -disallow-do -o:none -debug
97-
else
98-
odin test ./try_mbox/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
99-
fi
100-
10192
- name: Build nbio_mbox lib
10293
shell: bash
10394
run: |
@@ -107,15 +98,6 @@ jobs:
10798
odin build ./nbio_mbox/ -build-mode:lib -vet -strict-style -o:${{ matrix.opt }}
10899
fi
109100
110-
- name: Test nbio_mbox
111-
shell: bash
112-
run: |
113-
if [ "${{ matrix.opt }}" = "none" ]; then
114-
odin test ./nbio_mbox/ -vet -strict-style -disallow-do -o:none -debug
115-
else
116-
odin test ./nbio_mbox/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
117-
fi
118-
119101
- name: Build pool lib
120102
shell: bash
121103
run: |
@@ -143,22 +125,40 @@ jobs:
143125
odin test ./tests/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
144126
fi
145127
146-
- name: Build pool_tests
128+
- name: Test tests/mbox
129+
shell: bash
130+
run: |
131+
if [ "${{ matrix.opt }}" = "none" ]; then
132+
odin test ./tests/mbox/ -vet -strict-style -disallow-do -o:none -debug
133+
else
134+
odin test ./tests/mbox/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
135+
fi
136+
137+
- name: Test tests/try_mbox
138+
shell: bash
139+
run: |
140+
if [ "${{ matrix.opt }}" = "none" ]; then
141+
odin test ./tests/try_mbox/ -vet -strict-style -disallow-do -o:none -debug
142+
else
143+
odin test ./tests/try_mbox/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
144+
fi
145+
146+
- name: Test tests/nbio_mbox
147147
shell: bash
148148
run: |
149149
if [ "${{ matrix.opt }}" = "none" ]; then
150-
odin build ./pool_tests/ -build-mode:lib -vet -strict-style -o:none -debug
150+
odin test ./tests/nbio_mbox/ -vet -strict-style -disallow-do -o:none -debug
151151
else
152-
odin build ./pool_tests/ -build-mode:lib -vet -strict-style -o:${{ matrix.opt }}
152+
odin test ./tests/nbio_mbox/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
153153
fi
154154
155-
- name: Test pool_tests
155+
- name: Test tests/pool
156156
shell: bash
157157
run: |
158158
if [ "${{ matrix.opt }}" = "none" ]; then
159-
odin test ./pool_tests/ -vet -strict-style -disallow-do -o:none -debug
159+
odin test ./tests/pool/ -vet -strict-style -disallow-do -o:none -debug
160160
else
161-
odin test ./pool_tests/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
161+
odin test ./tests/pool/ -vet -strict-style -disallow-do -o:${{ matrix.opt }}
162162
fi
163163
164164
- name: Doc smoke test
@@ -171,7 +171,6 @@ jobs:
171171
odin doc ./try_mbox/
172172
odin doc ./nbio_mbox/
173173
odin doc ./pool/
174-
odin doc ./pool_tests/
175174
odin doc ./examples/
176175
odin doc ./tests/
177176
@@ -187,7 +186,6 @@ jobs:
187186
odin doc ./try_mbox/ > doc-out/try_mbox.txt
188187
odin doc ./nbio_mbox/ > doc-out/nbio_mbox.txt
189188
odin doc ./pool/ > doc-out/pool.txt
190-
odin doc ./pool_tests/ > doc-out/pool_tests.txt
191189
odin doc ./examples/ > doc-out/examples.txt
192190
odin doc ./tests/ > doc-out/tests.txt
193191

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ defer {
176176
177177
for {
178178
nbio.tick() // process I/O and wake-up tasks
179-
for msg, ok := try_mbox.try_receive(m); ok; msg, ok = try_mbox.try_receive(m) {
179+
batch := try_mbox.try_receive_batch(m)
180+
for node := list.pop_front(&batch); node != nil; node = list.pop_front(&batch) {
181+
msg := (^My_Msg)(node)
180182
// handle message, then free or return to pool
181183
}
182184
}

build_and_test.sh

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,13 @@ for opt in "${OPTS[@]}"; do
6868
odin build ./try_mbox/ -build-mode:lib -vet -strict-style -o:"${opt}"
6969
fi
7070

71-
echo " test try_mbox/..."
72-
if [ "${opt}" = "none" ]; then
73-
odin test ./try_mbox/ -vet -strict-style -disallow-do -o:none -debug
74-
else
75-
odin test ./try_mbox/ -vet -strict-style -disallow-do -o:"${opt}"
76-
fi
77-
7871
echo " build nbio_mbox lib..."
7972
if [ "${opt}" = "none" ]; then
8073
odin build ./nbio_mbox/ -build-mode:lib -vet -strict-style -o:none -debug
8174
else
8275
odin build ./nbio_mbox/ -build-mode:lib -vet -strict-style -o:"${opt}"
8376
fi
8477

85-
echo " test nbio_mbox/..."
86-
if [ "${opt}" = "none" ]; then
87-
odin test ./nbio_mbox/ -vet -strict-style -disallow-do -o:none -debug
88-
else
89-
odin test ./nbio_mbox/ -vet -strict-style -disallow-do -o:"${opt}"
90-
fi
91-
9278
echo " build pool lib..."
9379
if [ "${opt}" = "none" ]; then
9480
odin build ./pool/ -build-mode:lib -vet -strict-style -o:none -debug
@@ -110,18 +96,32 @@ for opt in "${OPTS[@]}"; do
11096
odin test ./tests/ -vet -strict-style -disallow-do -o:"${opt}"
11197
fi
11298

113-
echo " build pool_tests/..."
99+
echo " test tests/mbox/..."
100+
if [ "${opt}" = "none" ]; then
101+
odin test ./tests/mbox/ -vet -strict-style -disallow-do -o:none -debug
102+
else
103+
odin test ./tests/mbox/ -vet -strict-style -disallow-do -o:"${opt}"
104+
fi
105+
106+
echo " test tests/try_mbox/..."
107+
if [ "${opt}" = "none" ]; then
108+
odin test ./tests/try_mbox/ -vet -strict-style -disallow-do -o:none -debug
109+
else
110+
odin test ./tests/try_mbox/ -vet -strict-style -disallow-do -o:"${opt}"
111+
fi
112+
113+
echo " test tests/nbio_mbox/..."
114114
if [ "${opt}" = "none" ]; then
115-
odin build ./pool_tests/ -build-mode:lib -vet -strict-style -o:none -debug
115+
odin test ./tests/nbio_mbox/ -vet -strict-style -disallow-do -o:none -debug
116116
else
117-
odin build ./pool_tests/ -build-mode:lib -vet -strict-style -o:"${opt}"
117+
odin test ./tests/nbio_mbox/ -vet -strict-style -disallow-do -o:"${opt}"
118118
fi
119119

120-
echo " test pool_tests/..."
120+
echo " test tests/pool/..."
121121
if [ "${opt}" = "none" ]; then
122-
odin test ./pool_tests/ -vet -strict-style -disallow-do -o:none -debug
122+
odin test ./tests/pool/ -vet -strict-style -disallow-do -o:none -debug
123123
else
124-
odin test ./pool_tests/ -vet -strict-style -disallow-do -o:"${opt}"
124+
odin test ./tests/pool/ -vet -strict-style -disallow-do -o:"${opt}"
125125
fi
126126

127127
echo "${GREEN} pass: ${opt}${NC}"
@@ -136,7 +136,6 @@ odin doc ./wakeup/
136136
odin doc ./try_mbox/
137137
odin doc ./nbio_mbox/
138138
odin doc ./pool/
139-
odin doc ./pool_tests/
140139
odin doc ./examples/
141140
odin doc ./tests/
142141
echo "${GREEN} docs OK${NC}"

examples/msg.odin

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package examples
2+
3+
import list "core:container/intrusive/list"
4+
import "core:mem"
5+
6+
// Msg is the shared message type for all examples.
7+
// "node" is required by mbox (and pool). The name is fixed. The type is list.Node.
8+
// "allocator" is required by pool — set by pool.get on every retrieval.
9+
Msg :: struct {
10+
node: list.Node,
11+
allocator: mem.Allocator,
12+
data: int,
13+
}

examples/negotiation.odin

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ import mbox "../mbox"
44
import nbio_mbox "../nbio_mbox"
55
import try_mbox "../try_mbox"
66
import list "core:container/intrusive/list"
7-
import "core:mem"
87
import "core:nbio"
98
import "core:thread"
109

11-
// Msg is the shared message type for all examples.
12-
// "node" is required by mbox (and pool). The name is fixed. The type is list.Node.
13-
// "allocator" is required by pool — set by pool.get on every retrieval.
14-
Msg :: struct {
15-
node: list.Node,
16-
allocator: mem.Allocator,
17-
data: int,
18-
}
19-
2010
// _Worker holds pointers to both mailboxes and the result.
2111
@(private)
2212
_Worker :: struct {
@@ -79,10 +69,12 @@ negotiation_example :: proc(kind: nbio_mbox.Nbio_Wakeuper_Kind = .UDP) -> bool {
7969
if tick_err != nil {
8070
break
8171
}
82-
msg, ok := try_mbox.try_receive(loop_mb)
83-
if ok {
72+
nb := try_mbox.try_receive_batch(loop_mb)
73+
node := list.pop_front(&nb)
74+
if node != nil {
8475
// Reuse the received message as the reply.
8576
// No extra allocation needed. Ownership stays with the worker.
77+
msg := (^Msg)(node)
8678
msg.data = msg.data + 1
8779
mbox.send(&reply_mb, msg)
8880
break

mbox/doc.odin

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Typical usage:
2626
// receiver thread:
2727
got, err := mbox.wait_receive(&mb)
2828
29-
Use Loop_Mailbox (package nbio_mbox) for non-blocking nbio event-loop integration.
3029
*/
3130
package mbox
31+
32+
/*
33+
Note: Some test procedures may appear in the generated documentation.
34+
This is because they are part of the same package to allow for white-box testing.
35+
*/

mpsc/doc.odin

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ The stub sentinel node holds its own address in head and tail.
2525
Copying the struct after init invalidates those pointers.
2626
*/
2727
package mpsc
28+
29+
/*
30+
Note: Some test procedures may appear in the generated documentation.
31+
This is because they are part of the same package to allow for white-box testing.
32+
*/

mpsc/edge_test.odin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//+test
12
package mpsc
23

34
import "core:testing"

mpsc/queue_test.odin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//+test
12
package mpsc
23

34
import "core:testing"

nbio_mbox/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ try_mbox.send(m, msg)
4545
// event-loop thread — drain in the tick loop:
4646
for {
4747
nbio.tick(timeout)
48-
for {
49-
msg, ok := try_mbox.try_receive(m)
50-
if !ok { break }
51-
// handle msg
48+
batch := try_mbox.try_receive_batch(m)
49+
for node := list.pop_front(&batch); node != nil; node = list.pop_front(&batch) {
50+
msg := (^Msg)(node)
51+
// handle msg — free or return to pool
5252
}
5353
}
5454
```
@@ -59,7 +59,7 @@ for {
5959
|-----------|--------|
6060
| `init_nbio_mbox` | any thread |
6161
| `try_mbox.send` | any thread |
62-
| `try_mbox.try_receive` | event-loop thread only |
62+
| `try_mbox.try_receive_batch` | event-loop thread only |
6363
| `try_mbox.close` | event-loop thread only |
6464
| `try_mbox.destroy` | event-loop thread (after close) |
6565

0 commit comments

Comments
 (0)