Skip to content

Commit 99eccfc

Browse files
committed
tests/micropython: Remove dependence on big ints for boundary tests.
This commit provides an implementation for viper boundary tests that can work even without big int support. Since it uses a fixed-size buffer to hold values to work with, this should work on any platform as long as its integers are 32 bits wide, regardless its configuration on how big integers can be. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 096ff8b commit 99eccfc

6 files changed

+67
-60
lines changed

tests/micropython/viper_ptr16_store_boundary_intbig.py renamed to tests/micropython/viper_ptr16_store_boundary.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ def set{off}(dest: ptr16):
1313
MASK = (1 << (8 * SIZE)) - 1
1414

1515

16+
next_int = 1
17+
test_buffer = bytearray(SIZE)
18+
19+
20+
def next_value() -> uint:
21+
global next_int
22+
global test_buffer
23+
for index in range(1, SIZE):
24+
test_buffer[index - 1] = test_buffer[index]
25+
test_buffer[SIZE - 1] = next_int
26+
next_int += 1
27+
output = 0
28+
for byte in test_buffer:
29+
output = (output << 8) | byte
30+
return output & MASK
31+
32+
1633
@micropython.viper
1734
def set_index(dest: ptr16, i: int, val: uint):
1835
dest[i] = val
@@ -23,31 +40,17 @@ def get_index(src, i):
2340

2441

2542
buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024)
26-
next = 1
27-
val = 0
2843
for bit in BIT_THRESHOLDS:
2944
print("---", bit)
3045
pre, idx, post = (
3146
(((1 << bit) - (2 * SIZE)) // SIZE),
3247
(((1 << bit) - (1 * SIZE)) // SIZE),
3348
((1 << bit) // SIZE),
3449
)
35-
val = (val << 8) + next
36-
next += 1
37-
set_index(buffer, pre, val & MASK)
38-
val = (val << 8) + next
39-
next += 1
40-
set_index(buffer, idx, val & MASK)
41-
val = (val << 8) + next
42-
next += 1
43-
set_index(buffer, post, val & MASK)
44-
val = (val << 8) + next
45-
next += 1
50+
set_index(buffer, pre, next_value())
51+
set_index(buffer, idx, next_value())
52+
set_index(buffer, post, next_value())
4653
print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post)))
47-
exec(SET_TEMPLATE.format(off=pre, val=val & MASK))
48-
val = (val << 8) + next
49-
next += 1
50-
exec(SET_TEMPLATE.format(off=idx, val=val & MASK))
51-
val = (val << 8) + next
52-
next += 1
53-
exec(SET_TEMPLATE.format(off=post, val=val & MASK))
54+
exec(SET_TEMPLATE.format(off=pre, val=next_value()))
55+
exec(SET_TEMPLATE.format(off=idx, val=next_value()))
56+
exec(SET_TEMPLATE.format(off=post, val=next_value()))

tests/micropython/viper_ptr32_store_boundary_intbig.py renamed to tests/micropython/viper_ptr32_store_boundary.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ def set{off}(dest: ptr32):
1212
SIZE = 4
1313
MASK = (1 << (8 * SIZE)) - 1
1414

15+
next_int = 1
16+
test_buffer = bytearray(SIZE)
17+
18+
19+
def next_value() -> uint:
20+
global next_int
21+
global test_buffer
22+
for index in range(1, SIZE):
23+
test_buffer[index - 1] = test_buffer[index]
24+
test_buffer[SIZE - 1] = next_int
25+
next_int += 1
26+
output = 0
27+
for byte in test_buffer:
28+
output = (output << 8) | byte
29+
return output & MASK
30+
1531

1632
@micropython.viper
1733
def set_index(dest: ptr32, i: int, val: uint):
@@ -28,31 +44,17 @@ def get_index(src, i):
2844

2945

