Edit online

测试指南

RTC 测试所需的测试环境如下:
  • 硬件:开发板上安装有电池(用于给 RTC 供电)
  • 软件
    • PC 端的串口终端软件,用于 PC 和开发板进行串口通信

    • Linux 内核原生的 rtctest 工具

    • AiTest 测试框架,用于长时间的精度测试

测试步骤如下所示:
  1. 配置软件
    在 luban 的根目录下通过 menuconfig 可以打开 rtctest:
    Linux kernel
        Advance setting
            Linux Kernel Tools
                [*] selftests
  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
  3. RTC 精度测试

    测试过程需要用一个脚本来完成测试:

    1. 将 PC 的本地时间同步到板子上;
    2. 每隔 100 秒去检查下板子上的 RTC 时间,和 PC 时间比较,计算一个百万秒的精度值;
    3. 重复 3.b ,直到完成 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()