summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeo Takahashi <takeo.takahashi.xv@renesas.com>2022-04-28 22:21:17 +0900
committerTakeo Takahashi <takeo.takahashi.xv@renesas.com>2022-04-29 12:29:07 +0900
commit4753913253072d7d47f7d09540e7c5c210ebb673 (patch)
treefc17e4123d85a151cf99aca7ce2f5535fafd7782
parent3a941cce512529596968d34142e7ec0516b2a460 (diff)
tests/renesas-ra: Add tests for renesas-ra port.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
-rw-r--r--tests/renesas-ra/freq.py59
-rw-r--r--tests/renesas-ra/freq.py.exp1
-rw-r--r--tests/renesas-ra/i2c.py17
-rw-r--r--tests/renesas-ra/i2c.py.exp0
-rw-r--r--tests/renesas-ra/modtime.py78
-rw-r--r--tests/renesas-ra/modtime.py.exp46
-rw-r--r--tests/renesas-ra/pin.py51
-rw-r--r--tests/renesas-ra/pin.py.exp10
-rw-r--r--tests/renesas-ra/rtc_init.py12
-rw-r--r--tests/renesas-ra/rtc_init.py.exp2
-rw-r--r--tests/renesas-ra/spi.py40
-rw-r--r--tests/renesas-ra/spi.py.exp9
-rw-r--r--tests/renesas-ra/uart1.py51
-rw-r--r--tests/renesas-ra/uart1.py.exp1
14 files changed, 377 insertions, 0 deletions
diff --git a/tests/renesas-ra/freq.py b/tests/renesas-ra/freq.py
new file mode 100644
index 000000000..6fbf6ce09
--- /dev/null
+++ b/tests/renesas-ra/freq.py
@@ -0,0 +1,59 @@
+#
+# definitions
+#
+MACHINE_RA4M1_CLICKER = "RA4M1_CLICKER with RA4M1"
+MACHINE_RA4M1_EK = "RA4M1_EK with RA4M1"
+MACHINE_RA4W1_EK = "RA4W1_EK with RA4W1"
+MACHINE_RA6M1_EK = "RA6M1_EK with RA6M1"
+MACHINE_RA6M2_EK = "RA6M2_EK with RA6M2"
+SYSCLK_RA4M1_CLICKER = 48000000
+SYSCLK_RA4M1_EK = 48000000
+SYSCLK_RA4W1_EK = 48000000
+SYSCLK_RA6M1_EK = 120000000
+SYSCLK_RA6M2_EK = 120000000
+
+#
+# machine
+#
+
+import os
+
+try:
+ import machine
+except:
+ print("machine module is not found")
+ raise SystemExit
+
+m = os.uname().machine
+f = machine.freq()
+
+if m == MACHINE_RA4M1_CLICKER:
+ if f == SYSCLK_RA4M1_CLICKER:
+ print("freq: OK")
+ else:
+ print("freq: NG")
+
+
+if m == MACHINE_RA4M1_EK:
+ if f == SYSCLK_RA4M1_EK:
+ print("freq: OK")
+ else:
+ print("freq: NG")
+
+if m == MACHINE_RA4W1_EK:
+ if f == SYSCLK_RA4W1_EK:
+ print("freq: OK")
+ else:
+ print("freq: NG")
+
+if m == MACHINE_RA6M1_EK:
+ if f == SYSCLK_RA6M1_EK:
+ print("freq: OK")
+ else:
+ print("freq: NG")
+
+if m == MACHINE_RA6M2_EK:
+ if f == SYSCLK_RA6M2_EK:
+ print("freq: OK")
+ else:
+ print("freq: NG")
diff --git a/tests/renesas-ra/freq.py.exp b/tests/renesas-ra/freq.py.exp
new file mode 100644
index 000000000..7f4b843ee
--- /dev/null
+++ b/tests/renesas-ra/freq.py.exp
@@ -0,0 +1 @@
+freq: OK
diff --git a/tests/renesas-ra/i2c.py b/tests/renesas-ra/i2c.py
new file mode 100644
index 000000000..bb22509e4
--- /dev/null
+++ b/tests/renesas-ra/i2c.py
@@ -0,0 +1,17 @@
+import os
+import time
+
+n = os.uname().machine
+if "RA6M2_EK" in n:
+ i2c_id = 2
+elif "RA6M1_EK" in n:
+ i2c_id = 0
+elif ("RA4M1_CLICKER" in n) or ("RA4M1_EK" in n) or ("RA4W1_EK" in n):
+ print("SKIP")
+ raise SystemExit
+else:
+ i2c_id = 0
+
+from machine import I2C
+
+i2c = I2C(i2c_id)
diff --git a/tests/renesas-ra/i2c.py.exp b/tests/renesas-ra/i2c.py.exp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/renesas-ra/i2c.py.exp
diff --git a/tests/renesas-ra/modtime.py b/tests/renesas-ra/modtime.py
new file mode 100644
index 000000000..396f83266
--- /dev/null
+++ b/tests/renesas-ra/modtime.py
@@ -0,0 +1,78 @@
+import time
+
+DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+
+
+def is_leap(year):
+ return (year % 4) == 0
+
+
+def test():
+ seconds = 0
+ wday = 5 # Jan 1, 2000 was a Saturday
+ for year in range(2000, 2034):
+ print("Testing %d" % year)
+ yday = 1
+ for month in range(1, 13):
+ if month == 2 and is_leap(year):
+ DAYS_PER_MONTH[2] = 29
+ else:
+ DAYS_PER_MONTH[2] = 28
+ for day in range(1, DAYS_PER_MONTH[month] + 1):
+ secs = time.mktime((year, month, day, 0, 0, 0, 0, 0))
+ if secs != seconds:
+ print(
+ "mktime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
+ tuple = time.localtime(seconds)
+ secs = time.mktime(tuple)
+ if secs != seconds:
+ print(
+ "localtime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
+ return
+ seconds += 86400
+ if yday != tuple[7]:
+ print(
+ "locatime for %d-%02d-%02d got yday %d, expecting %d"
+ % (year, month, day, tuple[7], yday)
+ )
+ return
+ if wday != tuple[6]:
+ print(
+ "locatime for %d-%02d-%02d got wday %d, expecting %d"
+ % (year, month, day, tuple[6], wday)
+ )
+ return
+ yday += 1
+ wday = (wday + 1) % 7
+
+
+def spot_test(seconds, expected_time):
+ actual_time = time.localtime(seconds)
+ for i in range(len(actual_time)):
+ if actual_time[i] != expected_time[i]:
+ print(
+ "time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time
+ )
+ return
+ print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
+
+
+test()
+# fmt: off
+spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
+spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
+spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1))
+spot_test( 60, (2000, 1, 1, 0, 1, 0, 5, 1))
+spot_test( 3599, (2000, 1, 1, 0, 59, 59, 5, 1))
+spot_test( 3600, (2000, 1, 1, 1, 0, 0, 5, 1))
+spot_test( -1, (1999, 12, 31, 23, 59, 59, 4, 365))
+spot_test( 447549467, (2014, 3, 7, 23, 17, 47, 4, 66))
+spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66))
+spot_test(-1072915199, (1966, 1, 1, 0, 0, 1, 5, 1))
+spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1))
+spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365))
+# fmt: on
diff --git a/tests/renesas-ra/modtime.py.exp b/tests/renesas-ra/modtime.py.exp
new file mode 100644
index 000000000..3e1f6e920
--- /dev/null
+++ b/tests/renesas-ra/modtime.py.exp
@@ -0,0 +1,46 @@
+Testing 2000
+Testing 2001
+Testing 2002
+Testing 2003
+Testing 2004
+Testing 2005
+Testing 2006
+Testing 2007
+Testing 2008
+Testing 2009
+Testing 2010
+Testing 2011
+Testing 2012
+Testing 2013
+Testing 2014
+Testing 2015
+Testing 2016
+Testing 2017
+Testing 2018
+Testing 2019
+Testing 2020
+Testing 2021
+Testing 2022
+Testing 2023
+Testing 2024
+Testing 2025
+Testing 2026
+Testing 2027
+Testing 2028
+Testing 2029
+Testing 2030
+Testing 2031
+Testing 2032
+Testing 2033
+time.localtime( 0 ) returned (2000, 1, 1, 0, 0, 0, 5, 1) (pass)
+time.localtime( 1 ) returned (2000, 1, 1, 0, 0, 1, 5, 1) (pass)
+time.localtime( 59 ) returned (2000, 1, 1, 0, 0, 59, 5, 1) (pass)
+time.localtime( 60 ) returned (2000, 1, 1, 0, 1, 0, 5, 1) (pass)
+time.localtime( 3599 ) returned (2000, 1, 1, 0, 59, 59, 5, 1) (pass)
+time.localtime( 3600 ) returned (2000, 1, 1, 1, 0, 0, 5, 1) (pass)
+time.localtime( -1 ) returned (1999, 12, 31, 23, 59, 59, 4, 365) (pass)
+time.localtime( 447549467 ) returned (2014, 3, 7, 23, 17, 47, 4, 66) (pass)
+time.localtime( -940984933 ) returned (1970, 3, 7, 23, 17, 47, 5, 66) (pass)
+time.localtime( -1072915199 ) returned (1966, 1, 1, 0, 0, 1, 5, 1) (pass)
+time.localtime( -1072915200 ) returned (1966, 1, 1, 0, 0, 0, 5, 1) (pass)
+time.localtime( -1072915201 ) returned (1965, 12, 31, 23, 59, 59, 4, 365) (pass)
diff --git a/tests/renesas-ra/pin.py b/tests/renesas-ra/pin.py
new file mode 100644
index 000000000..32bad5dfe
--- /dev/null
+++ b/tests/renesas-ra/pin.py
@@ -0,0 +1,51 @@
+from machine import Pin
+import os
+
+n = os.uname().machine
+if "RA4W1_EK" in n:
+ try_pin = "P004"
+ try_s = "Pin(Pin.cpu.P004, mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.LOW_POWER)"
+else:
+ try_pin = "P000"
+ try_s = "Pin(Pin.cpu.P000, mode=Pin.IN, pull=Pin.PULL_NONE, drive=Pin.LOW_POWER)"
+
+p = Pin(try_pin, Pin.IN)
+if str(p) == try_s:
+ print("OK")
+else:
+ print("NG")
+ print("exp: " + try_s)
+ print("out: " + str(p))
+
+p = Pin("SW1", Pin.IN, Pin.PULL_UP)
+if p.mode() != 1:
+ print("mode: NG")
+p = Pin("SW1", Pin.IN, pull=Pin.PULL_UP)
+if p.pull() != 14:
+ print("pull: NG")
+p = Pin("SW1", mode=Pin.IN, pull=Pin.PULL_UP)
+
+p.init(p.IN, p.PULL_UP)
+p.init(p.IN, pull=p.PULL_UP)
+p.init(mode=p.IN, pull=p.PULL_UP)
+print(p.value())
+
+p.init(p.OUT)
+p.init(p.OPEN_DRAIN)
+p.low()
+print(p.value())
+p.high()
+print(p.value())
+p.value(0)
+print(p.value())
+p.value(1)
+print(p.value())
+p.value(False)
+print(p.value())
+p.value(True)
+print(p.value())
+p.off()
+print(p.value())
+p.on()
+print(p.value())
+p.off()
diff --git a/tests/renesas-ra/pin.py.exp b/tests/renesas-ra/pin.py.exp
new file mode 100644
index 000000000..4c8cc50b0
--- /dev/null
+++ b/tests/renesas-ra/pin.py.exp
@@ -0,0 +1,10 @@
+OK
+1
+0
+1
+0
+1
+0
+1
+0
+1
diff --git a/tests/renesas-ra/rtc_init.py b/tests/renesas-ra/rtc_init.py
new file mode 100644
index 000000000..08e36f535
--- /dev/null
+++ b/tests/renesas-ra/rtc_init.py
@@ -0,0 +1,12 @@
+import machine
+from machine import RTC
+import time
+
+rtc = RTC()
+rtc.init()
+print(rtc)
+
+# make sure that 1 second passes correctly
+rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
+time.sleep_ms(1002)
+print(rtc.datetime()[:7])
diff --git a/tests/renesas-ra/rtc_init.py.exp b/tests/renesas-ra/rtc_init.py.exp
new file mode 100644
index 000000000..d1ea2d959
--- /dev/null
+++ b/tests/renesas-ra/rtc_init.py.exp
@@ -0,0 +1,2 @@
+<RTC>
+(2014, 1, 1, 1, 0, 0, 1)
diff --git a/tests/renesas-ra/spi.py b/tests/renesas-ra/spi.py
new file mode 100644
index 000000000..eb24f3714
--- /dev/null
+++ b/tests/renesas-ra/spi.py
@@ -0,0 +1,40 @@
+import os
+from machine import SPI
+
+machine = os.uname().machine
+if (
+ "RA6M1_EK" in machine
+ or "RA4M1_CLICKER" in machine
+ or "RA4M1_EK" in machine
+ or "RA4W1_EK" in machine
+ or "RA6M1_EK" in machine
+):
+ spis = (-1, 0)
+else:
+ spis = (-1, 0, 1)
+
+# test we can correctly create by id
+for bus in spis:
+ try:
+ spi = SPI(bus)
+ except ValueError:
+ print("ValueError", bus)
+
+spi = SPI(0)
+print(spi)
+
+spi = SPI(0)
+spi = SPI(0, baudrate=500000)
+print(spi)
+spi = SPI(0, 500000, polarity=1, phase=0, bits=8)
+print(spi)
+spi.init(baudrate=400000)
+print(spi)
+spi.init(polarity=0)
+print(spi)
+spi.init(phase=1)
+print(spi)
+spi.init(bits=8)
+print(spi)
+
+spi.deinit()
diff --git a/tests/renesas-ra/spi.py.exp b/tests/renesas-ra/spi.py.exp
new file mode 100644
index 000000000..b2dd2b0fa
--- /dev/null
+++ b/tests/renesas-ra/spi.py.exp
@@ -0,0 +1,9 @@
+Warning: SPI(-1, ...) is deprecated, use SoftSPI(...) instead
+ValueError -1
+SPI(0, baudrate=500000, polarity=0, phase=0, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=500000, polarity=0, phase=0, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=500000, polarity=1, phase=0, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=400000, polarity=1, phase=0, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=400000, polarity=0, phase=0, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=400000, polarity=0, phase=1, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
+SPI(0, baudrate=400000, polarity=0, phase=1, bits=8, firstbit=0, sck=P102, mosi=P101, miso=P100)
diff --git a/tests/renesas-ra/uart1.py b/tests/renesas-ra/uart1.py
new file mode 100644
index 000000000..bf7b92760
--- /dev/null
+++ b/tests/renesas-ra/uart1.py
@@ -0,0 +1,51 @@
+import os
+from machine import UART
+
+machine = os.uname().machine
+if "RA6M2_EK" in machine:
+ # 0, 7, 9
+ uart_ids = (0, 7, 9)
+ try_id = 7
+ try_s = "UART(7, baudrate=115200, bits=8, parity=None, stop=1, tx=P401, rx=P402, flow=0, rxbuf=259, timeout=0, timeout_char=2)"
+elif "RA4M1_CLICKER" in machine:
+ # 0, 1
+ uart_ids = (0, 1)
+ try_id = 0
+ try_s = "UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=P411, rx=P410, flow=0, rxbuf=259, timeout=0, timeout_char=2)"
+elif "RA4M1_EK" in machine:
+ # 0, 1, 2, 9
+ # vector for 9 is not registered
+ uart_ids = (0, 1, 2)
+ try_id = 1
+ try_s = "UART(1, baudrate=115200, bits=8, parity=None, stop=1, tx=P401, rx=P402, flow=0, rxbuf=259, timeout=0, timeout_char=2)"
+elif "RA4W1_EK" in machine:
+ # 0, 1, 4, 9
+ # 0 is disabled.
+ uart_ids = (1, 4, 9)
+ try_id = 9
+ try_s = "UART(9, baudrate=115200, bits=8, parity=None, stop=1, tx=P109, rx=P110, flow=0, rxbuf=259, timeout=0, timeout_char=2)"
+elif "RA6M1_EK" in machine:
+ # 0, 1, 2, 3, 4, 8, 9
+ # 1/3/4/9 are disabled
+ uart_ids = (0, 2, 8)
+ try_id = 8
+ try_s = "UART(8, baudrate=115200, bits=8, parity=None, stop=1, tx=P105, rx=P104, flow=0, rxbuf=259, timeout=0, timeout_char=2)"
+else:
+ print("SKIP")
+ raise SystemExit
+
+for ch in uart_ids:
+ try:
+ uart = UART(ch)
+ except ValueError:
+ print("ValueError", bus)
+
+rxbuf_size = 259
+
+ch = UART(try_id, rxbuf=rxbuf_size)
+if str(ch) == try_s:
+ print("OK")
+else:
+ print("NG")
+ print("exp: " + try_s)
+ print("out: " + str(ch))
diff --git a/tests/renesas-ra/uart1.py.exp b/tests/renesas-ra/uart1.py.exp
new file mode 100644
index 000000000..d86bac9de
--- /dev/null
+++ b/tests/renesas-ra/uart1.py.exp
@@ -0,0 +1 @@
+OK