3046
buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024)
31-
next = 1
32-
val = 0
3347
for bit in BIT_THRESHOLDS:
3448
print("---", bit)
3549
pre, idx, post = (
3650
(((1 << bit) - (2 * SIZE)) // SIZE),
3751
(((1 << bit) - (1 * SIZE)) // SIZE),
3852
((1 << bit) // SIZE),
3953
)
40-
val = (val << 8) + next
41-
next += 1
42-
set_index(buffer, pre, val & MASK)
43-
val = (val << 8) + next
44-
next += 1
45-
set_index(buffer, idx, val & MASK)
46-
val = (val << 8) + next
47-
next += 1
48-
set_index(buffer, post, val & MASK)
49-
val = (val << 8) + next
50-
next += 1
54+
set_index(buffer, pre, next_value())
55+
set_index(buffer, idx, next_value())
56+
set_index(buffer, post, next_value())
5157
print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post)))
52-
exec(SET_TEMPLATE.format(off=pre, val=val & MASK))
53-
val = (val << 8) + next
54-
next += 1
55-
exec(SET_TEMPLATE.format(off=idx, val=val & MASK))
56-
val = (val << 8) + next
57-
next += 1
58-
exec(SET_TEMPLATE.format(off=post, val=val & MASK))
58+
exec(SET_TEMPLATE.format(off=pre, val=next_value()))
59+
exec(SET_TEMPLATE.format(off=idx, val=next_value()))
60+
exec(SET_TEMPLATE.format(off=post, val=next_value()))

tests/micropython/viper_ptr8_store_boundary_intbig.py renamed to tests/micropython/viper_ptr8_store_boundary.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ def set{off}(dest: ptr8):
1212
SIZE = 1
1313
MASK = (1 << (8 * SIZE)) - 1
1414

15+
next_int = 1
16+
test_buffer = bytearray(SIZE)
17+
18+
19+
def next_value() -> uint:
20+
global next_int
21+
global test_buffer
22+
for index in range(1, SIZE):
23+
test_buffer[index - 1] = test_buffer[index]
24+
test_buffer[SIZE - 1] = next_int
25+
next_int += 1
26+
output = 0
27+
for byte in test_buffer:
28+
output = (output << 8) | byte
29+
return output & MASK
30+
1531

1632
@micropython.viper
1733
def set_index(dest: ptr8, i: int, val: uint):
@@ -23,27 +39,13 @@ def get_index(src: ptr8, i: int):
2339

2440

2541
buffer = bytearray(((1 << max(BIT_THRESHOLDS) + 1) // 1024) * 1024)
26-
next = 1
27-
val = 0
2842
for bit in BIT_THRESHOLDS:
2943
print("---", bit)
3044
pre, idx, post = (((1 << bit) - (2 * SIZE)), ((1 << bit) - (1 * SIZE)), (1 << bit))
31-
val = (val << 8) + next
32-
next += 1
33-
set_index(buffer, pre, val & MASK)
34-
val = (val << 8) + next
35-
next += 1
36-
set_index(buffer, idx, val & MASK)
37-
val = (val << 8) + next
38-
next += 1
39-
set_index(buffer, post, val & MASK)
40-
val = (val << 8) + next
41-
next += 1
45+
set_index(buffer, pre, next_value())
46+
set_index(buffer, idx, next_value())
47+
set_index(buffer, post, next_value())
4248
print(hex(get_index(buffer, pre)), hex(get_index(buffer, idx)), hex(get_index(buffer, post)))
43-
exec(SET_TEMPLATE.format(off=pre, val=val & MASK))
44-
val = (val << 8) + next
45-
next += 1
46-
exec(SET_TEMPLATE.format(off=idx, val=val & MASK))
47-
val = (val << 8) + next
48-
next += 1
49-
exec(SET_TEMPLATE.format(off=post, val=val & MASK))
49+
exec(SET_TEMPLATE.format(off=pre, val=next_value()))
50+
exec(SET_TEMPLATE.format(off=idx, val=next_value()))
51+
exec(SET_TEMPLATE.format(off=post, val=next_value()))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy