Merge branch 'feature/automated-tests'

pull/13/head
nirenjan 2017-07-27 20:52:09 -07:00
commit 55963ba824
82 changed files with 1335 additions and 11 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ cli/x52cli*
test/x52test*
util/util_char_map.c
util/x52charmapgen*
libusbx52/x52test*
x52pro-linux-*.tar.gz
# Module files

View File

@ -1,5 +1,5 @@
language: c
script: ./autogen.sh && ./configure && make V=0 && make distcheck
script: ./.travis_build.sh
# Compile using both gcc & clang
compiler:
@ -14,3 +14,4 @@ addons:
packages:
- libusb-1.0-0-dev
- libudev-dev
- realpath

24
.travis_build.sh 100755
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Script to run automated build and testing on Travis-CI
# Abort early in case of failure
set -e
# Generate the build files
./autogen.sh
# Create a temporary directory to store build artifacts
rm -rf build
mkdir build
cd build
# Run the configuration script
../configure
# Build and run any tests
make V=0
make check
# Verify that the distribution works
make distcheck

View File

@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = libx52 test cli util
SUBDIRS = lib utils tests
# Extra files that need to be in the distribution
EXTRA_DIST = README.md LICENSE

View File

@ -24,14 +24,17 @@ AS_IF([test "x${have_libusb}" != xyes], [
])
AC_SUBST([X52_PKG_VERSION], [0.1])
AC_SUBST([X52_INCLUDE], ["-I \$(top_srcdir)/libx52"])
AC_SUBST([X52_CORE_LIB], [../libx52/libx52.la])
AC_SUBST([X52_INCLUDE], ["-I \$(top_srcdir)/lib/libx52"])
AC_CONFIG_FILES([
Makefile
libx52/Makefile
test/Makefile
cli/Makefile
util/Makefile
lib/Makefile
lib/libx52/Makefile
lib/libusbx52/Makefile
lib/libx52util/Makefile
utils/Makefile
utils/cli/Makefile
utils/test/Makefile
tests/Makefile
])
AC_OUTPUT

View File

@ -0,0 +1,35 @@
LibUSB X52 stub library
=======================
The libusbx52 stub library is a convenience library to help test the libusb
functions used by libx52 and associated code. It simulates the behavior of the
libusb functions used by the libx52 library, but doesn't actually control any
real hardware, and simply updates a few in-memory data structures.
The idea behind `libusbx52.so` is to use it as an LD_PRELOAD library, where it
will override the real functions used by `libx52.so`. The use case for this
scenario is in an automated testing environment, where a test runner could set
up the list of devices manually and simulate various scenarios.
# Design Overview
Unfortunately, the automake infrastructure does not support the use of
LD_PRELOAD because it is deemed "non-portable" in the automake sense. As a
result, this is now up to a test runner application to implement a method to
control the data passed between two processes.
# Data Structures
The server process is responsible for setting up the initial set of USB devices.
As far as libx52 is concerned, the only fields that it uses in the USB
descriptor are the idVendor and idProduct fields. These are written to a file
that is read by the libusbx52 stubs to populate the device list.
Once the file has been written by the server, the libusb_init stub function in
the client can read the file and populate the internal data structures as
necessary.
The client can also write to a separate file to record the USB communication
sent across to the simulated device.

2
lib/Makefile.am 100644
View File

@ -0,0 +1,2 @@
SUBDIRS = libx52 libx52util libusbx52

View File

@ -0,0 +1,18 @@
ACLOCAL_AMFLAGS = -I m4
# libusb stub library for use by test programs
noinst_LTLIBRARIES = libusbx52.la
libusbx52_la_SOURCES = usb_x52_stub.c
libusbx52_la_LDFLAGS = -rpath /nowhere
# Utility programs for use by tests
noinst_PROGRAMS = x52test_create_device_list x52test_log_actions
x52test_create_device_list_SOURCES = util/create_device_list.c
x52test_log_actions_SOURCES = util/log_actions.c
x52test_log_actions_CFLAGS = @X52_INCLUDE@
x52test_log_actions_LDADD = libusbx52.la
EXTRA_DIST = README.md libusbx52.h

View File

