From cd4fca0d2eaa21dff0ea9d36793da5dc6958f9d0 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Fri, 4 Dec 2015 17:58:34 -0800 Subject: [PATCH] Add tests for blink, shift & clock display --- libx52/Makefile.am | 3 +- libx52/src/x52_test.c | 2 ++ libx52/src/x52_test_clock.c | 55 ++++++++++++++++++++++++++++++++++++ libx52/src/x52_test_common.h | 4 ++- libx52/src/x52_test_led.c | 19 +++++++++++++ libx52/src/x52_test_mfd.c | 30 ++++---------------- 6 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 libx52/src/x52_test_clock.c diff --git a/libx52/Makefile.am b/libx52/Makefile.am index 6ca5562..1dcb614 100644 --- a/libx52/Makefile.am +++ b/libx52/Makefile.am @@ -11,5 +11,6 @@ bin_PROGRAMS = x52cli x52test x52cli_SOURCES = src/x52_cli.c x52cli_LDADD = libx52.la -x52test_SOURCES = src/x52_test.c src/x52_test_mfd.c src/x52_test_led.c +x52test_SOURCES = src/x52_test.c src/x52_test_mfd.c src/x52_test_led.c \ + src/x52_test_clock.c x52test_LDADD = libx52.la diff --git a/libx52/src/x52_test.c b/libx52/src/x52_test.c index 561faf5..a728fee 100644 --- a/libx52/src/x52_test.c +++ b/libx52/src/x52_test.c @@ -112,6 +112,8 @@ int main() RUN_TEST(leds) RUN_TEST(mfd_text) RUN_TEST(mfd_display) + RUN_TEST(blink_n_shift) + RUN_TEST(clock) } while (0); if (rc > 0) { diff --git a/libx52/src/x52_test_clock.c b/libx52/src/x52_test_clock.c new file mode 100644 index 0000000..e329a9b --- /dev/null +++ b/libx52/src/x52_test_clock.c @@ -0,0 +1,55 @@ +/* + * Saitek X52 Pro MFD & LED driver + * + * Copyright (C) 2012-2015 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * 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, version 2. + * + */ + +#include +#include +#include + +#include "libx52.h" +#include "x52_test_common.h" + +int test_clock(void) +{ + time_t i; + time_t start; + time_t end; + + print_banner("Clock"); + puts("This tests the clock display"); + + /* Start from midnight Jan 1 2015 GMT */ + start = 1420070400; + + puts("\nTesting clock time minute display for 1 hour increment"); + end = start + 3600; + TEST(clock_format, LIBX52_CLOCK_1, LIBX52_CLOCK_FORMAT_12HR); + for (i = start; i < end; i += 60) { + /* Run all minutes, display in GMT */ + TEST(clock, i, 0); + usleep(250000); + } + + puts("\nTesting clock time display for 25 hour increments, 12 hour mode"); + end = start + 86400 + 1440; + for (i = start; i < end; i += 3600) { + /* Run all hours, display in GMT */ + TEST(clock, i, 0); + usleep(250000); + } + + puts("\nTesting clock time display for 25 hour increments, 24 hour mode"); + TEST(clock_format, LIBX52_CLOCK_1, LIBX52_CLOCK_FORMAT_24HR); + for (i = start; i < end; i += 3600) { + /* Run all hours, display in GMT */ + TEST(clock, i, 0); + usleep(250000); + } +} diff --git a/libx52/src/x52_test_common.h b/libx52/src/x52_test_common.h index d3e5984..a9cc491 100644 --- a/libx52/src/x52_test_common.h +++ b/libx52/src/x52_test_common.h @@ -40,7 +40,9 @@ void print_banner(const char *message); int test_brightness(void); int test_mfd_display(void); +int test_mfd_text(void); int test_leds(void); - +int test_blink_n_shift(void); +int test_clock(void); #endif /* X52_TEST_COMMON_H */ diff --git a/libx52/src/x52_test_led.c b/libx52/src/x52_test_led.c index 7f0274f..6781293 100644 --- a/libx52/src/x52_test_led.c +++ b/libx52/src/x52_test_led.c @@ -57,3 +57,22 @@ int test_leds(void) return 0; } + +#define TEST_BLINK_OR_SHIFT(type) do { \ + puts("\nTesting " #type); \ + sleep(1); \ + puts(#type " ON"); \ + TEST(type, 1); \ + sleep(2); \ + puts(#type " OFF"); \ + TEST(type, 0); \ +} while (0) + +int test_blink_n_shift(void) +{ + print_banner("Blink & Shift"); + puts("This tests the blink indicator and shift functionality"); + + TEST_BLINK_OR_SHIFT(blink); + TEST_BLINK_OR_SHIFT(shift); +} diff --git a/libx52/src/x52_test_mfd.c b/libx52/src/x52_test_mfd.c index 4be4cb9..1cc7f6f 100644 --- a/libx52/src/x52_test_mfd.c +++ b/libx52/src/x52_test_mfd.c @@ -92,32 +92,12 @@ int test_mfd_display(void) memset(str, i, 16); - libx52_set_text(dev, 0, str, 16); - libx52_set_text(dev, 1, str, 16); - libx52_set_text(dev, 2, str, 16); + TEST(text, 0, str, 16); + TEST(text, 1, str, 16); + TEST(text, 2, str, 16); - /* Try upto 3 times - if it fails, dump an error */ - for (j = 0; j < 3; j++) { - rc = libx52_update(dev); - if (rc) { - fprintf(stderr, "\tError %d during update\n", rc); - sleep(1); - } else { - puts("OK"); - break; - } - } - - if (rc) { - return rc; - } - - if (test_exit) { - return test_exit; - } - - /* usleep(1500000); */ - sleep(1); + puts("OK"); + usleep(500000); } return 0;