8000 tests/renesas-ra: Add tests for renesas-ra port. · sstobbe/micropython@4753913 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4753913

Browse files
tests/renesas-ra: Add tests for renesas-ra port.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
1 parent 3a941cc commit 4753913

File tree

14 files changed

+377
-0
lines changed

14 files changed

+377
-0
lines changed

tests/renesas-ra/freq.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# definitions
3+
#
4+
MACHINE_RA4M1_CLICKER = "RA4M1_CLICKER with RA4M1"
5+
MACHINE_RA4M1_EK = "RA4M1_EK with RA4M1"
6+
MACHINE_RA4W1_EK = "RA4W1_EK with RA4W1"
7+
MACHINE_RA6M1_EK = "RA6M1_EK with RA6M1"
8+
MACHINE_RA6M2_EK = "RA6M2_EK with RA6M2"
9+
SYSCLK_RA4M1_CLICKER = 48000000
10+
SYSCLK_RA4M1_EK = 48000000
11+
SYSCLK_RA4W1_EK = 48000000
12+
SYSCLK_RA6M1_EK = 120000000
13+
SYSCLK_RA6M2_EK = 120000000
14+
15+
#
16+
# machine
17+
#
18+
19+
import os
20+
21+
try:
22+
import machine
23+
except:
24+
print("machine module is not found")
25+
raise SystemExit
26+
27+
m = os.uname().machine
28+
f = machine.freq()
29+
30+
if m == MACHINE_RA4M1_CLICKER:
31+
if f == SYSCLK_RA4M1_CLICKER:
32+
print("freq: OK")
33+
else:
34+
print("freq: NG")
35+
36+
37+
if m == MACHINE_RA4M1_EK:
38+
if f == SYSCLK_RA4M1_EK:
39+
print("freq: OK")
40+
else:
41+
print("freq: NG")
42+
43+
if m == MACHINE_RA4W1_EK:
44+
if f == SYSCLK_RA4W1_EK:
45+
print("freq: OK")
46+
else:
47+
print("freq: NG")
48+
49+
if m == MACHINE_RA6M1_EK:
50+
if f == SYSCLK_RA6M1_EK:
51+
print("freq: OK")
52+
else:
53+
print("freq: NG")
54+
55+
if m == MACHINE_RA6M2_EK:
56+
if f == SYSCLK_RA6M2_EK:
57+
print("freq: OK")
58+
else:
59+
print("freq: NG")

tests/renesas-ra/freq.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
freq: OK

tests/renesas-ra/i2c.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import time
3+
4+
n = os.uname().machine
5+
if "RA6M2_EK" in n:
6+
i2c_id = 2
7+
elif "RA6M1_EK" in n:
8+
i2c_id = 0
9+
elif ("RA4M1_CLICKER" in n) or ("RA4M1_EK" in n) or ("RA4W1_EK" in n):
10+
print("SKIP")
11+
raise SystemExit
12+
else:
13+
i2c_id = 0
14+
15+
from machine import I2C
16+
17+
i2c = I2C(i2c_id)

tests/renesas-ra/i2c.py.exp

Whitespace-only changes.

tests/renesas-ra/modtime.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import time
2+
3+
DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
4+
5+
6+
def is_leap(year):
7+
return (year % 4) == 0
8+
9+
10+
def test():
11+
seconds = 0
12+
wday = 5 # Jan 1, 2000 was a Saturday
13+
for year in range(2000, 2034):
14+
print("Testing %d" % year)
15+
yday = 1
16+
for month in range(1, 13):
17+
if month == 2 and is_leap(year):
18+
DAYS_PER_MONTH[2] = 29
19+
else:
20+
DAYS_PER_MONTH[2] = 28
21+
for day in range(1, DAYS_PER_MONTH[month] + 1):
22+
secs = time.mktime((year, month, day, 0, 0, 0, 0, 0))
23+
if secs != seconds:
24+
print(
25+
"mktime failed for %d-%02d-%02d got %d expected %d"
26+
% (year, month, day, secs, seconds)
27+
)
28+
tuple = time.localtime(seconds)
29+
secs = time.mktime(tuple)
30+
if secs != seconds:
31+
print(
32+
"localtime failed for %d-%02d-%02d got %d expected %d"
33+
% (year, month, day, secs, seconds)
34+
)
35+
return
36+
seconds += 86400
37+
if yday != tuple[7]:
38+
print(
39+
"locatime for %d-%02d-%02d got yday %d, expecting %d"
40+
% (year, month, day, tuple[7], yday)
41+
)
42+
return
43+
if wday != tuple[6]:
44+
print(
45+
"locatime for %d-%02d-%02d got wday %d, expecting %d"
46+
% (year, month, day, tuple[6], wday)
47+
)
48+
return
49+
yday += 1
50+
wday = (wday + 1) % 7
51+
52+
53+
def spot_test(seconds, expected_time):
54+
actual_time = time.localtime(seconds)
55+
for i in range(len(actual_time)):
56+
if actual_time[i] != expected_time[i]:
57+
print(
58+
"time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time
59+
)
60+
return
61+
print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
62+
63+
64+
test()
65+
# fmt: off
66+
spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
67+
spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
68+
spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1))
69+
spot_test( 60, (2000, 1, 1, 0, 1, 0, 5, 1))
70+
spot_test( 3599, (2000, 1, 1, 0, 59, 59, 5, 1))
71+
spot_test( 3600, (2000, 1, 1, 1, 0, 0, 5, 1))
72+
spot_test( -1, (1999, 12, 31, 23, 59, 59, 4, 365))
73+
spot_test( 447549467, (2014, 3, 7, 23, 17, 47, 4, 66))
74+
spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66))
75+
spot_test(-10729151 10000 99, (1966, 1, 1, 0, 0, 1, 5, 1))
76+
spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1))
77+
spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365))
78+
# fmt: on

