From: Rishi k. K R. <ris...@li...> - 2010-03-23 04:44:48
|
The branch, master, has been updated via 96a4822d72478abce6dceabc816f658ba4ded0d3 (commit) via c700433fe26d24b975bf241668a9701548e6c21d (commit) via 4d574b9f3c82a58d88b97e201ac49cddf7bc5c24 (commit) via e7ed287c04bef2108fa544b0b86629e554403970 (commit) via b80fdefbd1843484e5a3ccc3d5748fee5b4cd1f7 (commit) from 00c8b3450d151482e9f7424224fc8a64bff27fdd (commit) - Log ----------------------------------------------------------------- commit 96a4822d72478abce6dceabc816f658ba4ded0d3 Author: Rishikesh K Rajak <ris...@li...> Date: Mon Mar 22 11:53:21 2010 +0530 Merge branches 'next' and 'master' ----------------------------------------------------------------------- Summary of changes: .../rtc}/Makefile | 16 +- testcases/kernel/device-drivers/rtc/README | 29 +++ testcases/kernel/device-drivers/rtc/rtc-test.c | 218 ++++++++++++++++++++ .../conformance/interfaces/sem_getvalue/1-1.c | 21 +- .../conformance/interfaces/sem_getvalue/2-1.c | 19 +- .../conformance/interfaces/sem_getvalue/2-2.c | 59 ++---- .../conformance/interfaces/sem_getvalue/4-1.c | 18 +- .../conformance/interfaces/sem_getvalue/5-1.c | 23 +- 8 files changed, 318 insertions(+), 85 deletions(-) copy testcases/kernel/{syscalls/clock_nanosleep => device-drivers/rtc}/Makefile (73%) create mode 100644 testcases/kernel/device-drivers/rtc/README create mode 100644 testcases/kernel/device-drivers/rtc/rtc-test.c diff --git a/testcases/kernel/syscalls/clock_nanosleep/Makefile b/testcases/kernel/device-drivers/rtc/Makefile similarity index 73% copy from testcases/kernel/syscalls/clock_nanosleep/Makefile copy to testcases/kernel/device-drivers/rtc/Makefile index 71ebae9..9b776ca 100644 --- a/testcases/kernel/syscalls/clock_nanosleep/Makefile +++ b/testcases/kernel/device-drivers/rtc/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) International Business Machines Corp., 2009 +# Copyright (c) Larsen & Toubro Infotech Ltd., 2010 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,13 +13,17 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# # -top_srcdir ?= ../../../.. +CFLAGS = -O2 -Wall -I ../../../../include/ +LIBS = -L ../../../../lib/ -lltp +SRC = rtc-test.c -include $(top_srcdir)/include/mk/testcases.mk -LDLIBS += -lpthread -lrt +all: $(SRC) + $(CC) $(SRC) $(CFLAGS) $(LIBS) -o rtc-test -include $(top_srcdir)/include/mk/generic_leaf_target.mk +clean: + rm -f rtc-test diff --git a/testcases/kernel/device-drivers/rtc/README b/testcases/kernel/device-drivers/rtc/README new file mode 100644 index 0000000..3094aa7 --- /dev/null +++ b/testcases/kernel/device-drivers/rtc/README @@ -0,0 +1,29 @@ +rtc-test.c : Test the Real Time Clock driver + +Tests supported as of now +-------------------------- +1. Read test : This reads the time/date from the RTC + ioctls tested :- RTC_RD_TIME. + +2. Alarm Test: Sets the alarm to 5 seconds in future and makes sure it rings. + ioctls tested :- RTC_ALM_SET, RTC_ALM_READ, RTC_AIE_ON, RTC_AIE_OFF. + +3. Update interrupts test : Sets Update interrupts enable on, waits for five + interrupts and then turns it off. + ioctls tested :- RTC_UIE_ON, RTC_UIE_OFF. + + +How to Build +------------ +You have to build the complete LTP package before trying to build these tests. +After building the complete LTP sources enter this directory and issue a 'make'. + +How to Run +---------- + + The tests assume the rtc device node to be "/dev/rtc". If you have a +different node run the test with the name of the node as a parameter. + +Eg. If your node is /dev/rtc0, then run the test as + + $ ./rtc-test /dev/rtc0 diff --git a/testcases/kernel/device-drivers/rtc/rtc-test.c b/testcases/kernel/device-drivers/rtc/rtc-test.c new file mode 100644 index 0000000..a62b033 --- /dev/null +++ b/testcases/kernel/device-drivers/rtc/rtc-test.c @@ -0,0 +1,218 @@ +/* rtc-test.c + * + * Tests for the Real Time Clock driver. + * + * Copyright (c) Larsen & Toubro Infotech Ltd., 2010 + * + * Author : Silesh C V <Sil...@ln...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "test.h" +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <linux/rtc.h> +#include <errno.h> +#include <time.h> + +int rtc_fd = -1; +char *TCID = "rtc01"; +int TST_TOTAL = 3; + + +/* Read and Alarm Tests : Read test reads the Date/time from RTC + * while Alarm test, sets the alarm to 5 seconds in future and + * waits for it to ring.The ioctls tested in these tests are + * RTC_RD_TIME, RTC_ALM_SET, RTC_ALM_READ, RTC_AIE_OFF */ + +void read_alarm_test(void) +{ + struct rtc_time rtc_tm; + int ret; + unsigned long data; + fd_set rfds; + struct timeval tv; + + tst_resm(TINFO, "RTC READ TEST:"); + + /*Read RTC Time*/ + ret = ioctl(rtc_fd, RTC_RD_TIME, &rtc_tm); + if (ret == -1) { + tst_resm(TFAIL, "RTC_RD_TIME ioctl failed"); + return; + } + + tst_resm(TPASS, "RTC READ TEST Passed"); + + tst_resm(TINFO, "Current RTC date/time is %d-%d-%d, %02d:%02d:%02d.", + rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, + rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); + + tst_resm(TINFO, "RTC ALARM TEST :"); + + /*set Alarm to 5 Seconds*/ + rtc_tm.tm_sec += 5; + if (rtc_tm.tm_sec >= 60) { + rtc_tm.tm_sec %= 60; + rtc_tm.tm_min++; + } + + if (rtc_tm.tm_min == 60) { + rtc_tm.tm_min = 0; + rtc_tm.tm_hour++; + } + + if (rtc_tm.tm_hour == 24) + rtc_tm.tm_hour = 0; + + ret = ioctl(rtc_fd, RTC_ALM_SET, &rtc_tm); + if (ret == -1) { + tst_resm(TFAIL, "RTC_ALM_SET ioctl failed"); + return; + } + + /*Read current alarm time*/ + ret = ioctl(rtc_fd, RTC_ALM_READ, &rtc_tm); + if (ret == -1) { + tst_resm(TFAIL, "RTC_ALM_READ ioctl failed"); + return; + } + + tst_resm(TINFO, "Alarm time set to %02d:%02d:%02d.", + rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); + /* Enable alarm interrupts */ + ret = ioctl(rtc_fd, RTC_AIE_ON, 0); + if (ret == -1) { + tst_resm(TINFO, "RTC_AIE_ON ioctl failed"); + return; + } + + tst_resm(TINFO, "Waiting 5 seconds for the alarm..."); + + tv.tv_sec = 6;/*set 6 seconds as the time out*/ + tv.tv_usec = 0; + + FD_ZERO(&rfds); + FD_SET(rtc_fd, &rfds); + + ret = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);/*wait for alarm*/ + + if (ret == -1) { + tst_resm(TFAIL, "select failed"); + return; + } else if (ret) { + ret = read(rtc_fd, &data, sizeof(unsigned long)); + if (ret == -1) { + tst_resm(TFAIL, "read failed"); + return; + } + tst_resm(TINFO, "Alarm rang."); + } else { + tst_resm(TFAIL, "Timed out waiting for the alarm"); + return; + } + + /* Disable alarm interrupts */ + ret = ioctl(rtc_fd, RTC_AIE_OFF, 0); + if (ret == -1) { + tst_resm(TFAIL, "RTC_AIE_OFF ioctl failed"); + return; + } + tst_resm(TPASS, "RTC ALARM TEST Passed"); +} + +/* Update_interrupts_test :Once the Update interrupts is enabled, + * the RTC gives interrupts (1/sec) on the interrupts line(if the rtc + * has one). This is tested by enabling the update interrupts + * and then waiting for 5 interrupts.*/ + +void update_interrupts_test(void) +{ + int ret, i; + unsigned long data; + fd_set rfds; + struct timeval tv; + + tst_resm(TINFO, "RTC UPDATE INTERRUPTS TEST :"); + /*Turn on update interrupts*/ + ret = ioctl(rtc_fd, RTC_UIE_ON, 0); + if (ret == -1) { + tst_resm(TFAIL, "RTC_UIE_ON ioctl failed"); + return; + } + + tst_resm(TINFO, "Waiting for 5 update interrupts..."); + for (i = 1; i < 6; i++) { + + tv.tv_sec = 2; /*2 sec time out for each interrupt*/ + tv.tv_usec = 0; + + FD_ZERO(&rfds); + FD_SET(rtc_fd, &rfds); + + ret = select(rtc_fd + 1, &rfds, NULL, NULL, &tv); + if (ret == -1) { + tst_resm(TFAIL, "select failed"); + return; + } else if (ret) { + ret = read(rtc_fd, &data, sizeof(unsigned long)); + if (ret == -1) { + tst_resm(TFAIL, "read failed"); + return; + } + tst_resm(TINFO, "Update interrupt %d", i); + } else { + tst_resm(TFAIL, + "Timed out waiting for the update interrupt"); + return; + } + } + + /* Turn off update interrupts */ + ret = ioctl(rtc_fd, RTC_UIE_OFF, 0); + if (ret == -1) { + tst_resm(TFAIL, "RTC_UIE_OFF ioctl failed"); + return; + } + tst_resm(TPASS, "RTC UPDATE INTERRUPTS TEST Passed"); +} + +int main(int argc, char **argv) +{ + char *rtc_dev = "/dev/rtc"; + + if (argc == 2) + rtc_dev = argv[1]; + + rtc_fd = open(rtc_dev, O_RDONLY); + + if (rtc_fd < 0) + tst_brkm(TBROK | TERRNO, tst_exit, "couldn't open %s", rtc_dev); + + /*Read and alarm tests*/ + read_alarm_test(); + + /*Update interrupts test*/ + update_interrupts_test(); + + close(rtc_fd); + + tst_resm(TINFO, "RTC Tests Done!"); + return 0; +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c index 767f1b0..c0746c0 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/1-1.c @@ -10,9 +10,7 @@ * This test case will call sem_getvalue to update the location referenced * by the semaphpre without effecting the state of the semaphore. The * updated value represents the actual semaphore value when it was called. -*/ - - + */ #include <stdio.h> #include <errno.h> @@ -20,29 +18,29 @@ #include <semaphore.h> #include <sys/stat.h> #include <fcntl.h> +#include <limits.h> #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_getvalue" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " - -int main() { - - char semname[28]; +int main(void) +{ + char semname[NAME_MAX - 4]; sem_t *mysemp; int val; - sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); + snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); - if( mysemp == SEM_FAILED || mysemp == NULL ) { + if (mysemp == SEM_FAILED || mysemp == NULL) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } - if( sem_getvalue(mysemp, &val) == -1 ) { + if (sem_getvalue(mysemp, &val) == -1) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } @@ -50,7 +48,8 @@ int main() { /* printf("Current value is: %d\n", val); */ - if (val == 1 ) { + + if (val == 1) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c index ac19af8..06814fb 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-1.c @@ -8,8 +8,7 @@ /* * When semaphore is locked, then the value returned by sem_getvalue is zero. -*/ - + */ #include <stdio.h> #include <errno.h> @@ -17,35 +16,35 @@ #include <semaphore.h> #include <sys/stat.h> #include <fcntl.h> +#include <limits.h> #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_getvalue" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " - -int main() { - - char semname[28]; +int main(void) +{ + char semname[NAME_MAX - 4]; sem_t *mysemp; int val; - sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); + snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); - if( mysemp == SEM_FAILED || mysemp == NULL ) { + if (mysemp == SEM_FAILED || mysemp == NULL) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Lock Semaphore */ - if (sem_trywait(mysemp) == -1 ) { + if (sem_trywait(mysemp) == -1) { perror(ERROR_PREFIX "trywait"); return PTS_UNRESOLVED; } - if( sem_getvalue(mysemp, &val) < 0 ) { + if (sem_getvalue(mysemp, &val) < 0) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c index 5918ceb..9989e48 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/2-2.c @@ -83,18 +83,15 @@ /*************************** Test case ***********************************/ /******************************************************************************/ -void * threaded ( void * arg ) +void *threaded(void * arg) { int ret; - do - { + do { ret = sem_wait( arg ); - } - while ( ( ret != 0 ) && ( errno == EINTR ) ); + } while (( ret != 0 ) && (errno == EINTR)); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } @@ -103,7 +100,7 @@ void * threaded ( void * arg ) /* The main test function. */ -int main( int argc, char * argv[] ) +int main(int argc, char *argv[]) { int ret, val; sem_t sem; @@ -113,71 +110,61 @@ int main( int argc, char * argv[] ) output_init(); /* Initialize semaphore */ - ret = sem_init( &sem, 0, 0 ); + ret = sem_init(&sem, 0, 0); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( errno, "Failed to init semaphore" ); } /* Create the thread */ - ret = pthread_create( &th, NULL, threaded, &sem ); + ret = pthread_create(&th, NULL, threaded, &sem); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( ret, "Failed to create the thread" ); } /* Sleep 1 sec so the thread enters the sem_wait call */ - sleep( 1 ); + sleep(1); /* Check value */ - ret = sem_getvalue( &sem, &val ); + ret = sem_getvalue(&sem, &val); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( errno, "Failed to get semaphore value" ); } - if ( ( val != 0 ) && ( val != -1 ) ) - { - output( "Val: %d\n", val ); - FAILED( "Semaphore count is neither 0 nor # of waiting processes" ); + if ((val != 0) && (val != -1)) { + output("Val: %d\n", val ); + FAILED("Semaphore count is neither 0 nor # of waiting processes"); } /* Post the semaphore */ - ret = sem_post( &sem ); + ret = sem_post(&sem); - if ( ret != 0 ) - { - UNRESOLVED( errno, "Failed to post the semaphore" ); + if (ret != 0) { + UNRESOLVED(errno, "Failed to post the semaphore"); } /* Join the thread */ - ret = pthread_join( th, NULL ); + ret = pthread_join(th, NULL); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( ret, "Failed to join the thread" ); } - /* Destroy the semaphore */ - ret = sem_destroy( &sem ); + ret = sem_destroy(&sem); - if ( ret != 0 ) - { + if (ret != 0) { UNRESOLVED( errno, "Failed to sem_destroy" ); } /* Test passed */ #if VERBOSE > 0 - output( "Test passed\n" ); + output("Test passed\n"); #endif PASSED; } - - diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c index 0774acb..2507fd3 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/4-1.c @@ -9,9 +9,7 @@ /* * Upon successful completion of calling sem_getvalue, it shall return a value * of zero. -*/ - - + */ #include <stdio.h> #include <errno.h> @@ -19,29 +17,29 @@ #include <semaphore.h> #include <sys/stat.h> #include <fcntl.h> +#include <limits.h> #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_getvalue" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " - -int main() { - - char semname[28]; +int main(void) +{ + char semname[NAME_MAX - 4]; sem_t *mysemp; int val; - sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); + snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); - if( mysemp == SEM_FAILED || mysemp == NULL ) { + if (mysemp == SEM_FAILED || mysemp == NULL) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } - if( sem_getvalue(mysemp, &val) != 0 ) { + if (sem_getvalue(mysemp, &val) != 0) { puts("TEST FAILED"); return PTS_FAIL; } else { diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c index c77b19c..1f17f5f 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_getvalue/5-1.c @@ -9,8 +9,7 @@ /* * This test case verifies that calling sem_getvalue doesn't change the * state of the semaphore. -*/ - + */ #include <stdio.h> #include <errno.h> @@ -18,40 +17,40 @@ #include <semaphore.h> #include <sys/stat.h> #include <fcntl.h> +#include <limits.h> #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_getvalue" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " - -int main() { - - char semname[20]; +int main(void) +{ + char semname[NAME_MAX - 4]; sem_t *mysemp; int val; - sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); + snprintf(semname, sizeof(semname), "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 4); - if( mysemp == SEM_FAILED || mysemp == NULL ) { + if (mysemp == SEM_FAILED || mysemp == NULL) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } - if( sem_getvalue(mysemp, &val) == -1 ) { + if (sem_getvalue(mysemp, &val) == -1) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } - if ( sem_trywait(mysemp) == -1 ) { + if (sem_trywait(mysemp) == -1) { perror(ERROR_PREFIX "sem_trywait"); return PTS_UNRESOLVED; } - if( sem_getvalue(mysemp, &val) == -1 ) { + if (sem_getvalue(mysemp, &val) == -1) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } @@ -60,7 +59,7 @@ int main() { printf("Current value is: %d\n", val); */ - if (val == 3 ) { + if (val == 3) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); hooks/post-receive -- ltp |