diff --git a/.gitignore b/.gitignore index 96d27c1..7a334a8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ cli/x52cli* test/x52test* util/util_char_map.c util/x52charmapgen* +libusbx52/x52test* x52pro-linux-*.tar.gz # Module files diff --git a/.travis.yml b/.travis.yml index 94aaa21..5675ad0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.travis_build.sh b/.travis_build.sh new file mode 100755 index 0000000..17c9419 --- /dev/null +++ b/.travis_build.sh @@ -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 + diff --git a/Makefile.am b/Makefile.am index 123f8e4..c362fcd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index 8e32324..083059e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/docs/design/libusbx52.md b/docs/design/libusbx52.md new file mode 100644 index 0000000..3dc56ce --- /dev/null +++ b/docs/design/libusbx52.md @@ -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. + + diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 0000000..891dcef --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = libx52 libx52util libusbx52 + diff --git a/lib/libusbx52/Makefile.am b/lib/libusbx52/Makefile.am new file mode 100644 index 0000000..71741cc --- /dev/null +++ b/lib/libusbx52/Makefile.am @@ -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 diff --git a/lib/libusbx52/README.md b/lib/libusbx52/README.md new file mode 100644 index 0000000..749f2ee --- /dev/null +++ b/lib/libusbx52/README.md @@ -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. + diff --git a/lib/libusbx52/libusbx52.h b/lib/libusbx52/libusbx52.h new file mode 100644 index 0000000..ed69519 --- /dev/null +++ b/lib/libusbx52/libusbx52.h @@ -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 +#include + +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" + diff --git a/lib/libusbx52/usb_x52_stub.c b/lib/libusbx52/usb_x52_stub.c new file mode 100644 index 0000000..609bc33 --- /dev/null +++ b/lib/libusbx52/usb_x52_stub.c @@ -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 +#include +#include +#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; +} diff --git a/lib/libusbx52/util/create_device_list.c b/lib/libusbx52/util/create_device_list.c new file mode 100644 index 0000000..e2c3591 --- /dev/null +++ b/lib/libusbx52/util/create_device_list.c @@ -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 +#include +#include +#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; +} diff --git a/lib/libusbx52/util/log_actions.c b/lib/libusbx52/util/log_actions.c new file mode 100644 index 0000000..f0f07d9 --- /dev/null +++ b/lib/libusbx52/util/log_actions.c @@ -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 +#include +#include +#include +#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; +} diff --git a/libx52/Makefile.am b/lib/libx52/Makefile.am similarity index 100% rename from libx52/Makefile.am rename to lib/libx52/Makefile.am diff --git a/libx52/README.md b/lib/libx52/README.md similarity index 100% rename from libx52/README.md rename to lib/libx52/README.md diff --git a/libx52/libx52.h b/lib/libx52/libx52.h similarity index 100% rename from libx52/libx52.h rename to lib/libx52/libx52.h diff --git a/libx52/x52_commands.h b/lib/libx52/x52_commands.h similarity index 100% rename from libx52/x52_commands.h rename to lib/libx52/x52_commands.h diff --git a/libx52/x52_common.h b/lib/libx52/x52_common.h similarity index 100% rename from libx52/x52_common.h rename to lib/libx52/x52_common.h diff --git a/libx52/x52_control.c b/lib/libx52/x52_control.c similarity index 100% rename from libx52/x52_control.c rename to lib/libx52/x52_control.c diff --git a/libx52/x52_core.c b/lib/libx52/x52_core.c similarity index 97% rename from libx52/x52_core.c rename to lib/libx52/x52_core.c index ed14ec4..d73d6be 100644 --- a/libx52/x52_core.c +++ b/lib/libx52/x52_core.c @@ -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++) { diff --git a/libx52/x52_date_time.c b/lib/libx52/x52_date_time.c similarity index 100% rename from libx52/x52_date_time.c rename to lib/libx52/x52_date_time.c diff --git a/libx52/x52_mfd_led.c b/lib/libx52/x52_mfd_led.c similarity index 100% rename from libx52/x52_mfd_led.c rename to lib/libx52/x52_mfd_led.c diff --git a/util/Makefile.am b/lib/libx52util/Makefile.am similarity index 100% rename from util/Makefile.am rename to lib/libx52util/Makefile.am diff --git a/util/libx52util.h b/lib/libx52util/libx52util.h similarity index 100% rename from util/libx52util.h rename to lib/libx52util/libx52util.h diff --git a/util/x52_char_map.cfg b/lib/libx52util/x52_char_map.cfg similarity index 100% rename from util/x52_char_map.cfg rename to lib/libx52util/x52_char_map.cfg diff --git a/util/x52_char_map.h b/lib/libx52util/x52_char_map.h similarity index 100% rename from util/x52_char_map.h rename to lib/libx52util/x52_char_map.h diff --git a/util/x52_char_map_gen.py b/lib/libx52util/x52_char_map_gen.py similarity index 100% rename from util/x52_char_map_gen.py rename to lib/libx52util/x52_char_map_gen.py diff --git a/util/x52_char_map_lookup.c b/lib/libx52util/x52_char_map_lookup.c similarity index 100% rename from util/x52_char_map_lookup.c rename to lib/libx52util/x52_char_map_lookup.c diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..e4405bd --- /dev/null +++ b/tests/Makefile.am @@ -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) + diff --git a/tests/common_infra.sh b/tests/common_infra.sh new file mode 100644 index 0000000..99d3754 --- /dev/null +++ b/tests/common_infra.sh @@ -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 + diff --git a/tests/make_tests.sh b/tests/make_tests.sh new file mode 100755 index 0000000..4c53491 --- /dev/null +++ b/tests/make_tests.sh @@ -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 diff --git a/tests/test_led_a_amber.sh b/tests/test_led_a_amber.sh new file mode 100644 index 0000000..a5ecbf8 --- /dev/null +++ b/tests/test_led_a_amber.sh @@ -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 + diff --git a/tests/test_led_a_green.sh b/tests/test_led_a_green.sh new file mode 100644 index 0000000..fb775d0 --- /dev/null +++ b/tests/test_led_a_green.sh @@ -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 + diff --git a/tests/test_led_a_off.sh b/tests/test_led_a_off.sh new file mode 100644 index 0000000..28e9194 --- /dev/null +++ b/tests/test_led_a_off.sh @@ -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 + diff --git a/tests/test_led_a_red.sh b/tests/test_led_a_red.sh new file mode 100644 index 0000000..3f85b34 --- /dev/null +++ b/tests/test_led_a_red.sh @@ -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 + diff --git a/tests/test_led_b_amber.sh b/tests/test_led_b_amber.sh new file mode 100644 index 0000000..87ab013 --- /dev/null +++ b/tests/test_led_b_amber.sh @@ -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 + diff --git a/tests/test_led_b_green.sh b/tests/test_led_b_green.sh new file mode 100644 index 0000000..2580466 --- /dev/null +++ b/tests/test_led_b_green.sh @@ -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 + diff --git a/tests/test_led_b_off.sh b/tests/test_led_b_off.sh new file mode 100644 index 0000000..352b4d9 --- /dev/null +++ b/tests/test_led_b_off.sh @@ -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 + diff --git a/tests/test_led_b_red.sh b/tests/test_led_b_red.sh new file mode 100644 index 0000000..461791b --- /dev/null +++ b/tests/test_led_b_red.sh @@ -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 + diff --git a/tests/test_led_clutch_amber.sh b/tests/test_led_clutch_amber.sh new file mode 100644 index 0000000..13fc16a --- /dev/null +++ b/tests/test_led_clutch_amber.sh @@ -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 + diff --git a/tests/test_led_clutch_green.sh b/tests/test_led_clutch_green.sh new file mode 100644 index 0000000..05c8d69 --- /dev/null +++ b/tests/test_led_clutch_green.sh @@ -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 + diff --git a/tests/test_led_clutch_off.sh b/tests/test_led_clutch_off.sh new file mode 100644 index 0000000..8652914 --- /dev/null +++ b/tests/test_led_clutch_off.sh @@ -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 + diff --git a/tests/test_led_clutch_red.sh b/tests/test_led_clutch_red.sh new file mode 100644 index 0000000..c496c5f --- /dev/null +++ b/tests/test_led_clutch_red.sh @@ -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 + diff --git a/tests/test_led_d_amber.sh b/tests/test_led_d_amber.sh new file mode 100644 index 0000000..1ec1d17 --- /dev/null +++ b/tests/test_led_d_amber.sh @@ -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 + diff --git a/tests/test_led_d_green.sh b/tests/test_led_d_green.sh new file mode 100644 index 0000000..43439db --- /dev/null +++ b/tests/test_led_d_green.sh @@ -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 + diff --git a/tests/test_led_d_off.sh b/tests/test_led_d_off.sh new file mode 100644 index 0000000..ba81a5e --- /dev/null +++ b/tests/test_led_d_off.sh @@ -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 + diff --git a/tests/test_led_d_red.sh b/tests/test_led_d_red.sh new file mode 100644 index 0000000..5f1ca06 --- /dev/null +++ b/tests/test_led_d_red.sh @@ -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 + diff --git a/tests/test_led_e_amber.sh b/tests/test_led_e_amber.sh new file mode 100644 index 0000000..a25e655 --- /dev/null +++ b/tests/test_led_e_amber.sh @@ -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 + diff --git a/tests/test_led_e_green.sh b/tests/test_led_e_green.sh new file mode 100644 index 0000000..763a78b --- /dev/null +++ b/tests/test_led_e_green.sh @@ -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 + diff --git a/tests/test_led_e_off.sh b/tests/test_led_e_off.sh new file mode 100644 index 0000000..36fd67c --- /dev/null +++ b/tests/test_led_e_off.sh @@ -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 + diff --git a/tests/test_led_e_red.sh b/tests/test_led_e_red.sh new file mode 100644 index 0000000..c6c12c2 --- /dev/null +++ b/tests/test_led_e_red.sh @@ -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 + diff --git a/tests/test_led_fire_off.sh b/tests/test_led_fire_off.sh new file mode 100644 index 0000000..32e6046 --- /dev/null +++ b/tests/test_led_fire_off.sh @@ -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 + diff --git a/tests/test_led_fire_on.sh b/tests/test_led_fire_on.sh new file mode 100644 index 0000000..a4b0cd4 --- /dev/null +++ b/tests/test_led_fire_on.sh @@ -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 + diff --git a/tests/test_led_pov_amber.sh b/tests/test_led_pov_amber.sh new file mode 100644 index 0000000..fe58c24 --- /dev/null +++ b/tests/test_led_pov_amber.sh @@ -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 + diff --git a/tests/test_led_pov_green.sh b/tests/test_led_pov_green.sh new file mode 100644 index 0000000..74fb9c0 --- /dev/null +++ b/tests/test_led_pov_green.sh @@ -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 + diff --git a/tests/test_led_pov_off.sh b/tests/test_led_pov_off.sh new file mode 100644 index 0000000..cad3b5f --- /dev/null +++ b/tests/test_led_pov_off.sh @@ -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 + diff --git a/tests/test_led_pov_red.sh b/tests/test_led_pov_red.sh new file mode 100644 index 0000000..01bf7f1 --- /dev/null +++ b/tests/test_led_pov_red.sh @@ -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 + diff --git a/tests/test_led_t1_amber.sh b/tests/test_led_t1_amber.sh new file mode 100644 index 0000000..c9906e1 --- /dev/null +++ b/tests/test_led_t1_amber.sh @@ -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 + diff --git a/tests/test_led_t1_green.sh b/tests/test_led_t1_green.sh new file mode 100644 index 0000000..bf17414 --- /dev/null +++ b/tests/test_led_t1_green.sh @@ -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 + diff --git a/tests/test_led_t1_off.sh b/tests/test_led_t1_off.sh new file mode 100644 index 0000000..225bef1 --- /dev/null +++ b/tests/test_led_t1_off.sh @@ -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 + diff --git a/tests/test_led_t1_red.sh b/tests/test_led_t1_red.sh new file mode 100644 index 0000000..64fe574 --- /dev/null +++ b/tests/test_led_t1_red.sh @@ -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 + diff --git a/tests/test_led_t2_amber.sh b/tests/test_led_t2_amber.sh new file mode 100644 index 0000000..6c4c0ff --- /dev/null +++ b/tests/test_led_t2_amber.sh @@ -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 + diff --git a/tests/test_led_t2_green.sh b/tests/test_led_t2_green.sh new file mode 100644 index 0000000..f25f592 --- /dev/null +++ b/tests/test_led_t2_green.sh @@ -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 + diff --git a/tests/test_led_t2_off.sh b/tests/test_led_t2_off.sh new file mode 100644 index 0000000..d27f245 --- /dev/null +++ b/tests/test_led_t2_off.sh @@ -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 + diff --git a/tests/test_led_t2_red.sh b/tests/test_led_t2_red.sh new file mode 100644 index 0000000..1ad6755 --- /dev/null +++ b/tests/test_led_t2_red.sh @@ -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 + diff --git a/tests/test_led_t3_amber.sh b/tests/test_led_t3_amber.sh new file mode 100644 index 0000000..63656e1 --- /dev/null +++ b/tests/test_led_t3_amber.sh @@ -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 + diff --git a/tests/test_led_t3_green.sh b/tests/test_led_t3_green.sh new file mode 100644 index 0000000..05c9255 --- /dev/null +++ b/tests/test_led_t3_green.sh @@ -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 + diff --git a/tests/test_led_t3_off.sh b/tests/test_led_t3_off.sh new file mode 100644 index 0000000..9825e86 --- /dev/null +++ b/tests/test_led_t3_off.sh @@ -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 + diff --git a/tests/test_led_t3_red.sh b/tests/test_led_t3_red.sh new file mode 100644 index 0000000..8d74bdb --- /dev/null +++ b/tests/test_led_t3_red.sh @@ -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 + diff --git a/tests/test_led_throttle_off.sh b/tests/test_led_throttle_off.sh new file mode 100644 index 0000000..be11458 --- /dev/null +++ b/tests/test_led_throttle_off.sh @@ -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 + diff --git a/tests/test_led_throttle_on.sh b/tests/test_led_throttle_on.sh new file mode 100644 index 0000000..afc630a --- /dev/null +++ b/tests/test_led_throttle_on.sh @@ -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 + diff --git a/tests/test_skip.sh b/tests/test_skip.sh new file mode 100644 index 0000000..f0e8497 --- /dev/null +++ b/tests/test_skip.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Test the LED Fire button + +source $(dirname $0)/common_infra.sh + +exit $EXIT_SKIP diff --git a/utils/Makefile.am b/utils/Makefile.am new file mode 100644 index 0000000..a5816ab --- /dev/null +++ b/utils/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = cli test + diff --git a/cli/Makefile.am b/utils/cli/Makefile.am similarity index 83% rename from cli/Makefile.am rename to utils/cli/Makefile.am index 19e7592..7bb6bb3 100644 --- a/cli/Makefile.am +++ b/utils/cli/Makefile.am @@ -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 diff --git a/cli/x52_cli.c b/utils/cli/x52_cli.c similarity index 100% rename from cli/x52_cli.c rename to utils/cli/x52_cli.c diff --git a/cli/x52cli.man b/utils/cli/x52cli.man similarity index 100% rename from cli/x52cli.man rename to utils/cli/x52cli.man diff --git a/test/Makefile.am b/utils/test/Makefile.am similarity index 87% rename from test/Makefile.am rename to utils/test/Makefile.am index 22b8423..ee8dc83 100644 --- a/test/Makefile.am +++ b/utils/test/Makefile.am @@ -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 diff --git a/test/x52_test.c b/utils/test/x52_test.c similarity index 100% rename from test/x52_test.c rename to utils/test/x52_test.c diff --git a/test/x52_test_clock.c b/utils/test/x52_test_clock.c similarity index 100% rename from test/x52_test_clock.c rename to utils/test/x52_test_clock.c diff --git a/test/x52_test_common.h b/utils/test/x52_test_common.h similarity index 100% rename from test/x52_test_common.h rename to utils/test/x52_test_common.h diff --git a/test/x52_test_led.c b/utils/test/x52_test_led.c similarity index 100% rename from test/x52_test_led.c rename to utils/test/x52_test_led.c diff --git a/test/x52_test_mfd.c b/utils/test/x52_test_mfd.c similarity index 100% rename from test/x52_test_mfd.c rename to utils/test/x52_test_mfd.c