4.4.4. 测试指南
4.4.4.1. 测试环境
4.4.4.1.1. 硬件
开发板上安装有电池(用于给RTC供电)
4.4.4.1.2. 软件
PC端的串口终端软件,用于PC和开发板进行串口通信
Linux内核原生的rtctest工具
AiTest测试框架,用于长时间的精度测试
4.4.4.1.3. 软件配置
4.4.4.1.3.1. rtctest
在openwrt的根目录下通过make menuconfig可以打开rtctest:
Linux kernel
Advance setting
Linux Kernel Tools
[*] selftests
4.4.4.2. rtctest 测试
rtctest的主要功能是测试RTC的Alarm功能,板子上的rtctest位于 /usr/lib/kselftests/rtc/
,进入该目录,直接运行rtctest即可:
[aic@] # cd /usr/lib/kselftests/rtc/
[aic@rtc] # ./rtctest
TAP version 13
1..7
# Starting 7 tests from 2 test cases.
# RUN rtc.date_read ...
# rtctest.c:49:date_read:Current RTC date/time is 05/01/1970 21:50:57.
# OK rtc.date_read
ok 1 rtc.date_read
# RUN rtc.uie_read ...
# OK rtc.uie_read
ok 2 rtc.uie_read
# RUN rtc.uie_select ...
# OK rtc.uie_select
ok 3 rtc.uie_select
# RUN rtc.alarm_alm_set ...
# rtctest.c:137:alarm_alm_set:Alarm time now set to 21:51:06.
# rtctest.c:156:alarm_alm_set:data: 1a0
# OK rtc.alarm_alm_set
ok 4 rtc.alarm_alm_set
# RUN rtc.alarm_wkalm_set ...
# rtctest.c:195:alarm_wkalm_set:Alarm time now set to 05/01/1970 21:51:09.
# OK rtc.alarm_wkalm_set
ok 5 rtc.alarm_wkalm_set
# RUN rtc.alarm_alm_set_minute ...
# rtctest.c:239:alarm_alm_set_minute:Alarm time now set to 21:52:00.
# rtctest.c:258:alarm_alm_set_minute:data: 1a0
# OK rtc.alarm_alm_set_minute
ok 6 rtc.alarm_alm_set_minute
# RUN rtc.alarm_wkalm_set_minute ...
# rtctest.c:297:alarm_wkalm_set_minute:Alarm time now set to 05/01/1970 21:53:00.
# OK rtc.alarm_wkalm_set_minute
ok 7 rtc.alarm_wkalm_set_minute
# PASSED: 7 / 7 tests passed.
# Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0
4.4.4.3. RTC 精度测试
测试过程需要用一个脚本来完成测试,测试步骤是:
将PC的本地时间同步到板子上;
每隔100秒去检查下板子上的RTC时间,和PC时间比较,计算一个百万秒的精度值;
重复步骤2,直到完成1百万秒的测试。
以下是测试用例的主干代码,详见AiTest/testcase/rtc/test_mod_rtc_precision.py
def test_case_rtc_precision(self):
self.assertTrue(self.detectLinux())
self.sync_localtime_to_target()
loop = int(self.mega / self.delay)
loop = 100 * int((loop + 99) / 100)
self.logger.info(f'Do {loop} loops, {self.delay} sec each loop\n')
for i in range(0, loop):
self.logger.info(f"{i}/{loop}. Sleep {self.delay} sec ...")
time.sleep(self.delay)
self.check_current_time()