summaryrefslogtreecommitdiff
path: root/evdevtest/juice_evtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'evdevtest/juice_evtest.c')
-rw-r--r--evdevtest/juice_evtest.c408
1 files changed, 0 insertions, 408 deletions
diff --git a/evdevtest/juice_evtest.c b/evdevtest/juice_evtest.c
deleted file mode 100644
index 66f98e4..0000000
--- a/evdevtest/juice_evtest.c
+++ /dev/null
@@ -1,408 +0,0 @@
-#include <linux/input.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <getopt.h>
-#include <errno.h>
-#include <time.h>
-#include <signal.h>
-
-#define debug 0
-#define JUICE_DEBUG() if (debug) \
- do \
- printf("##Juice debug in %s and line ##\n", __FUNCTION__, __LINE__); \
- while(0)
-
-#define JUICE_ERROR(X) \
- do \
- printf("##Juice error: %s in %s at line %d ##\n", X, __FUNCTION__, __LINE__); \
- while(0)
-
-#define DELAY 10
-#define CLOCK_REALTIME_ALARM 8
-#define CLOCK_BOOTTIME_ALARM 9
-
-#ifndef EVIOCGSUSPENDBLOCK
-/* Those calls aren't part of the official kernel - but we're likely
- * using Bionic's kernel headers */
-#define EVIOCGSUSPENDBLOCK _IOR('E', 0x91, int)
-#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)
-#endif
-
-void sigalarm(int signumber)
-{
- /*We just want to test the suspend and resuem
- * nothing need to be done here!
- */
-}
-
-static int suspend_resume_test(const int seconds)
-{
- int ret;
- timer_t timerid;
- struct itimerspec its;
- struct timespec t1, t2;
- struct sigevent se;
- struct sigaction act;
- sigset_t sigmask;
- int signum = SIGRTMAX;
-
- /* Set up signal handler */
- sigfillset(&act.sa_mask);
- act.sa_flags = 0;
- act.sa_handler = sigalarm;
- sigaction(signum, &act, NULL);
-
- /* Set up timer */
- memset(&se, 0, sizeof(se));
- se.sigev_notify = SIGEV_SIGNAL;
- se.sigev_signo = signum;
- se.sigev_value.sival_int = 0;
-
- if (seconds < 6) {
- JUICE_ERROR("Input suspend time less than 6 seconds");
- return -1;
- }
-
- ret = timer_create(CLOCK_REALTIME_ALARM, &se, &timerid);
- if (ret < 0) {
- JUICE_ERROR("Create alarm timer failed");
- return -1;
- }
-
- memset(&its, 0, sizeof(struct itimerspec));
- ret = clock_gettime(CLOCK_REALTIME_ALARM, &its.it_value);
- if (ret < 0) {
- JUICE_ERROR("Get time failed");
- return -1;
- }
-
- its.it_value.tv_sec += seconds;
-
- ret = timer_settime(timerid, TIMER_ABSTIME, &its, NULL);
- if (ret < 0) {
- JUICE_ERROR("Set alarm timer failed");
- return -1;
- }
-
- /*record the suspend start time*/
- ret = clock_gettime(CLOCK_REALTIME, &t1);
- if (ret < 0) {
- JUICE_ERROR("Get start time of suspend failed");
- return -1;
- }
-
- /*start suspend the system now*/
- ret = system("echo mem > /sys/power/state");
- if (ret < 0) {
- JUICE_ERROR("echo mem to power state failed");
- return -1;
- }
-
- /*record the system resume time*/
- ret = clock_gettime(CLOCK_REALTIME, &t2);
- if (ret < 0) {
- JUICE_ERROR("Get the suspend end time failed");
- return -1;
- }
-
- if (t2.tv_sec - t1.tv_sec >= seconds)
- return 0;
- else
- return 1;
-}
-
-int main (int argc, char **argv)
-{
- struct option lopt[] = {
- { "path", required_argument, NULL, 'p' },
- { "help", no_argument, NULL, 'h' },
- { NULL, 0, NULL, 0 },
- };
-
- char parameter1 = 0;
- int parameter2 = 0;
- long long parameter3 = 0;
-
- char * shopt = "p:h";
- char *evdevice = NULL;
- long enable_lock = 1, disable_lock = 0, lockvalue = -1;
- int fd, c, opti = 0, ret;
- unsigned int clk;
- struct input_event ev[64];
- struct timespec tp1, tp2;
-
- if(getuid()) {
- JUICE_ERROR("Not run this test as root");
- return -1;
- }
-
- while ((c = getopt_long(argc, argv, shopt, lopt, &opti)) != -1 ) {
- switch (c) {
- case 'h':
- fprintf(stdout, "Userage:\n" "juice_evtest -p /dev/input/eventX \n");
- break;
- case 'p':
- evdevice = strdup(optarg);
- break;
- default:
- JUICE_ERROR("Warning, unknown option!");
- break;
- }
- }
-
- if (!evdevice) {
- JUICE_ERROR("No input device");
- return -1;
- }
-
- /*Open the evdev input device*/
- if ((fd = open(evdevice, O_RDONLY)) < 0) {
- JUICE_ERROR("Open input device failed");
- return -1;
- }
-
-
- printf("===========================\n");
- printf("Starting input ioctl cmd EVIOCGSUSPENDBLOCK/EVIOCCSUSPENDBLOCK test:\n");
- /* Read lock command */
- if (ioctl(fd, EVIOCGSUSPENDBLOCK, &lockvalue))
- printf("[EVDEV_EVIOCGSUSPENDBLOCK_READ_TEST1]: test failed\n");
- else
- printf("[EVDEV_EVIOCGSUSPENDBLOCK_READ_TEST1]: test passed\n");
-
- if (0 == lockvalue) /*default lock value*/
- printf("[EVDEV_TEST2]: test passed\n");
- else
- printf("[EVDEV_TEST2]: test failed\n");
-
- /*Set user_wake_lock*/
- if (ioctl(fd, EVIOCSSUSPENDBLOCK, enable_lock))
- printf("[EVDEV_EVIOCSSUSPENDBLOCK_SET_TEST3]: test failed\n");
- else
- printf("[EVDEV_EVIOCSSUSPENDBLOCK_SET_TEST3]: test passed\n");
-
- /*Verfify the lock value equals what we set*/
- ioctl(fd, EVIOCGSUSPENDBLOCK, &lockvalue);
- if (enable_lock == lockvalue)
- printf("[EVDEV_TEST4]: test passed\n");
- else {
- printf("[EVDEV_TEST4]: test failed\n");
- goto para_test;
- }
-
- /*Start generating input event*/
- ret = system("echo 1 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Enable generate input event failed");
- goto para_test;
- }
-
- /*Judge the system can not suspend*/
- ret = suspend_resume_test(DELAY);
- if (1 == ret)
- printf("[EVDEV_CMD_DISABLE_SUSPEND_TEST5]: test passed\n");
- else
- printf("[EVDEV_CMD_DISABLE_SUSPEND_TEST5]: test failed\n");
-
- /*Disable evdev usr_wake_lock*/
- ioctl(fd, EVIOCSSUSPENDBLOCK, disable_lock);
- ioctl(fd, EVIOCGSUSPENDBLOCK, &lockvalue);
- if ( disable_lock == lockvalue )
- printf("[EVDEV_TEST6]: test passed\n");
- else
- printf("[EVDEV_TEST6]: test failed\n");
-
- /*Judge the system can be suspend resume*/
- ret = suspend_resume_test(DELAY);
- if (0 == ret)
- printf("[EVDEV_ENABLE_SUSPEND_RESUME_TEST7]: test passed\n");
- else
- printf("[EVDEV_ENABLE_SUSPEND_RESUME_TEST7]: test failed\n");
-
- /*Stop generateing input event*/
- ret = system("echo 0 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Disable generate input event failed");
- goto para_test;
- }
-
-
-
- /*The followings are the test cases for verifying different parameters*/
-para_test:
- /* Null parameters test!*/
- printf("Starting test EVIOCGSUSPENDBLOCK/EVIOCSSUSPENDBLOCK with different parameters:\n");
- ret = ioctl(fd, EVIOCGSUSPENDBLOCK, NULL);
- if (ret < 0)
- printf("[EVDEV_TEST8]: test passed\n");
- else
- printf("[EVDEV_TEST8]: test failed\n");
-
- ret = ioctl(fd, EVIOCSSUSPENDBLOCK, NULL);
- if (!ret)
- printf("[EVDEV_TEST9]: test passed\n");
- else
- printf("[EVDEV_TEST9]: test failed\n");
-
- /* byte parameters test*/
- ret = ioctl(fd, EVIOCGSUSPENDBLOCK, &parameter1);
- if (!ret)
- printf("[EVDEV_TEST10]: test passed\n");
- else
- printf("[EVDEV_TEST10]: test failed\n");
-
- ret = ioctl(fd, EVIOCSSUSPENDBLOCK, parameter1);
- if (!ret)
- printf("[EVDEV_TEST11]: test passed\n");
- else
- printf("[EVDEV_TEST11]: test failed\n");
-
- /* int parameters test*/
- ret = ioctl(fd, EVIOCGSUSPENDBLOCK, &parameter2);
- if (!ret)
- printf("[EVDEV_TEST12]: test passed\n");
- else
- printf("[EVDEV_TEST12]: test failed\n");
-
- ret = ioctl(fd, EVIOCSSUSPENDBLOCK, parameter2);
- if (!ret)
- printf("[EVDEV_TEST13]: test passed\n");
- else
- printf("[EVDEV_TEST13]: test failed\n");
-
- /* 64bit parameters test*/
- ret = ioctl(fd, EVIOCGSUSPENDBLOCK, &parameter3);
- if (!ret)
- printf("[EVDEV_TEST14]: test passed\n");
- else
- printf("[EVDEV_TEST14]: test failed\n");
-
- ret = ioctl(fd, EVIOCSSUSPENDBLOCK, parameter3);
- if (!ret)
- printf("[EVDEV_TEST15]: test passed\n");
- else
- printf("[EVDEV_TEST15]: test failed\n");
-
-
-
-/*The followings are testcases for ioctl cmd EVIOCSCLOCKID*/
- printf("Starting EVIOCSCLOCKID test:\n");
-
- clk = CLOCK_REALTIME_ALARM;
- ret = ioctl(fd, EVIOCSCLOCKID, &clk);
- if (ret < 0)
- printf("[EVDEV_TEST16]: test passed\n");
- else
- printf("[EVDEV_TEST16]: test failed\n");
-
- clk = CLOCK_BOOTTIME;
- ret = ioctl(fd, EVIOCSCLOCKID, &clk);
- if (ret < 0)
- printf("[EVDEV_TEST17]: test passed\n");
- else
- printf("[EVDEV_TEST17]: test failed\n");
-
- ret = ioctl(fd, EVIOCSCLOCKID, NULL);
- if (ret < 0)
- printf("[EVDEV_TEST18]: test passed\n");
- else
- printf("[EVDEV_TEST18]: test failed\n");
-
-
- /*EVIOCSCLOCKID with CLOCK_REALTIME test start*/
- clk = CLOCK_REALTIME;
- ret = ioctl(fd, EVIOCSCLOCKID, &clk);
- if (ret < 0)
- printf("[EVDEV_TEST19]: test failed\n");
- else
- printf("[EVDEV_TEST19]: test passed\n");
-
- /*Start generate event*/
- ret = system("echo 1 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Enable generating input event failed");
- goto finish;
- }
-
- ret = clock_gettime(CLOCK_REALTIME, &tp1);
- if (ret < 0)
- JUICE_ERROR("Get time with clock id REALTIME failed");
-
- /*Get event here!*/
- ret = read(fd, ev, sizeof(struct input_event));
- if (ret < (int) sizeof(struct input_event))
- JUICE_ERROR("Reading input event failed");
-
- ret = clock_gettime(CLOCK_REALTIME, &tp2);
- if (ret < 0)
- JUICE_ERROR("Get time with clock id REALTIME failed");
-
- if (tp1.tv_sec <= ev[0].time.tv_sec && ev[0].time.tv_sec <= tp2.tv_sec)
- printf("[EVDEV_TEST20]: test passed\n");
- else
- printf("[EVDEV_TEST20]: test failed\n");
-
- /*Stop generate input event*/
- ret = system("echo 0 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Disable generating input event failed");
- goto finish;
- }
- /*EVIOCSCLOCKID with CLOCK_REALTIME test end*/
-
-
- /*EVIOCSCLOCKID with CLOCK_MONOTONIC test start*/
- close(fd);
- if ((fd = open(evdevice, O_RDONLY)) < 0) {
- JUICE_ERROR("Open input device failed");
- return -1;
- }
-
- clk = CLOCK_MONOTONIC;
- ret = ioctl(fd, EVIOCSCLOCKID, &clk);
- if (ret < 0)
- printf("[EVDEV_TEST21]: test failed\n");
- else
- printf("[EVDEV_TEST21]: test passed\n");
-
- ret = system("echo 1 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Enable generating input event failed");
- goto finish;
- }
-
- ret = clock_gettime(CLOCK_MONOTONIC, &tp1);
- if (ret < 0)
- JUICE_ERROR("Get time with clock id MONOTONIC failed");
-
- /*Get event here!*/
- ret = read(fd, ev, sizeof(struct input_event));
- if (ret < (int) sizeof(struct input_event))
- JUICE_ERROR("Reading input event failed");
-
- ret = clock_gettime(CLOCK_MONOTONIC, &tp2);
- if (ret < 0)
- JUICE_ERROR("Get time with clock id MONOTONIC failed");
-
- if (tp1.tv_sec <= ev[0].time.tv_sec && ev[0].time.tv_sec<= tp2.tv_sec)
- printf("[EVDEV_TEST22]: test passed\n");
- else
- printf("[EVDEV_TEST22]: test failed\n");
-
- /*Stop generate input event*/
- ret = system("echo 0 > /sys/juice_input/run");
- if (ret < 0) {
- JUICE_ERROR("Disable generating input event failed");
- goto finish;
- }
- /*EVIOCSCLOCKID with CLOCK_MONOTONIC test end*/
-
-finish:
- close(fd);
- printf("===========================\n");
- return 0;
-}