@ -0,0 +1,15 @@
LibUSB mocker library
=====================
This folder contains a convenience library to mock the API of libusb. This is
intended to be used as an LD_PRELOAD library when used by automated tests to
verify the library without needing actual hardware to verify the tests.
While a manual test using real hardware is valuable, running some automated
tests in an environment where the hardware is not available is equally valuable,
especially if the source code is changing frequently.
Note that the API exported by the mocker is limited to the API used by libx52,
as writing a complete USB simulator stack in software is not an easy job, nor is
it necessary for the purposes of this project.

View File

@ -0,0 +1,53 @@
/*
* LibUSB stub driver for testing the Saitek X52/X52 Pro
*
* Copyright (C) 2017 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 <stdio.h>
#include <libusb-1.0/libusb.h>
struct libusb_device {
struct libusb_context *context;
int index;
int ref_count;
struct libusb_device_descriptor desc;
};
struct libusb_context {
int block_size; // Set to LIBUSBX52_MEMORY_BLOCK_SIZE
int max_devices; // Calculated based on block_size
int debug_level;
int num_devices;
struct libusb_device *devices;
};
struct libusb_device_handle {
struct libusb_context *ctx;
struct libusb_device *dev;
int packets_written;
FILE *packet_data_file;
};
/**
* @brief File location of the device list file
*
* This file contains a list of VIDs and PIDs in hexadecimal format separated
* by spaces. There must be an even number of entries, each pair corresponding
* to a (VID, PID) tuple identifying a single USB device.
*/
#define INPUT_DEVICE_LIST_FILE "/tmp/libusbx52_device_list"
/**
* @brief File location of the communication data file
*
* This file contains the libusb APIs called by libx52, after a device has
* been opened, i.e., all APIs that operate on a libusb_device_handle
*/
#define OUTPUT_DATA_FILE "/tmp/libusbx52_output_data"

View File

@ -0,0 +1,256 @@
/*
* LibUSB stub driver for testing the Saitek X52/X52 Pro
*
* Copyright (C) 2017 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 <stdio.h>
#include <stdlib.h>
#include <libusb-1.0/libusb.h>
#include "libusbx52.h"
int libusb_init(libusb_context **ctx)
{
int rc;
int dev_count;
int vid;
int pid;
int parsed;
FILE *dev_list;
int i;
/*
* Technically, libusb_init can be called with a NULL context pointer,
* in which case, libusb will allocate a default context. However, in
* the case of libx52, the libusb APIs are always called with a non-NULL
* context pointer, which is then initialized with the allocated context
* pointer.
*/
libusb_context *tmp_ctx = calloc(1, sizeof(*tmp_ctx));
if (tmp_ctx == NULL) {
rc = LIBUSB_ERROR_NO_MEM;
goto init_err_recovery;
}
dev_list = fopen(INPUT_DEVICE_LIST_FILE, "r");
if (dev_list == NULL) {
rc = LIBUSB_ERROR_IO;
goto init_err_recovery;
}
/* Determine the number of devices in the file */
dev_count = 0;
do {
parsed = fscanf(dev_list, "%x %x", &vid, &pid);
/*
* If we have read fewer than 2 items, then quit.
* We've read all we can
*/
if (parsed < 2) {
break;
}
dev_count++;
} while (!feof(dev_list));
/* Make sure we have at least 1 device */
if (dev_count == 0) {
rc = LIBUSB_ERROR_NOT_FOUND;
goto init_err_recovery;
}
/* We now have the number of devices, allocate memory for them */
tmp_ctx->devices = calloc(dev_count, sizeof(*(tmp_ctx->devices)));
if (tmp_ctx->devices == NULL) {
rc = LIBUSB_ERROR_NO_MEM;
goto init_err_recovery;
}
tmp_ctx->num_devices = dev_count;
/* Rewind and read the file again, but now put them into the device list */
rewind(dev_list);
for (i = 0; i < dev_count && !feof(dev_list); i++) {
/* Set the base fields */
tmp_ctx->devices[i].context = tmp_ctx;
tmp_ctx->devices[i].index = i;
parsed = fscanf(dev_list, "%x %x", &vid, &pid);
if (parsed < 2) {
/* Parse error, skip this device */
continue;
}
/* Set the VID & PID */
tmp_ctx->devices[i].desc.idVendor = vid;
tmp_ctx->devices[i].desc.idProduct = pid;
}
/* Done, close the file and return */
fclose(dev_list);
*ctx = tmp_ctx;
return LIBUSB_SUCCESS;
init_err_recovery:
/* Close the device list file if it is open */
if (dev_list) {
fclose(dev_list);
}
/* Free up any allocated memory */
libusb_exit(tmp_ctx);
return rc;
}
void libusb_exit(libusb_context *ctx)
{
if (ctx) {
if (ctx->devices) {
free(ctx->devices);
}
free(ctx);
}
}
void libusb_set_debug(libusb_context *ctx, int level)
{
/* Set the debug level appropriately */
ctx->debug_level = level;
}
ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
{
/* Allocate a list of num_devices, each pointing to a corresponding
* libusb_device structure.
*
* Actually, the allocation adds one more than needed, since the list
* is supposed to be NULL terminated, according to the libusb docs.
*/
libusb_device **tmp_list = calloc(ctx->num_devices + 1, sizeof(*tmp_list));
libusb_device *dev;
int i;
if (tmp_list == NULL) {
return LIBUSB_ERROR_NO_MEM;
}
/* Initialize the list with pointers to the individual devices */
for (i = 0; i < ctx->num_devices; i++) {
dev = &(ctx->devices[i]);
/* Increment the refcount */
dev->ref_count += 1;
tmp_list[i] = dev;
}
*list = tmp_list;
return ctx->num_devices;
}
void libusb_free_device_list(libusb_device **list, int unref_devices)
{
libusb_device **dev;
if (unref_devices) {
for (dev = list; *dev; dev++) {
/* Decrement the refcount */
(*dev)->ref_count -= 1;
}
}
free(list);
}
int libusb_get_device_descriptor(libusb_device *dev,
struct libusb_device_descriptor *desc)
{
/* Copy the descriptor to the destination address */
*desc = dev->desc;
return 0;
}
#define LIBUSB_DUMP_LOG_FILE(hdl, loglevel, fmt_str, ...) do { \
if (hdl->ctx->debug_level != LIBUSB_LOG_LEVEL_NONE && \
hdl->ctx->debug_level >= loglevel) { \
fprintf(hdl->packet_data_file, "%s: " fmt_str, __func__, __VA_ARGS__); \
} \
} while (0)
int libusb_open(libusb_device *dev, libusb_device_handle **handle)
{
/* Allocate a handle for the application */
libusb_device_handle *tmp_hdl = calloc(1, sizeof(*tmp_hdl));
if (tmp_hdl == NULL) {
return LIBUSB_ERROR_NO_MEM;
}
/* Increment the reference count for the underlying device */
dev->ref_count += 1;
/* Populate the handle structure with the right values */
tmp_hdl->ctx = dev->context;
tmp_hdl->dev = dev;
tmp_hdl->packet_data_file = fopen(OUTPUT_DATA_FILE, "w");
/* Make sure that the file opened correctly */
if (tmp_hdl->packet_data_file == NULL) {
/* Error condition, return with a failure */
free(tmp_hdl);
return LIBUSB_ERROR_IO;
}
LIBUSB_DUMP_LOG_FILE(tmp_hdl, LIBUSB_LOG_LEVEL_DEBUG,
"VID: %04x PID: %04x idx: %d ref: %d\n",
dev->desc.idVendor, dev->desc.idProduct, dev->index, dev->ref_count);
*handle = tmp_hdl;
return LIBUSB_SUCCESS;
}
void libusb_close(libusb_device_handle *dev_handle)
{
/* Decrement the refcount for the underlying device */
dev_handle->dev->ref_count -= 1;
libusb_device *dev = dev_handle->dev;
LIBUSB_DUMP_LOG_FILE(dev_handle, LIBUSB_LOG_LEVEL_DEBUG,
"VID: %04x PID: %04x idx: %d ref: %d\n",
dev->desc.idVendor, dev->desc.idProduct, dev->index, dev->ref_count);
/* Close the file */
fclose(dev_handle->packet_data_file);
/* Free any memory used */
free(dev_handle);
}
int libusb_control_transfer(libusb_device_handle *dev_handle,
uint8_t request_type,
uint8_t bRequest,
uint16_t wValue,
uint16_t wIndex,
unsigned char *data,
uint16_t wLength,
unsigned int timeout)
{
int i;
/* Always log the control transfer */
fprintf(dev_handle->packet_data_file,
"%s: RqType: %02x bRequest: %02x wValue: %04x wIndex: %04x timeout: %d\n",
__func__, request_type, bRequest, wValue, wIndex, timeout);
if (data != NULL) {
fprintf(dev_handle->packet_data_file, "%s: Data[%d]: ", __func__,
wLength);
for (i = 0; i < wLength; i++) {
fprintf(dev_handle->packet_data_file, "%02x ", data[i]);
}
fprintf(dev_handle->packet_data_file, "\n");
}
return 0;
}

View File

@ -0,0 +1,48 @@
/*
* LibUSB test utility library
*
* This program generates a list of USB devices for use by libusbx52.so
*
* Copyright (C) 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 <stdio.h>
#include <string.h>
#include <errno.h>
#include "libusbx52.h"
int main(int argc, char *argv[])
{
FILE *data;
char **id_pair;
int vid;
int pid;
int parsed;
int i;
data = fopen(INPUT_DEVICE_LIST_FILE, "w");
if (data == NULL) {
fprintf(stderr, "Unable to open %s for writing\n",
INPUT_DEVICE_LIST_FILE);
fprintf(stderr, "%s\n", strerror(errno));
}
/* Process arguments until there are fewer than 2 remaining */
for (i = 1; i < argc && (argc - i) >= 2; i += 2) {
parsed = sscanf(argv[i], "%x", &vid);
if (parsed != 1) break;
parsed = sscanf(argv[i+1], "%x", &pid);
if (parsed != 1) break;
fprintf(data, "%04x %04x\n", vid, pid);
}
fclose(data);
return 0;
}

View File

@ -0,0 +1,98 @@
/*
* LibUSB test utility library
*
* This program calls the libusb_control_transfer API to log the bytes to
* the given file. This is useful to generate a file with the same syntax
* and verify that they match.
*
* Copyright (C) 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "libusbx52.h"
#include "x52_commands.h"
libusb_context *global_context;
static int send_command(libusb_device_handle *hdl, uint16_t index, uint16_t value)
{
return libusb_control_transfer(hdl,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
X52_VENDOR_REQUEST, value, index, NULL, 0, 5000);
}
static libusb_device_handle *libusbx52_init(void)
{
int rc;
ssize_t count;
int i;
libusb_device **list;
libusb_device *device;
libusb_device_handle *hdl = NULL;
struct libusb_device_descriptor desc;
rc = libusb_init(&global_context);
if (rc) {
return NULL;
}
libusb_set_debug(global_context, LIBUSB_LOG_LEVEL_ERROR);
count = libusb_get_device_list(global_context, &list);
for (i = 0; i < count; i++) {
device = list[i];
if (!libusb_get_device_descriptor(device, &desc)) {
if (desc.idVendor == 0x06a3) {
if (desc.idProduct == 0x0762) {
rc = libusb_open(device, &hdl);
if (rc) {
if (hdl) free(hdl);
hdl = NULL;
break;
}
}
}
}
}
libusb_free_device_list(list, 1);
return hdl;
}
int main(int argc, char *argv[])
{
int index;
int value;
int parsed;
int i;
libusb_device_handle *hdl;
libusb_context *ctx;
hdl = libusbx52_init();
ctx = hdl->ctx;
/* Process arguments until there are fewer than 2 remaining */
for (i = 1; i < argc && (argc - i) >= 2; i += 2) {
parsed = sscanf(argv[i], "%x", &index);
if (parsed != 1) break;
parsed = sscanf(argv[i+1], "%x", &value);
if (parsed != 1) break;
send_command(hdl, index, value);
}
libusb_close(hdl);
libusb_exit(ctx);
return 0;
}

View File

