device-drivers/rtc: add rtc02 test
PATCH 1/1 device-drivers/rtc: add rtc02 test
From: Cixi Geng <[email protected]>
add new testcase for Real Time Clock driver
--- runtest/kernel_misc | 1 + testcases/kernel/device-drivers/rtc/rtc02.c | 119 ++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 testcases/kernel/device-drivers/rtc/rtc02.c
runtest/kernel_misc +1 -0
@@ -1,6 +1,7 @@ kmsg01 kmsg01 fw_load fw_load rtc01 rtc01 +rtc02 rtc02 block_dev block_dev tpci tpci tbio tbio
testcases/kernel/device-drivers/rtc/rtc02.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 1/1 device-drivers/rtc: add rtc02 test
Hi!
Quoted 2 lines
runtest/kernel_misc | 1 + testcases/kernel/device-drivers/rtc/rtc02.c | 119 ++++++++++++++++++++
Missing .gitignore entry, please add it.
testcases/kernel/device-drivers/rtc/rtc02.c line 2
Quoted 8 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +2
-0@@ -0,0 +1,119 @@ +/* +* Test for the Real Time Clock driver.
This test description should be more verbose, e.g. what exactly we do in the test and in a separate documentation comment.
See:
https://github.com/linux-test-project/ltp/blob/master/docparse/README.md
testcases/kernel/device-drivers/rtc/rtc02.c line 3
Quoted 1 line
testcases/kernel/device-drivers/rtc/rtc02.c new file +1
-0+*
^
Trailing whitespace.
Also there are many different minor coding style violations as well. Please use checkpatch.pl (which is distributed along linux kernel sources) to check for common mistakes before sending patches to mailing list.
testcases/kernel/device-drivers/rtc/rtc02.c line 4
Quoted 1 line
testcases/kernel/device-drivers/rtc/rtc02.c new file +1
-0+* SPDX-License-Identifier: GPL-2.0-or-later
This should be on a first line of the souce and the line should start with //
Quoted 8 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +8
-0+* Copyright (C) 2019, Unisoc Communications Inc. +* +* Author: Xiaopeng Bai <[email protected]> +* Author: Cixi Geng <[email protected]> +* +*/ +#include <sys/ioctl.h> +#include <stdio.h>
testcases/kernel/device-drivers/rtc/rtc02.c line 23
Quoted 10 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +10
-0+#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <linux/rtc.h> +#include <errno.h> +#include <time.h> + +#include "tst_test.h" + +int rtc_fd =-1 ;
Missing static.
testcases/kernel/device-drivers/rtc/rtc02.c line 36
Quoted 12 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +12
-0+static char *rtc_dev ="/dev/rtc" ; + +static struct tst_option rtc_options[] = { + {"d:" , &rtc_dev,"test driver device name" }, + {NULL ,NULL ,NULL } +}; + +static void help (void ) +{ +printf (" -d xxx --> rtc device node, default is %s\n" , + rtc_dev); +}
This is not used at all.
testcases/kernel/device-drivers/rtc/rtc02.c line 41
Quoted 4 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +4
-0+static void rtc_setup (void ) +{ +if (access (rtc_dev,F_OK ) ==-1 ) +tst_brk (TBROK |TERRNO ,"setenv() failed" );
^
Huh, really "setenv() failed" ?
Also this should really be TCONF
Also we do set the during the test so that we should restore it after the test as well.
We do this usually by:
* Reading the RTC in the setup as well as timestamping with monotonic timer
* Getting a second monotonic timestamp in the cleanup
* Setting the RTC to the value taken in setup plus the difference in the monotonic timer timestamps
Have a look how it's done for the system wallclock timer in lib/tst_wallclock.c. It would be very similar for RTC the only difference is that we will read/write RTC instead of realtime timer.
I guess that we can as well add tst_rtc_save() and tst_rct_restore() functions to the tst_wallclock.c if we are expecting to use the code from more than one testcase.
Quoted 14 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +14
-0+} + +static int rtc_tm_cmp (struct rtc_time *set_tm,struct rtc_time *read_tm) +{ +if ((set_tm->tm_sec == read_tm->tm_sec) + && (set_tm->tm_min == read_tm->tm_min) + && (set_tm->tm_hour == read_tm->tm_hour) + && (set_tm->tm_mday == read_tm->tm_mday) + && (set_tm->tm_mon == read_tm->tm_mon) + && (set_tm->tm_year == read_tm->tm_year)) { +return 0 ; + } + +return -1 ;
testcases/kernel/device-drivers/rtc/rtc02.c line 65
Quoted 10 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +10
-0+} + +static void set_rtc_test (void ) +{ +struct rtc_time set_tm, read_tm; +int ret; + + rtc_fd =SAFE_OPEN (rtc_dev,O_RDONLY ); + +tst_res (TINFO ,"RTC SET TEST :" );
We do not print what we are about to test in LTP, we just print the results.
testcases/kernel/device-drivers/rtc/rtc02.c line 73
Quoted 7 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +7
-0+/* set rtc to 2020.10.9 13:23:30 */ + set_tm.tm_sec =30 ; + set_tm.tm_min =23 ; + set_tm.tm_hour =13 ; + set_tm.tm_mday =9 ; + set_tm.tm_mon =9 ; + set_tm.tm_year =120 ;
This can be initialized on declaration as with:
struct rtc_time set_tm = {
.tm_sec = 30,
...
};testcases/kernel/device-drivers/rtc/rtc02.c line 76
Quoted 3 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +3
-0+tst_res (TINFO ,"set RTC date/time is %d-%d-%d, %02d:%02d:%02d." , + set_tm.tm_mday, set_tm.tm_mon +1 , set_tm.tm_year +1900 , + set_tm.tm_hour, set_tm.tm_min, set_tm.tm_sec);
I guess that should as well make a function to print the rtc_time structure sice to simplify the code since this is not the only place we use that.
testcases/kernel/device-drivers/rtc/rtc02.c line 84
Quoted 7 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +7
-0+ ret =ioctl (rtc_fd,RTC_SET_TIME , &set_tm); +if (ret !=0 ) { +tst_res (TFAIL |TERRNO ,"RTC_SET_TIME ioctl failed" ); +return ; + } + +tst_res (TINFO ,"RTC READ TEST:" );
Here as well, we do not announce what we are about to test.
Quoted 9 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +9
-0+/* Read current RTC Time */ + ret =ioctl (rtc_fd,RTC_RD_TIME , &read_tm); +if (ret !=0 ) { +tst_res (TFAIL |TERRNO ,"RTC_RD_TIME ioctl failed" ); +return ; + } +tst_res (TINFO ,"read RTC date/time is %d-%d-%d, %02d:%02d:%02d." , + read_tm.tm_mday, read_tm.tm_mon +1 , read_tm.tm_year +1900 , + read_tm.tm_hour, read_tm.tm_min, read_tm.tm_sec);
testcases/kernel/device-drivers/rtc/rtc02.c line 103
Quoted 10 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +10
-0+tst_res (TPASS ,"RTC READ TEST Passed" ); + +if (rtc_tm_cmp (&set_tm, &read_tm)) { +tst_res (TFAIL |TERRNO ,"RTC SET TEST Failed" ); +return ; + } + +tst_res (TPASS ,"RTC SET TEST Passed" ); + +tst_res (TINFO ,"RTC Tests Done!" );
And we do not print info like this either.
Quoted 19 lines
testcases/kernel/device-drivers/rtc/rtc02.c new file +16
-0+} + +static void rtc_cleanup (viod ) +{ +if (rtc_fd >0 ){ +SAFE_CLOSE (rtc_fd); + } +} + +static struct tst_test test={ + .setup = rtc_setup, + .test_all = set_rtc_test, + .options = rtc_options, + .cleanup = rtc_cleanup, + .needs_root =1 , +};Signature · 1 line
2.25.1
Signature · 2 lines
Cyril Hrubis [email protected]