Add option to run test without delay

x52test by default expects to run with an attached X52 unit. Since the
primary goal of the program is to test the hardware, it has embedded
delays to allow the user to verify the individual LEDs, MFD, brightness,
etc.

However, the complete test takes about 6 minutes. When using the stub
libusb library, the goal is to capture the requests, not verify it
against the hardware. In this case, the delays serve no useful purpose.

This change adds a nodelay flag, which is controlled by the presence of
a `NO_DELAY` environment variable, or the `LD_PRELOAD` environment
variable. As long as either of these variables are present in the
environment block, there will be no delays in the test execution.
debian-packaging
nirenjan 2020-04-12 16:48:29 -07:00
parent a7caba19df
commit dc80a0f2f1
5 changed files with 17 additions and 10 deletions

View File

@ -7,6 +7,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -15,6 +16,7 @@
#include "x52_test_common.h" #include "x52_test_common.h"
libx52_device *dev; libx52_device *dev;
int test_exit; int test_exit;
bool nodelay;
void test_cleanup(void) void test_cleanup(void)
{ {
@ -221,6 +223,9 @@ int main(int argc, char **argv)
} }
} }
/* Initialize the nodelay variable */
nodelay = (getenv("LD_PRELOAD") != NULL || getenv("NO_DELAY") != NULL);
if (test_list) { if (test_list) {
i = run_tests(test_list); i = run_tests(test_list);
} else { } else {

View File

@ -23,7 +23,7 @@ int test_clock(void)
#define TEST_CLOCK_LOOP(bump) do { \ #define TEST_CLOCK_LOOP(bump) do { \
for (i = start; i < end; i += bump) { \ for (i = start; i < end; i += bump) { \
TEST(clock, i, 0); \ TEST(clock, i, 0); \
usleep(250000); \ if (!nodelay) usleep(250000); \
} \ } \
} while (0) } while (0)

View File

@ -10,10 +10,12 @@
#define X52_TEST_COMMON_H #define X52_TEST_COMMON_H
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include "libx52.h" #include "libx52.h"
extern libx52_device *dev; extern libx52_device *dev;
extern int test_exit; extern int test_exit;
extern bool nodelay;
#define TEST(tst, ...) do { \ #define TEST(tst, ...) do { \
int rc; \ int rc; \

View File

@ -16,19 +16,19 @@
#define TEST_LED(name, state) do { \ #define TEST_LED(name, state) do { \
puts("LED " #name " - " #state); \ puts("LED " #name " - " #state); \
TEST(led_state, LIBX52_LED_ ## name, LIBX52_LED_STATE_ ## state); \ TEST(led_state, LIBX52_LED_ ## name, LIBX52_LED_STATE_ ## state); \
usleep(500000); \ if (!nodelay) usleep(500000); \
} while(0) } while(0)
#define TEST_LED_MONO(name) do { \ #define TEST_LED_MONO(name) do { \
puts("\nTesting LED " #name); \ puts("\nTesting LED " #name); \
sleep(2); \ if (!nodelay) sleep(2); \
TEST_LED(name, OFF); \ TEST_LED(name, OFF); \
TEST_LED(name, ON); \ TEST_LED(name, ON); \
} while(0) } while(0)
#define TEST_LED_COLOR(name) do {\ #define TEST_LED_COLOR(name) do {\
puts("\nTesting LED " #name); \ puts("\nTesting LED " #name); \
sleep(2); \ if (!nodelay) sleep(2); \
TEST_LED(name, OFF); \ TEST_LED(name, OFF); \
TEST_LED(name, RED); \ TEST_LED(name, RED); \
TEST_LED(name, AMBER); \ TEST_LED(name, AMBER); \
@ -57,10 +57,10 @@ int test_leds(void)
#define TEST_BLINK_OR_SHIFT(type) do { \ #define TEST_BLINK_OR_SHIFT(type) do { \
puts("\nTesting " #type); \ puts("\nTesting " #type); \
sleep(1); \ if (!nodelay) sleep(1); \
puts(#type " ON"); \ puts(#type " ON"); \
TEST(type, 1); \ TEST(type, 1); \
sleep(2); \ if (!nodelay) sleep(2); \
puts(#type " OFF"); \ puts(#type " OFF"); \
TEST(type, 0); \ TEST(type, 0); \
} while (0) } while (0)

View File

@ -29,14 +29,14 @@ int test_brightness(void)
if (!(i & 3)) fputs("#", stdout); if (!(i & 3)) fputs("#", stdout);
fflush(stdout); fflush(stdout);
TEST_BRIGHTNESS(1, i); TEST_BRIGHTNESS(1, i);
usleep(250000); if (!nodelay) usleep(250000);
} }
fputs("\nLED: ", stdout); fputs("\nLED: ", stdout);
for (i = 0; i < 129; i++) { for (i = 0; i < 129; i++) {
if (!(i & 3)) fputs("#", stdout); if (!(i & 3)) fputs("#", stdout);
fflush(stdout); fflush(stdout);
TEST_BRIGHTNESS(0, i); TEST_BRIGHTNESS(0, i);
usleep(250000); if (!nodelay) usleep(250000);
} }
fputs("\n\n", stdout); fputs("\n\n", stdout);
@ -66,7 +66,7 @@ int test_mfd_text(void)
TEST(text, 1, str, 16); TEST(text, 1, str, 16);
TEST(text, 2, str + 16, 16); TEST(text, 2, str + 16, 16);
sleep(2); if (!nodelay) sleep(2);
} }
return 0; return 0;
@ -92,7 +92,7 @@ int test_mfd_display(void)
TEST(text, 2, str, 16); TEST(text, 2, str, 16);
puts("OK"); puts("OK");
usleep(500000); if (!nodelay) usleep(500000);
} }
return 0; return 0;