@ -72,7 +72,7 @@ libx52_device* libx52_init(void)
#endif
goto err_recovery;
}
libusb_set_debug(x52_dev->ctx, 3);
libusb_set_debug(x52_dev->ctx, LIBUSB_LOG_LEVEL_WARNING);
count = libusb_get_device_list(x52_dev->ctx, &list);
for (i = 0; i < count; i++) {

51
tests/Makefile.am 100644
View File

@ -0,0 +1,51 @@
TEST_EXTENSIONS = .sh
SH_LOG_COMPILER = $(SHELL)
AM_SH_LOG_FLAGS =
TESTS = \
test_led_fire_off.sh \
test_led_fire_on.sh \
test_led_throttle_off.sh \
test_led_throttle_on.sh \
test_led_a_off.sh \
test_led_a_red.sh \
test_led_a_amber.sh \
test_led_a_green.sh \
test_led_b_off.sh \
test_led_b_red.sh \
test_led_b_amber.sh \
test_led_b_green.sh \
test_led_d_off.sh \
test_led_d_red.sh \
test_led_d_amber.sh \
test_led_d_green.sh \
test_led_e_off.sh \
test_led_e_red.sh \
test_led_e_amber.sh \
test_led_e_green.sh \
test_led_t1_off.sh \
test_led_t1_red.sh \
test_led_t1_amber.sh \
test_led_t1_green.sh \
test_led_t2_off.sh \
test_led_t2_red.sh \
test_led_t2_amber.sh \
test_led_t2_green.sh \
test_led_t3_off.sh \
test_led_t3_red.sh \
test_led_t3_amber.sh \
test_led_t3_green.sh \
test_led_pov_off.sh \
test_led_pov_red.sh \
test_led_pov_amber.sh \
test_led_pov_green.sh \
test_led_clutch_off.sh \
test_led_clutch_red.sh \
test_led_clutch_amber.sh \
test_led_clutch_green.sh \
test_skip.sh
EXTRA_DIST = common_infra.sh $(TESTS)

View File

@ -0,0 +1,127 @@
#!/bin/bash
# Common infrastructure for the test cases
# Set up exit status codes
EXIT_SUCCESS=0
EXIT_SKIP=77
EXIT_HARD_ERROR=99
EXIT_FAILURE=1
# Set up some command sequences
X52_LED_COMMAND_INDEX=00b8
X52_LED_FIRE_ON=0101
X52_LED_FIRE_OFF=0100
X52_LED_A_RED_ON=0201
X52_LED_A_RED_OFF=0200
X52_LED_A_GREEN_ON=0301
X52_LED_A_GREEN_OFF=0300
X52_LED_B_RED_ON=0401
X52_LED_B_RED_OFF=0400
X52_LED_B_GREEN_ON=0501
X52_LED_B_GREEN_OFF=0500
X52_LED_D_RED_ON=0601
X52_LED_D_RED_OFF=0600
X52_LED_D_GREEN_ON=0701
X52_LED_D_GREEN_OFF=0700
X52_LED_E_RED_ON=0801
X52_LED_E_RED_OFF=0800
X52_LED_E_GREEN_ON=0901
X52_LED_E_GREEN_OFF=0900
X52_LED_T1_RED_ON=0a01
X52_LED_T1_RED_OFF=0a00
X52_LED_T1_GREEN_ON=0b01
X52_LED_T1_GREEN_OFF=0b00
X52_LED_T2_RED_ON=0c01
X52_LED_T2_RED_OFF=0c00
X52_LED_T2_GREEN_ON=0d01
X52_LED_T2_GREEN_OFF=0d00
X52_LED_T3_RED_ON=0e01
X52_LED_T3_RED_OFF=0e00
X52_LED_T3_GREEN_ON=0f01
X52_LED_T3_GREEN_OFF=0f00
X52_LED_POV_RED_ON=1001
X52_LED_POV_RED_OFF=1000
X52_LED_POV_GREEN_ON=1101
X52_LED_POV_GREEN_OFF=1100
X52_LED_CLUTCH_RED_ON=1201
X52_LED_CLUTCH_RED_OFF=1200
X52_LED_CLUTCH_GREEN_ON=1301
X52_LED_CLUTCH_GREEN_OFF=1300
X52_LED_THROTTLE_ON=1401
X52_LED_THROTTLE_OFF=1400
find_programs()
{
# Find the X52cli script
X52CLI=$(find .. -path '*/cli/x52cli' -executable)
if [[ -z "$X52CLI" ]]
then
exit $EXIT_HARD_ERROR
fi
# Find the x52test_log_actions program
X52LOGACT=$(find .. -path '*/libusbx52/x52test_log_actions' -executable)
if [[ -z "$X52LOGACT" ]]
then
exit $EXIT_HARD_ERROR
fi
# Find the x52test_create_device_list program
X52DEVLIST=$(find .. -path '*/libusbx52/x52test_create_device_list' -executable)
if [[ -z "$X52DEVLIST" ]]
then
exit $EXIT_HARD_ERROR
fi
}
setup_preload()
{
# Find the libusb stub library
LIBUSB=$(find .. -name 'libusbx52.so.*.*.*' -type f)
if [[ -z "$LIBUSB" ]]
then
exit $EXIT_HARD_ERROR
fi
export LD_PRELOAD=$(realpath $LIBUSB)
}
setup_test()
{
EXPECTED_OUTPUT=$(mktemp)
trap "rm -f $EXPECTED_OUTPUT /tmp/libusbx52*" EXIT
$X52DEVLIST 06a3 0762
}
expect_pattern()
{
local msg="libusb_control_transfer: RqType: 40 bRequest: 91"
msg="$msg wValue: $2 wIndex: $1 timeout: 5000"
echo "$msg" >> $EXPECTED_OUTPUT
}
verify_output()
{
if diff -q $EXPECTED_OUTPUT /tmp/libusbx52_output_data
then
exit $EXIT_SUCCESS
else
echo 'Expected:'
echo '========='
sed 's/^/\t/' $EXPECTED_OUTPUT
echo
echo 'Observed:'
echo '========='
sed 's/^/\t/' /tmp/libusbx52_output_data
exit $EXIT_FAILURE
fi
}
set -e
find_programs
setup_test
setup_preload

108
tests/make_tests.sh 100755
View File

@ -0,0 +1,108 @@
#!/bin/bash
# Script to generate the test scripts
# Most of the test cases are extremely similar, but they do need to be created
# and saved in the repository so that the automake infrastructure can pick them
# up.
_mono_led_template()
{
local led_ident=$(echo $1 | tr a-z A-Z)
local led_color=$2
local state=$(echo "\$X52_LED_${led_ident}_${led_color}" | tr a-z A-Z)
cat << EOF
#!/bin/bash
# Test setting the $led_ident button $led_color
source \$(dirname \$0)/common_infra.sh
expect_pattern \$X52_LED_COMMAND_INDEX $state
\$X52CLI led $led_ident $led_color
verify_output
EOF
}
_color_led_template()
{
local led_ident=$(echo $1 | tr a-z A-Z)
local led_color=$2
local led_r_state=off
local led_g_state=off
case $led_color in
"red")
led_r_state=on
;;
"green")
led_g_state=on
;;
"amber")
led_r_state=on
led_g_state=on
;;
esac
led_r_state=$(echo "\$X52_LED_${led_ident}_red_${led_r_state}" | tr a-z A-Z)
led_g_state=$(echo "\$X52_LED_${led_ident}_green_${led_g_state}" | tr a-z A-Z)
cat << EOF
#!/bin/bash
# Test setting the $led_ident button to $led_color
source \$(dirname \$0)/common_infra.sh
expect_pattern \$X52_LED_COMMAND_INDEX $led_r_state
expect_pattern \$X52_LED_COMMAND_INDEX $led_g_state
\$X52CLI led $led_ident $led_color
verify_output
EOF
}
make_led_tests()
{
# Make the mono-color LED tests
for led in fire throttle
do
for state in off on
do
filename=test_led_${led}_${state}.sh
_mono_led_template $led $state > $filename
echo -e "\t$filename \\" >> Makefile.am
done
done
# Make the multi-color LED tests
for led in a b d e t1 t2 t3 pov clutch
do
for state in off red amber green
do
filename=test_led_${led}_${state}.sh
_color_led_template $led $state > test_led_${led}_${state}.sh
echo -e "\t$filename \\" >> Makefile.am
done
done
}
clear_tests()
{
# Delete the tests from Makefile.am
sed -i '/^TESTS /,$d' Makefile.am
echo "TESTS = \\" >> Makefile.am
}
finalize_tests()
{
# Put the last line to close the tests list
echo -e "\ttest_skip.sh\n" >> Makefile.am
echo -e "\nEXTRA_DIST = common_infra.sh \$(TESTS)\n" >> Makefile.am
}
clear_tests
make_led_tests
finalize_tests

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the A button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_GREEN_ON
$X52CLI led A amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the A button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_GREEN_ON
$X52CLI led A green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the A button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_GREEN_OFF
$X52CLI led A off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the A button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_A_GREEN_OFF
$X52CLI led A red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the B button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_GREEN_ON
$X52CLI led B amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the B button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_GREEN_ON
$X52CLI led B green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the B button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_GREEN_OFF
$X52CLI led B off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the B button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_B_GREEN_OFF
$X52CLI led B red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the CLUTCH button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_GREEN_ON
$X52CLI led CLUTCH amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the CLUTCH button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_GREEN_ON
$X52CLI led CLUTCH green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the CLUTCH button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_GREEN_OFF
$X52CLI led CLUTCH off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the CLUTCH button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_CLUTCH_GREEN_OFF
$X52CLI led CLUTCH red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the D button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_GREEN_ON
$X52CLI led D amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the D button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_GREEN_ON
$X52CLI led D green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the D button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_GREEN_OFF
$X52CLI led D off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the D button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_D_GREEN_OFF
$X52CLI led D red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the E button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_GREEN_ON
$X52CLI led E amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the E button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_GREEN_ON
$X52CLI led E green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the E button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_GREEN_OFF
$X52CLI led E off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the E button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_E_GREEN_OFF
$X52CLI led E red
verify_output

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Test setting the FIRE button off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_FIRE_OFF
$X52CLI led FIRE off
verify_output

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Test setting the FIRE button on
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_FIRE_ON
$X52CLI led FIRE on
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the POV button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_GREEN_ON
$X52CLI led POV amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the POV button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_GREEN_ON
$X52CLI led POV green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the POV button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_GREEN_OFF
$X52CLI led POV off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the POV button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_POV_GREEN_OFF
$X52CLI led POV red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T1 button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_GREEN_ON
$X52CLI led T1 amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T1 button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_GREEN_ON
$X52CLI led T1 green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T1 button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_GREEN_OFF
$X52CLI led T1 off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T1 button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T1_GREEN_OFF
$X52CLI led T1 red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T2 button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_GREEN_ON
$X52CLI led T2 amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T2 button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_GREEN_ON
$X52CLI led T2 green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T2 button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_GREEN_OFF
$X52CLI led T2 off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T2 button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T2_GREEN_OFF
$X52CLI led T2 red
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T3 button to amber
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_GREEN_ON
$X52CLI led T3 amber
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T3 button to green
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_GREEN_ON
$X52CLI led T3 green
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T3 button to off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_RED_OFF
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_GREEN_OFF
$X52CLI led T3 off
verify_output

View File

@ -0,0 +1,12 @@
#!/bin/bash
# Test setting the T3 button to red
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_RED_ON
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_T3_GREEN_OFF
$X52CLI led T3 red
verify_output

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Test setting the THROTTLE button off
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_THROTTLE_OFF
$X52CLI led THROTTLE off
verify_output

View File

@ -0,0 +1,11 @@
#!/bin/bash
# Test setting the THROTTLE button on
source $(dirname $0)/common_infra.sh
expect_pattern $X52_LED_COMMAND_INDEX $X52_LED_THROTTLE_ON
$X52CLI led THROTTLE on
verify_output

View File

@ -0,0 +1,6 @@
#!/bin/bash
# Test the LED Fire button
source $(dirname $0)/common_infra.sh
exit $EXIT_SKIP

View File

@ -0,0 +1,2 @@
SUBDIRS = cli test

View File

@ -5,7 +5,7 @@ bin_PROGRAMS = x52cli
# Command line utility that front ends the core library
x52cli_SOURCES = x52_cli.c
x52cli_CFLAGS = @X52_INCLUDE@
x52cli_LDADD = @X52_CORE_LIB@
x52cli_LDADD = ../../lib/libx52/libx52.la
# Man pages for CLI utility
dist_man1_MANS = x52cli.man

View File

@ -5,7 +5,7 @@ bin_PROGRAMS = x52test
# Test utility that exercises all the library functions
x52test_SOURCES = x52_test.c x52_test_mfd.c x52_test_led.c x52_test_clock.c
x52test_CFLAGS = @X52_INCLUDE@
x52test_LDADD = @X52_CORE_LIB@
x52test_LDADD = ../../lib/libx52/libx52.la
# Extra files that need to be in the distribution
EXTRA_DIST = x52_test_common.h