tests/renesas-ra/modtime.py.exp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Testing 2000
2+
Testing 2001
3+
Testing 2002
4+
Testing 2003
5+
Testing 2004
6+
Testing 2005
7+
Testing 2006
8+
Testing 2007
9+
Testing 2008
10+
Testing 2009
11+
Testing 2010
12+
Testing 2011
13+
Testing 2012
14+
Testing 2013
15+
Testing 2014
16+
Testing 2015
17+
Testing 2016
18+
Testing 2017
19+
Testing 2018
20+
Testing 2019
21+
Testing 2020
22+
Testing 2021
23+
Testing 2022
24+
Testing 2023
25+
Testing 2024
26+
Testing 2025
27+
Testing 2026
28+
Testing 2027
29+
Testing 2028
30+
Testing 2029
31+
Testing 2030
32+
Testing 2031
33+
Testing 2032
34+
Testing 2033
35+
time.localtime( 0 ) returned (2000, 1, 1, 0, 0, 0, 5, 1) (pass)
36+
time.localtime( 1 ) returned (2000, 1, 1, 0, 0, 1, 5, 1) (pass)
37+
time.localtime( 59 ) returned (2000, 1, 1, 0, 0, 59, 5, 1) (pass)
38+
time.localtime( 60 ) returned (2000, 1, 1, 0, 1, 0, 5, 1) (pass)
39+
time.localtim 10000 e( 3599 ) returned (2000, 1, 1, 0, 59, 59, 5, 1) (pass)
40+
time.localtime( 3600 ) returned (2000, 1, 1, 1, 0, 0, 5, 1) (pass)
41+
time.localtime( -1 ) returned (1999, 12, 31, 23, 59, 59, 4, 365) (pass)
42+
time.localtime( 447549467 ) returned (2014, 3, 7, 23, 17, 47, 4, 66) (pass)
43+
time.localtime( -940984933 ) returned (1970, 3, 7, 23, 17, 47, 5, 66) (pass)
44+
time.localtime( -1072915199 ) returned (1966, 1, 1, 0, 0, 1, 5, 1) (pass)
45+
time.localtime( -1072915200 ) returned (1966, 1, 1, 0, 0, 0, 5, 1) (pass)
46+
time.localtime( -1072915201 ) returned (1965, 12, 31, 23, 59, 59, 4, 365) (pass)

tests/renesas-ra/pin.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from machine import Pin
2+
import os
3+
4+
n = os.uname().machine
5+
if "RA4W1_EK" in n:
6+
try_pin = "P004"
7+
try_s = "Pin(Pin.cpu.P004, mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.LOW_POWER)"
8+
else:
9+
try_pin = "P000"
10+
try_s = "Pin(Pin.cpu.P000, mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.LOW_POWER)"
11+
12+
p = Pin(try_pin, Pin.IN)
13+
if str(p) == try_s:
14+
print("OK")
15+
else:
16+
print("NG")
17+
print("exp: " + try_s)
18+
print("out: " + str(p))
19+
20+
p = Pin("SW1", Pin.IN, Pin.PULL_UP)
21+
if p.mode() != 1:
22+
print("mode: NG")
23+
p = Pin("SW1", Pin.IN, pull=Pin.PULL_UP)
24+
if p.pull() != 14:
25+
print("pull: NG")
26+
p = Pin("SW1", mode=Pin.IN, pull=Pin.PULL_UP)
27+
28+
p.init(p.IN, p.PULL_UP)
29+
p.init(p.IN, pull=p.PULL_UP)
30+
p.init(mode=p.IN, pull=p.PULL_UP)
31+
print(p.value())
32+
33+
p.init(p.OUT)
34+
p.init(p.OPEN_DRAIN)
35+
p.low()
36+
print(p.value())
37+
p.high()
38+
print(p.value())
39+
p.value(0)
40+
print(p.value())
41+
p.value(1)
42+
print(p.value())
43+
p.value(False)
44+
print(p.value())
45+
p.value(True)
46+
print(p.value())
47+
p.off()
48+
print(p.value())
49+
p.on()
50+
print(p.value())
51+
p.off()

tests/renesas-ra/pin.py.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
OK
2+
1
3+
0
4+
1
5+
0
6+
1
7+
0
8+
1
9+
0
10+
1

tests/renesas-ra/rtc_init.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import machine
2+
from machine import RTC
3+
import time
4+
5+
rtc = RTC()
6+
rtc.init()
7+
print(rtc)
8+
9+
# make sure that 1 second passes correctly
10+
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
11+
time.sleep_ms(1002)
12+
print(rtc.datetime()[:7])

tests/renesas-ra/rtc_init.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<RTC>
2+
(2014, 1, 1, 1, 0, 0, 1)

0 commit comments

Comments
 (0)
0