mirror of https://github.com/nirenjan/libx52.git
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
parent
a7caba19df
commit
dc80a0f2f1
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include "x52_test_common.h"
|
||||
libx52_device *dev;
|
||||
int test_exit;
|
||||
bool nodelay;
|
||||
|
||||
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) {
|
||||
i = run_tests(test_list);
|
||||
} else {
|
||||
|
|
|
@ -23,7 +23,7 @@ int test_clock(void)
|
|||
#define TEST_CLOCK_LOOP(bump) do { \
|
||||
for (i = start; i < end; i += bump) { \
|
||||
TEST(clock, i, 0); \
|
||||
usleep(250000); \
|
||||
if (!nodelay) usleep(250000); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
#define X52_TEST_COMMON_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "libx52.h"
|
||||
|
||||
extern libx52_device *dev;
|
||||
extern int test_exit;
|
||||
extern bool nodelay;
|
||||
|
||||
#define TEST(tst, ...) do { \
|
||||
int rc; \
|
||||
|
|
|
@ -16,19 +16,19 @@
|
|||
#define TEST_LED(name, state) do { \
|
||||
puts("LED " #name " - " #state); \
|
||||
TEST(led_state, LIBX52_LED_ ## name, LIBX52_LED_STATE_ ## state); \
|
||||
usleep(500000); \
|
||||
if (!nodelay) usleep(500000); \
|
||||
} while(0)
|
||||
|
||||
#define TEST_LED_MONO(name) do { \
|
||||
puts("\nTesting LED " #name); \
|
||||
sleep(2); \
|
||||
if (!nodelay) sleep(2); \
|
||||
TEST_LED(name, OFF); \
|
||||
TEST_LED(name, ON); \
|
||||
} while(0)
|
||||
|
||||
#define TEST_LED_COLOR(name) do {\
|
||||
puts("\nTesting LED " #name); \
|
||||
sleep(2); \
|
||||
if (!nodelay) sleep(2); \
|
||||
TEST_LED(name, OFF); \
|
||||
TEST_LED(name, RED); \
|
||||
TEST_LED(name, AMBER); \
|
||||
|
@ -57,10 +57,10 @@ int test_leds(void)
|
|||
|
||||
#define TEST_BLINK_OR_SHIFT(type) do { \
|
||||
puts("\nTesting " #type); \
|
||||
sleep(1); \
|
||||
if (!nodelay) sleep(1); \
|
||||
puts(#type " ON"); \
|
||||
TEST(type, 1); \
|
||||
sleep(2); \
|
||||
if (!nodelay) sleep(2); \
|
||||
puts(#type " OFF"); \
|
||||
TEST(type, 0); \
|
||||
} while (0)
|
||||
|
|
|
@ -29,14 +29,14 @@ int test_brightness(void)
|
|||
if (!(i & 3)) fputs("#", stdout);
|
||||
fflush(stdout);
|
||||
TEST_BRIGHTNESS(1, i);
|
||||
usleep(250000);
|
||||
if (!nodelay) usleep(250000);
|
||||
}
|
||||
fputs("\nLED: ", stdout);
|
||||
for (i = 0; i < 129; i++) {
|
||||
if (!(i & 3)) fputs("#", stdout);
|
||||
fflush(stdout);
|
||||
TEST_BRIGHTNESS(0, i);
|
||||
usleep(250000);
|
||||
if (!nodelay) usleep(250000);
|
||||
}
|
||||
|
||||
fputs("\n\n", stdout);
|
||||
|
@ -66,7 +66,7 @@ int test_mfd_text(void)
|
|||
TEST(text, 1, str, 16);
|
||||
TEST(text, 2, str + 16, 16);
|
||||
|
||||
sleep(2);
|
||||
if (!nodelay) sleep(2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -92,7 +92,7 @@ int test_mfd_display(void)
|
|||
TEST(text, 2, str, 16);
|
||||
|
||||
puts("OK");
|
||||
usleep(500000);
|
||||
if (!nodelay) usleep(500000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue