Skip to content

Commit 41c9142

Browse files
committed
tests/extmod/framebuf: Fix buffer size issues.
Tests framebuf1 and framebuf2 do not take the need for byte-aligned strides into consideration when calculating buffer lengths. Accordingly, the buffers allocated are slightly too small. Fixed buffer length calculations. Signed-off-by: Duncan Lowther <[email protected]>
1 parent bc2ed8c commit 41c9142

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

tests/extmod/framebuf1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
w = 5
88
h = 16
9-
size = w * h // 8
9+
size = ((w + 7) & ~7) * ((h + 7) & ~7) // 8
1010
buf = bytearray(size)
1111
maps = {
1212
framebuf.MONO_VLSB: "MONO_VLSB",

tests/extmod/framebuf1.py.exp

+54-54
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
MONO_VLSB
22
0
3-
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
4-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
5-
bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80')
6-
bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x00')
3+
bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00')
4+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
5+
bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00')
6+
bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
77
1 0
8-
hline bytearray(b'\x02\x02\x02\x02\x02\x00\x00\x00\x00\x00')
9-
vline bytearray(b'\x00\xff\x00\x00\x00\x00\xff\x00\x00\x00')
10-
rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00')
11-
fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00')
12-
line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00')
13-
line bytearray(b'\x00\x00\x06\x08\x00\x00\x00\x00\x00\x00')
14-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00')
15-
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
16-
bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00')
17-
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
18-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
19-
bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00')
20-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
21-
bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00')
8+
hline bytearray(b'\x02\x02\x02\x02\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
9+
vline bytearray(b'\x00\xff\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00')
10+
rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
11+
fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
12+
line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
13+
line bytearray(b'\x00\x00\x06\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
14+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00')
15+
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
16+
bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
17+
bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
18+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00')
19+
bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
20+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
21+
bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
2222

2323
MONO_HLSB
2424
0
25-
bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8')
26-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
27-
bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00')
28-
bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00')
25+
bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8')
26+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
27+
bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x88')
28+
bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80')
2929
1 0
30-
hline bytearray(b'\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00')
31-
vline bytearray(b'@@@@@@@@@@')
32-
rect bytearray(b'\x00pPp\x00\x00\x00\x00\x00\x00')
33-
fill_rect bytearray(b'\x00ppp\x00\x00\x00\x00\x00\x00')
34-
line bytearray(b'\x00@ \x10\x00\x00\x00\x00\x00\x00')
35-
line bytearray(b'\x00 \x10\x00\x00\x00\x00\x00\x00')
36-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00 \x00')
37-
bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00')
38-
bytearray(b'\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00')
39-
bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00')
40-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00')
41-
bytearray(b'``x````\x00\x00\x00')
42-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
43-
bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00')
30+
hline bytearray(b'\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
31+
vline bytearray(b'@@@@@@@@@@@@@@@@')
32+
rect bytearray(b'\x00pPp\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
33+
fill_rect bytearray(b'\x00ppp\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
34+
line bytearray(b'\x00@ \x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
35+
line bytearray(b'\x00 \x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
36+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00')
37+
bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00')
38+
bytearray(b'\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00')
39+
bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00')
40+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00')
41+
bytearray(b'``x````\x00\x00\x00\x00\x00\x00\x00\x00\x00')
42+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
43+
bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00\x00\x00\x00\x00\x00\x00')
4444

4545
MONO_HMSB
4646
0
47-
bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f')
48-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
49-
bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00')
50-
bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00')
47+
bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f')
48+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
49+
bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11')
50+
bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
5151
1 0
52-
hline bytearray(b'\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00')
53-
vline bytearray(b'\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02')
54-
rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00')
55-
fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00')
56-
line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00')
57-
line bytearray(b'\x00\x04\x04\x08\x00\x00\x00\x00\x00\x00')
58-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00')
59-
bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00')
60-
bytearray(b'\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00')
61-
bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00')
62-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00')
63-
bytearray(b'\x06\x06\x1e\x06\x06\x06\x06\x00\x00\x00')
64-
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
65-
bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00')
52+
hline bytearray(b'\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
53+
vline bytearray(b'\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02')
54+
rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
55+
fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
56+
line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
57+
line bytearray(b'\x00\x04\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
58+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00')
59+
bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00')
60+
bytearray(b'\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00')
61+
bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00')
62+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00')
63+
bytearray(b'\x06\x06\x1e\x06\x06\x06\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00')
64+
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
65+
bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00\x00\x00\x00\x00\x00\x00')
6666

6767
ValueError
6868
True

tests/extmod/framebuf2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def printbuf():
4848

4949
w2 = 2
5050
h2 = 3
51-
buf2 = bytearray(w2 * h2 // 4)
51+
buf2 = bytearray(h2 * ((w2 + 3) // 4))
5252
fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.GS2_HMSB)
5353

5454
# blit

0 commit comments

Comments
 (0)