diff --git a/.github/scripts/install-dependencies-macos.sh b/.github/scripts/install-dependencies-macos.sh index 3f13107..7fcbcc8 100755 --- a/.github/scripts/install-dependencies-macos.sh +++ b/.github/scripts/install-dependencies-macos.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -x # Install dependencies to build and test on Ubuntu runners brew install \ autoconf \ @@ -11,6 +11,15 @@ brew install \ hidapi \ doxygen \ rsync \ + meson \ cmocka +# inih cannot be installed via Homebrew, install it manually +INIH_VER=r53 +curl -LO https://github.com/benhoyt/inih/archive/refs/tags/${INIH_VER}.tar.gz +tar xvf ${INIH_VER}.tar.gz +cd inih-${INIH_VER} +meson build +meson install -C build + exit 0 diff --git a/.github/scripts/install-dependencies-ubuntu.sh b/.github/scripts/install-dependencies-ubuntu.sh index c0f6c08..487d56d 100755 --- a/.github/scripts/install-dependencies-ubuntu.sh +++ b/.github/scripts/install-dependencies-ubuntu.sh @@ -11,6 +11,7 @@ sudo apt-get install -y \ autopoint \ libusb-1.0-0-dev \ libhidapi-dev \ + libinih-dev \ libevdev-dev \ doxygen \ rsync \ diff --git a/.gitignore b/.gitignore index 9bea998..1c51b6b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,13 @@ a.out utils/cli/x52cli* utils/test/x52test* +utils/evtest/x52evtest* lib/libx52util/util_char_map.c util/x52charmapgen* lib/libusbx52/x52test* +udev/*.rules +daemon/x52d* +!daemon/x52d_*.* x52pro-linux-*.tar.gz # Module files diff --git a/ChangeLog.md b/ChangeLog.md index 7d563da..b091a14 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,8 @@ The format is based upon [Keep a Changelog]. ### Added - IO library to read and parse events from a supported joystick. - Event test utility which displays the events similar to evtest. +- Import pinelog library for daemon logging. +- Daemon to control and update the X52 joystick. ### Changed - Linux kernel driver to correctly handle the X52/X52 Pro. This is not required @@ -20,6 +22,8 @@ The format is based upon [Keep a Changelog]. be used in the actual rules file. This allows systems such as openSUSE which use `input` as the group for input devices to behave the same as Ubuntu and other similar systems. +- Code layout changed to improve parallel builds. +- x52cli tests modified to use cmocka tests. ## [0.2.1] - 2020-06-28 ### Added diff --git a/INSTALL.md b/INSTALL.md index cafa640..b9b5296 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,12 +1,10 @@ Installation instructions for x52pro-linux ========================================== -[![Build Status](https://www.travis-ci.org/nirenjan/x52pro-linux.svg?branch=master)](https://www.travis-ci.org/nirenjan/x52pro-linux) - Build has been tested on the following operating systems (x86-64 only): -* Ubuntu 16.04 LTS * Ubuntu 18.04 LTS +* Ubuntu 20.04 LTS * OS X 10.13.6 # Prerequisites @@ -18,6 +16,7 @@ Build has been tested on the following operating systems (x86-64 only): * autopoint * gettext * hidapi +* [inih](https://github.com/benhoyt/inih) * libtool * libusb-1.0 + headers * pkg-config @@ -27,9 +26,16 @@ Build has been tested on the following operating systems (x86-64 only): | Platform | Install instructions | | -------- | -------------------- | -| Ubuntu | `sudo apt-get install automake autoconf gettext autopoint libhidapi-dev libtool libusb-1.0-0-dev pkg-config python3` | -| MacOS + Homebrew | `brew install automake autoconf gettext hidapi libtool libusb pkg-config python3` | -| Arch Linux | `pacman -S base-devel libusb hidapi python` | +| Ubuntu | `sudo apt-get install automake autoconf gettext autopoint libhidapi-dev libinih-dev libtool libusb-1.0-0-dev pkg-config python3` | +| MacOS + Homebrew | `brew install automake autoconf gettext hidapi libtool libusb meson pkg-config python3` | +| Arch Linux | `pacman -S base-devel libusb hidapi libinih python` | + +On MacOS, `inih` is not available as a Homebrew formula. You need to build and +install it manually using the following steps: + +* Download and extract inih from Github +* From the inih source directory, run `meson build`, then run `meson install -C + build`. ## Optional Packages @@ -39,10 +45,7 @@ the utilities, you will need the following packages: * doxygen * rsync -You will also need the following packages to run the unit tests: - -* faketime -* cmocka +You will also need the `cmocka` package to run the unit tests. # Installation Instructions diff --git a/Makefile.am b/Makefile.am index 2d85255..964852c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,28 +6,44 @@ ACLOCAL_AMFLAGS = -I m4 +# Build any support libraries first +SUBDIRS = lib + if USE_NLS -po_SUBDIRS = po +SUBDIRS += po endif -SUBDIRS = $(po_SUBDIRS) lib utils tests udev +####################################################################### +# Defaults +####################################################################### +bin_PROGRAMS = +check_PROGRAMS = +lib_LTLIBRARIES = +check_LTLIBRARIES = +pkgconfig_DATA = +TESTS = +EXTRA_DIST = +CLEANFILES = -# Extra files that need to be in the distribution -EXTRA_DIST = \ - ABOUT-NLS \ - AUTHORS \ - ChangeLog.md \ - CONTRIBUTING.md \ - Doxyfile.in \ - INSTALL.md \ - LICENSE \ - README.md \ - config.rpath \ - gettext.h \ - usb-ids.h \ - po/README.md +x52includedir = $(includedir)/libx52 +x52include_HEADERS = +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh + +include libx52/Makefile.am +include libx52util/Makefile.am +include libx52io/Makefile.am +include libusbx52/Makefile.am + +include cli/Makefile.am +include joytest/Makefile.am +include evtest/Makefile.am +include daemon/Makefile.am +include udev/Makefile.am + +####################################################################### # Doxygen support +####################################################################### if HAVE_DOXYGEN DXGEN = $(DXGEN_@AM_V@) DXGEN_ = $(DXGEN_@AM_DEFAULT_V@) @@ -53,3 +69,20 @@ uninstall-local: rm -rf $(DESTDIR)$(mandir)/man1/x52cli.1 endif + +# Extra files that need to be in the distribution +EXTRA_DIST += \ + ABOUT-NLS \ + AUTHORS \ + ChangeLog.md \ + CONTRIBUTING.md \ + Doxyfile.in \ + DoxygenLayout.xml \ + INSTALL.md \ + LICENSE \ + README.md \ + config.rpath \ + gettext.h \ + usb-ids.h \ + po/README.md + diff --git a/README.md b/README.md index bff9f94..34547ee 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ for your needs as it provides a graphical interface to control the MFD and LEDs. # Building and installing -See [INSTALL.md](https://github.com/nirenjan/x52pro-linux/blob/master/INSTALL.md) +See [INSTALL.md](INSTALL.md) diff --git a/cli/Makefile.am b/cli/Makefile.am new file mode 100644 index 0000000..ea5c7d1 --- /dev/null +++ b/cli/Makefile.am @@ -0,0 +1,27 @@ +# Automake for x52cli +# +# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + +bin_PROGRAMS += x52cli + +# Command line utility that front ends the core library +x52cli_SOURCES = cli/x52_cli.c +x52cli_CFLAGS = -I $(top_srcdir)/libx52 $(WARN_CFLAGS) +x52cli_LDFLAGS = $(WARN_LDFLAGS) +x52cli_LDADD = libx52.la + +if HAVE_CMOCKA +TESTS += test-cli +check_PROGRAMS += test-cli + +test_cli_SOURCES = cli/x52_cli.c cli/test_x52_cli.c +test_cli_CFLAGS = -DX52_CLI_TESTING -I $(top_srcdir)/libx52 +test_cli_LDFLAGS = @CMOCKA_LIBS@ $(WARN_LDFLAGS) + +# Add a dependency on test_x52_cli_tests.c +cli/test_x52_cli.c: cli/test_x52_cli_tests.c +endif + +EXTRA_DIST += cli/test_x52_cli_tests.c diff --git a/cli/test_x52_cli.c b/cli/test_x52_cli.c new file mode 100644 index 0000000..2fdb800 --- /dev/null +++ b/cli/test_x52_cli.c @@ -0,0 +1,177 @@ +/* + * Saitek X52 Pro MFD & LED driver - CLI test harness + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include +#include +#include +#include +#include + +#include "libx52.h" + +extern int run_main(int argc, char **argv); + +/* Wrapper functions for libx52 */ +int libx52_init(libx52_device **dev) +{ + *dev = NULL; + return LIBX52_SUCCESS; +} + +int libx52_connect(libx52_device *dev) +{ + return LIBX52_SUCCESS; +} + +int libx52_update(libx52_device *dev) +{ + return LIBX52_SUCCESS; +} + +void libx52_exit(libx52_device *dev) +{ +} + +const char *libx52_strerror(libx52_error_code rc) +{ + return ""; +} + +int libx52_set_text(libx52_device *x52, uint8_t line, const char *text, uint8_t length) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(line); + check_expected(text); + check_expected(length); + + return mock(); +} + +int libx52_set_led_state(libx52_device *x52, libx52_led_id id, libx52_led_state state) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(id); + check_expected(state); + + return mock(); +} + +int libx52_set_clock(libx52_device *x52, time_t time, int local) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(time); + check_expected(local); + + return mock(); +} + +int libx52_set_clock_timezone(libx52_device *x52, libx52_clock_id clock, int offset) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(clock); + check_expected(offset); + + return mock(); +} + +int libx52_set_clock_format(libx52_device *x52, libx52_clock_id clock, libx52_clock_format format) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(clock); + check_expected(format); + + return mock(); +} + +int libx52_set_time(libx52_device *x52, uint8_t hour, uint8_t minute) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(hour); + check_expected(minute); + + return mock(); +} + +int libx52_set_date(libx52_device *x52, uint8_t dd, uint8_t mm, uint8_t yy) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(dd); + check_expected(mm); + check_expected(yy); + + return mock(); +} + +int libx52_set_date_format(libx52_device *x52, libx52_date_format format) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(format); + + return mock(); +} + +int libx52_set_brightness(libx52_device *x52, uint8_t mfd, uint16_t brightness) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(mfd); + check_expected(brightness); + + return mock(); +} + +int libx52_set_shift(libx52_device *x52, uint8_t state) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(state); + + return mock(); +} + +int libx52_set_blink(libx52_device *x52, uint8_t state) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(state); + + return mock(); +} + +int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value) +{ + function_called(); + assert_ptr_equal(x52, NULL); + check_expected(index); + check_expected(value); + + return mock(); +} + +#include "test_x52_cli_tests.c" +#define TEST_LIST + +const struct CMUnitTest tests[] = { + #include "test_x52_cli_tests.c" +}; + +int main(int argc, char **argv) +{ + cmocka_set_message_output(CM_OUTPUT_TAP); + cmocka_run_group_tests(tests, NULL, NULL); + return 0; +} + diff --git a/cli/test_x52_cli_tests.c b/cli/test_x52_cli_tests.c new file mode 100644 index 0000000..f86d00c --- /dev/null +++ b/cli/test_x52_cli_tests.c @@ -0,0 +1,1401 @@ +/* + * Saitek X52 Pro MFD & LED driver - CLI test suite + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#ifndef TEST_LIST +// Setup the test case function +#define TEST_CASE(tc) static void tc(void **state) +#define TEST_DEF 1 +// Function header, this calls the corresponding libx52 function, and expects +// a certain number of calls to that function +#define SETUP(...) \ + int rc; \ + char *argv[] = {"x52cli", __VA_ARGS__}; + +#define FUNC(fn, count) \ + expect_function_calls(libx52_ ## fn, count); \ + will_return_count(libx52_ ## fn, LIBX52_SUCCESS, count); + +#define EXPECT(fn, param, value) expect_value(libx52_ ## fn, param, value); +#define EXPECT_STRING(fn, param, value) expect_string(libx52_ ##fn, param, value); +#define FINISH() \ + rc = run_main(sizeof(argv)/sizeof(argv[0]), argv); \ + assert_int_equal(rc, LIBX52_SUCCESS); + +#else // !defined TEST_LIST +#define TEST_CASE(tc) cmocka_unit_test(tc), +#define TEST_DEF 0 +#endif // defined TEST_LIST + +/* LED test cases {{{ */ +TEST_CASE(led_fire_off) +#if TEST_DEF +{ + SETUP("led", "fire", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_FIRE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_fire_on) +#if TEST_DEF +{ + SETUP("led", "fire", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_FIRE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_fire_red) +#if TEST_DEF +{ + SETUP("led", "fire", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_FIRE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_fire_amber) +#if TEST_DEF +{ + SETUP("led", "fire", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_FIRE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_fire_green) +#if TEST_DEF +{ + SETUP("led", "fire", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_FIRE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_a_off) +#if TEST_DEF +{ + SETUP("led", "a", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_A) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_a_on) +#if TEST_DEF +{ + SETUP("led", "a", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_A) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_a_red) +#if TEST_DEF +{ + SETUP("led", "a", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_A) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_a_amber) +#if TEST_DEF +{ + SETUP("led", "a", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_A) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_a_green) +#if TEST_DEF +{ + SETUP("led", "a", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_A) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_b_off) +#if TEST_DEF +{ + SETUP("led", "b", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_B) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_b_on) +#if TEST_DEF +{ + SETUP("led", "b", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_B) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_b_red) +#if TEST_DEF +{ + SETUP("led", "b", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_B) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_b_amber) +#if TEST_DEF +{ + SETUP("led", "b", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_B) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_b_green) +#if TEST_DEF +{ + SETUP("led", "b", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_B) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_d_off) +#if TEST_DEF +{ + SETUP("led", "d", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_D) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_d_on) +#if TEST_DEF +{ + SETUP("led", "d", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_D) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_d_red) +#if TEST_DEF +{ + SETUP("led", "d", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_D) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_d_amber) +#if TEST_DEF +{ + SETUP("led", "d", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_D) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_d_green) +#if TEST_DEF +{ + SETUP("led", "d", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_D) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_e_off) +#if TEST_DEF +{ + SETUP("led", "e", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_E) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_e_on) +#if TEST_DEF +{ + SETUP("led", "e", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_E) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_e_red) +#if TEST_DEF +{ + SETUP("led", "e", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_E) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_e_amber) +#if TEST_DEF +{ + SETUP("led", "e", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_E) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_e_green) +#if TEST_DEF +{ + SETUP("led", "e", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_E) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_t1_off) +#if TEST_DEF +{ + SETUP("led", "t1", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T1) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_t1_on) +#if TEST_DEF +{ + SETUP("led", "t1", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T1) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_t1_red) +#if TEST_DEF +{ + SETUP("led", "t1", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T1) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_t1_amber) +#if TEST_DEF +{ + SETUP("led", "t1", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T1) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_t1_green) +#if TEST_DEF +{ + SETUP("led", "t1", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T1) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_t2_off) +#if TEST_DEF +{ + SETUP("led", "t2", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T2) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_t2_on) +#if TEST_DEF +{ + SETUP("led", "t2", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T2) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_t2_red) +#if TEST_DEF +{ + SETUP("led", "t2", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T2) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_t2_amber) +#if TEST_DEF +{ + SETUP("led", "t2", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T2) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_t2_green) +#if TEST_DEF +{ + SETUP("led", "t2", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T2) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_t3_off) +#if TEST_DEF +{ + SETUP("led", "t3", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T3) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_t3_on) +#if TEST_DEF +{ + SETUP("led", "t3", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T3) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_t3_red) +#if TEST_DEF +{ + SETUP("led", "t3", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T3) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_t3_amber) +#if TEST_DEF +{ + SETUP("led", "t3", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T3) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_t3_green) +#if TEST_DEF +{ + SETUP("led", "t3", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_T3) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_pov_off) +#if TEST_DEF +{ + SETUP("led", "pov", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_POV) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_pov_on) +#if TEST_DEF +{ + SETUP("led", "pov", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_POV) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_pov_red) +#if TEST_DEF +{ + SETUP("led", "pov", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_POV) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_pov_amber) +#if TEST_DEF +{ + SETUP("led", "pov", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_POV) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_pov_green) +#if TEST_DEF +{ + SETUP("led", "pov", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_POV) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +TEST_CASE(led_throttle_off) +#if TEST_DEF +{ + SETUP("led", "throttle", "off") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_THROTTLE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_OFF) + FINISH() +} +#endif + +TEST_CASE(led_throttle_on) +#if TEST_DEF +{ + SETUP("led", "throttle", "on") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_THROTTLE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_ON) + FINISH() +} +#endif + +TEST_CASE(led_throttle_red) +#if TEST_DEF +{ + SETUP("led", "throttle", "red") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_THROTTLE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_RED) + FINISH() +} +#endif + +TEST_CASE(led_throttle_amber) +#if TEST_DEF +{ + SETUP("led", "throttle", "amber") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_THROTTLE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_AMBER) + FINISH() +} +#endif + +TEST_CASE(led_throttle_green) +#if TEST_DEF +{ + SETUP("led", "throttle", "green") + FUNC(set_led_state, 1) + EXPECT(set_led_state, id, LIBX52_LED_THROTTLE) + EXPECT(set_led_state, state, LIBX52_LED_STATE_GREEN) + FINISH() +} +#endif + +/* }}} */ + +/* Brightness test cases {{{ */ +TEST_CASE(brightness_mfd_0) +#if TEST_DEF +{ + SETUP("bri", "mfd", "0") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 0) + FINISH() +} +#endif + +TEST_CASE(brightness_mfd_1) +#if TEST_DEF +{ + SETUP("bri", "mfd", "1") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 1) + FINISH() +} +#endif + +TEST_CASE(brightness_mfd_2) +#if TEST_DEF +{ + SETUP("bri", "mfd", "2") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 2) + FINISH() +} +#endif + +TEST_CASE(brightness_mfd_126) +#if TEST_DEF +{ + SETUP("bri", "mfd", "126") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 126) + FINISH() +} +#endif + +TEST_CASE(brightness_mfd_127) +#if TEST_DEF +{ + SETUP("bri", "mfd", "127") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 127) + FINISH() +} +#endif + +TEST_CASE(brightness_mfd_128) +#if TEST_DEF +{ + SETUP("bri", "mfd", "128") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 1) + EXPECT(set_brightness, brightness, 128) + FINISH() +} +#endif + +TEST_CASE(brightness_led_0) +#if TEST_DEF +{ + SETUP("bri", "led", "0") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 0) + FINISH() +} +#endif + +TEST_CASE(brightness_led_1) +#if TEST_DEF +{ + SETUP("bri", "led", "1") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 1) + FINISH() +} +#endif + +TEST_CASE(brightness_led_2) +#if TEST_DEF +{ + SETUP("bri", "led", "2") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 2) + FINISH() +} +#endif + +TEST_CASE(brightness_led_126) +#if TEST_DEF +{ + SETUP("bri", "led", "126") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 126) + FINISH() +} +#endif + +TEST_CASE(brightness_led_127) +#if TEST_DEF +{ + SETUP("bri", "led", "127") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 127) + FINISH() +} +#endif + +TEST_CASE(brightness_led_128) +#if TEST_DEF +{ + SETUP("bri", "led", "128") + FUNC(set_brightness, 1) + EXPECT(set_brightness, mfd, 0) + EXPECT(set_brightness, brightness, 128) + FINISH() +} +#endif + +/* }}} */ + +/* Indicator test cases {{{ */ +TEST_CASE(indicator_blink_on) +#if TEST_DEF +{ + SETUP("blink", "on") + FUNC(set_blink, 1) + EXPECT(set_blink, state, 1) + FINISH() +} +#endif + +TEST_CASE(indicator_blink_off) +#if TEST_DEF +{ + SETUP("blink", "off") + FUNC(set_blink, 1) + EXPECT(set_blink, state, 0) + FINISH() +} +#endif + +TEST_CASE(indicator_shift_on) +#if TEST_DEF +{ + SETUP("shift", "on") + FUNC(set_shift, 1) + EXPECT(set_shift, state, 1) + FINISH() +} +#endif + +TEST_CASE(indicator_shift_off) +#if TEST_DEF +{ + SETUP("shift", "off") + FUNC(set_shift, 1) + EXPECT(set_shift, state, 0) + FINISH() +} +#endif + +/* }}} */ + +/* MFD text tests {{{ */ +TEST_CASE(mfd_0_1) +#if TEST_DEF +{ + SETUP("mfd", "0", "a") + FUNC(set_text, 1) + EXPECT(set_text, line, 0) + EXPECT_STRING(set_text, text, "a") + EXPECT(set_text, length, 1) + FINISH() +} +#endif + +TEST_CASE(mfd_0_2) +#if TEST_DEF +{ + SETUP("mfd", "0", "ab") + FUNC(set_text, 1) + EXPECT(set_text, line, 0) + EXPECT_STRING(set_text, text, "ab") + EXPECT(set_text, length, 2) + FINISH() +} +#endif + +TEST_CASE(mfd_1_1) +#if TEST_DEF +{ + SETUP("mfd", "1", "a") + FUNC(set_text, 1) + EXPECT(set_text, line, 1) + EXPECT_STRING(set_text, text, "a") + EXPECT(set_text, length, 1) + FINISH() +} +#endif + +TEST_CASE(mfd_1_2) +#if TEST_DEF +{ + SETUP("mfd", "1", "ab") + FUNC(set_text, 1) + EXPECT(set_text, line, 1) + EXPECT_STRING(set_text, text, "ab") + EXPECT(set_text, length, 2) + FINISH() +} +#endif + +TEST_CASE(mfd_2_1) +#if TEST_DEF +{ + SETUP("mfd", "2", "a") + FUNC(set_text, 1) + EXPECT(set_text, line, 2) + EXPECT_STRING(set_text, text, "a") + EXPECT(set_text, length, 1) + FINISH() +} +#endif + +TEST_CASE(mfd_2_2) +#if TEST_DEF +{ + SETUP("mfd", "2", "ab") + FUNC(set_text, 1) + EXPECT(set_text, line, 2) + EXPECT_STRING(set_text, text, "ab") + EXPECT(set_text, length, 2) + FINISH() +} +#endif + +/* }}} */ + +/* Clock tests {{{ */ +TEST_CASE(clock_local_12hr_ddmmyy) +#if TEST_DEF +{ + SETUP("clock", "local", "12hr", "ddmmyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_DDMMYY) + FINISH() +} +#endif + +TEST_CASE(clock_local_12hr_mmddyy) +#if TEST_DEF +{ + SETUP("clock", "local", "12hr", "mmddyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_MMDDYY) + FINISH() +} +#endif + +TEST_CASE(clock_local_12hr_yymmdd) +#if TEST_DEF +{ + SETUP("clock", "local", "12hr", "yymmdd") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_YYMMDD) + FINISH() +} +#endif + +TEST_CASE(clock_local_24hr_ddmmyy) +#if TEST_DEF +{ + SETUP("clock", "local", "24hr", "ddmmyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_DDMMYY) + FINISH() +} +#endif + +TEST_CASE(clock_local_24hr_mmddyy) +#if TEST_DEF +{ + SETUP("clock", "local", "24hr", "mmddyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_MMDDYY) + FINISH() +} +#endif + +TEST_CASE(clock_local_24hr_yymmdd) +#if TEST_DEF +{ + SETUP("clock", "local", "24hr", "yymmdd") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 1) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_YYMMDD) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_12hr_ddmmyy) +#if TEST_DEF +{ + SETUP("clock", "gmt", "12hr", "ddmmyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_DDMMYY) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_12hr_mmddyy) +#if TEST_DEF +{ + SETUP("clock", "gmt", "12hr", "mmddyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_MMDDYY) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_12hr_yymmdd) +#if TEST_DEF +{ + SETUP("clock", "gmt", "12hr", "yymmdd") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_YYMMDD) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_24hr_ddmmyy) +#if TEST_DEF +{ + SETUP("clock", "gmt", "24hr", "ddmmyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_DDMMYY) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_24hr_mmddyy) +#if TEST_DEF +{ + SETUP("clock", "gmt", "24hr", "mmddyy") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_MMDDYY) + FINISH() +} +#endif + +TEST_CASE(clock_gmt_24hr_yymmdd) +#if TEST_DEF +{ + SETUP("clock", "gmt", "24hr", "yymmdd") + FUNC(set_clock, 1) + EXPECT(set_clock, local, 0) + EXPECT(set_clock, time, time(NULL)) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_YYMMDD) + FINISH() +} +#endif +/* }}} */ + +/* Clock offset tests {{{ */ +TEST_CASE(offset_2__30_12hr) +#if TEST_DEF +{ + SETUP("offset", "2", "-30", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, -30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_2__30_24hr) +#if TEST_DEF +{ + SETUP("offset", "2", "-30", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, -30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(offset_2_0_12hr) +#if TEST_DEF +{ + SETUP("offset", "2", "0", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_2_0_24hr) +#if TEST_DEF +{ + SETUP("offset", "2", "0", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(offset_2_30_12hr) +#if TEST_DEF +{ + SETUP("offset", "2", "30", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, 30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_2_30_24hr) +#if TEST_DEF +{ + SETUP("offset", "2", "30", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_timezone, offset, 30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_2) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(offset_3__30_12hr) +#if TEST_DEF +{ + SETUP("offset", "3", "-30", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, -30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_3__30_24hr) +#if TEST_DEF +{ + SETUP("offset", "3", "-30", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, -30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(offset_3_0_12hr) +#if TEST_DEF +{ + SETUP("offset", "3", "0", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_3_0_24hr) +#if TEST_DEF +{ + SETUP("offset", "3", "0", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(offset_3_30_12hr) +#if TEST_DEF +{ + SETUP("offset", "3", "30", "12hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, 30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(offset_3_30_24hr) +#if TEST_DEF +{ + SETUP("offset", "3", "30", "24hr") + FUNC(set_clock_timezone, 1) + EXPECT(set_clock_timezone, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_timezone, offset, 30) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_3) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +/* }}} */ + +/* Raw time tests {{{ */ +TEST_CASE(raw_time_0_0_12hr) +#if TEST_DEF +{ + SETUP("time", "0", "0", "12hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 0) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_0_0_24hr) +#if TEST_DEF +{ + SETUP("time", "0", "0", "24hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 0) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_0_1_12hr) +#if TEST_DEF +{ + SETUP("time", "0", "1", "12hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 0) + EXPECT(set_time, minute, 1) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_0_1_24hr) +#if TEST_DEF +{ + SETUP("time", "0", "1", "24hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 0) + EXPECT(set_time, minute, 1) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_1_0_12hr) +#if TEST_DEF +{ + SETUP("time", "1", "0", "12hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 1) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_1_0_24hr) +#if TEST_DEF +{ + SETUP("time", "1", "0", "24hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 1) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_2_0_12hr) +#if TEST_DEF +{ + SETUP("time", "2", "0", "12hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 2) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_12HR) + FINISH() +} +#endif + +TEST_CASE(raw_time_2_0_24hr) +#if TEST_DEF +{ + SETUP("time", "2", "0", "24hr") + FUNC(set_time, 1) + EXPECT(set_time, hour, 2) + EXPECT(set_time, minute, 0) + FUNC(set_clock_format, 1) + EXPECT(set_clock_format, clock, LIBX52_CLOCK_1) + EXPECT(set_clock_format, format, LIBX52_CLOCK_FORMAT_24HR) + FINISH() +} +#endif + +/* }}} */ + +/* Raw date tests {{{ */ +TEST_CASE(raw_date_ddmmyy) +#if TEST_DEF +{ + SETUP("date", "1", "2", "3", "ddmmyy") + FUNC(set_date, 1) + EXPECT(set_date, dd, 1) + EXPECT(set_date, mm, 2) + EXPECT(set_date, yy, 3) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_DDMMYY) + FINISH() +} +#endif + +TEST_CASE(raw_date_mmddyy) +#if TEST_DEF +{ + SETUP("date", "1", "2", "3", "mmddyy") + FUNC(set_date, 1) + EXPECT(set_date, dd, 1) + EXPECT(set_date, mm, 2) + EXPECT(set_date, yy, 3) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_MMDDYY) + FINISH() +} +#endif + +TEST_CASE(raw_date_yymmdd) +#if TEST_DEF +{ + SETUP("date", "1", "2", "3", "yymmdd") + FUNC(set_date, 1) + EXPECT(set_date, dd, 1) + EXPECT(set_date, mm, 2) + EXPECT(set_date, yy, 3) + FUNC(set_date_format, 1) + EXPECT(set_date_format, format, LIBX52_DATE_FORMAT_YYMMDD) + FINISH() +} +#endif +/* }}} */ + +/* Vendor command tests {{{ */ +TEST_CASE(vendor_command_hex) +#if TEST_DEF +{ + SETUP("raw", "0x0123", "0x4567") + FUNC(vendor_command, 1) + EXPECT(vendor_command, index, 0x0123) + EXPECT(vendor_command, value, 0x4567) + FINISH() +} +#endif + +TEST_CASE(vendor_command_oct) +#if TEST_DEF +{ + SETUP("raw", "0123", "0456") + FUNC(vendor_command, 1) + EXPECT(vendor_command, index, 0123) + EXPECT(vendor_command, value, 0456) + FINISH() +} +#endif + +TEST_CASE(vendor_command_dec) +#if TEST_DEF +{ + SETUP("raw", "123", "456") + FUNC(vendor_command, 1) + EXPECT(vendor_command, index, 123) + EXPECT(vendor_command, value, 456) + FINISH() +} +#endif + +/* }}} */ + +#undef TEST_CASE +#undef TEST_DEF diff --git a/utils/cli/x52_cli.c b/cli/x52_cli.c similarity index 99% rename from utils/cli/x52_cli.c rename to cli/x52_cli.c index 0dcb210..467d291 100644 --- a/utils/cli/x52_cli.c +++ b/cli/x52_cli.c @@ -1,7 +1,7 @@ /* * Saitek X52 Pro MFD & LED driver * - * Copyright (C) 2015 Nirenjan Krishnan (nirenjan@nirenjan.org) + * Copyright (C) 2015-2021 Nirenjan Krishnan (nirenjan@nirenjan.org) * * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 */ @@ -469,7 +469,11 @@ static void do_help(const struct command_handler *cmd) } } +#ifdef X52_CLI_TESTING +int run_main(int argc, char **argv) +#else int main(int argc, char **argv) +#endif { libx52_device *x52; struct string_map result; diff --git a/configure.ac b/configure.ac index f78f977..fa78dad 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ # Autoconf settings for x52pro-linux # -# Copyright (C) 2012-2020 Nirenjan Krishnan (nirenjan@nirenjan.org) +# Copyright (C) 2012-2021 Nirenjan Krishnan (nirenjan@nirenjan.org) # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -AC_INIT([x52pro-linux], [0.2.1], [nirenjan@gmail.com]) +AC_INIT([x52pro-linux], [0.2.2], [nirenjan@gmail.com]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) AC_REQUIRE_AUX_FILE([tap-driver.sh]) @@ -18,6 +18,11 @@ PKG_PROG_PKG_CONFIG PKG_INSTALLDIR AX_COMPILER_FLAGS AC_CANONICAL_HOST +AX_GCC_FUNC_ATTRIBUTE([constructor]) +AX_GCC_FUNC_ATTRIBUTE([destructor]) +AX_GCC_FUNC_ATTRIBUTE([format]) +AX_GCC_FUNC_ATTRIBUTE([noreturn]) +AC_C_TYPEOF AC_MSG_NOTICE([Detected host OS is ${host_os}]) build_linux=no @@ -31,7 +36,7 @@ AM_CONDITIONAL([LINUX], [test "x${build_linux}" = "xyes"]) # Internationalization AM_GNU_GETTEXT([external]) -AM_GNU_GETTEXT_VERSION(0.18) +AM_GNU_GETTEXT_VERSION(0.19) AM_CONDITIONAL([USE_NLS], [test "x${USE_NLS}" == "xyes"]) # Check for libusb-1.0 @@ -41,13 +46,25 @@ AC_SUBST([LIBUSB_CFLAGS]) AC_SUBST([LIBUSB_LDFLAGS]) AC_SUBST([LIBUSB_LIBS]) -AC_SUBST([X52_PKG_VERSION], [0.1]) -AC_SUBST([X52_INCLUDE], ["-I \$(top_srcdir)/lib/libx52"]) +# Check for libinih +PKG_CHECK_MODULES([INIH], [inih], [], + [ + # Older versions of Ubuntu don't provide a .pc file + AC_CHECK_HEADERS([ini.h]) + AC_SEARCH_LIBS([ini_parse], [inih]) + ]) +AC_SUBST([INIH_CFLAGS]) +AC_SUBST([INIH_LDFLAGS]) +AC_SUBST([INIH_LIBS]) + +# Pinelog configuration +AC_SUBST([PINELOG_CFLAGS], ["-DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1"]) + # Check for hidapi. This uses a different pkg-config file on Linux vs other # hosts, so check accordingly AM_COND_IF([LINUX], [hidapi_backend=hidapi-hidraw], [hidapi_backend=hidapi]) -AX_PKG_CHECK_MODULES([HIDAPI], [${hidapi_backend}]) +PKG_CHECK_MODULES([HIDAPI], [${hidapi_backend}]) AC_SUBST([HIDAPI_CFLAGS]) AC_SUBST([HIDAPI_LDFLAGS]) AC_SUBST([HIDAPI_LIBS]) @@ -66,7 +83,7 @@ AC_MSG_CHECKING([final decision IS_MAKE_DISTCHECK (running "make distcheck"?)]) AM_COND_IF([IS_MAKE_DISTCHECK], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) # udev support -AX_PKG_CHECK_MODULES([UDEV], [udev], [], [have_udev=yes], [have_udev=no]) +PKG_CHECK_MODULES([UDEV], [udev], [have_udev=yes], [have_udev=no]) AM_CONDITIONAL([HAVE_UDEV], [test "x$have_udev" = xyes]) AC_ARG_WITH([udevrulesdir], AS_HELP_STRING([--with-udevrulesdir=DIR], [Directory for udev rules]), @@ -88,7 +105,7 @@ AM_COND_IF([HAVE_DOXYGEN], [AC_MSG_WARN(["Doxygen not found; continuing without doxygen support"])]) # cmocka unit tests -AX_PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1], [], [have_cmocka=yes], [have_cmocka=no]) +PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1], [have_cmocka=yes], [have_cmocka=no]) AM_CONDITIONAL([HAVE_CMOCKA], [test "x$have_cmocka" = xyes]) AM_COND_IF([HAVE_CMOCKA], [], [AC_MSG_WARN(["cmocka not found; disabling unit test build"])]) @@ -107,17 +124,8 @@ AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([ po/Makefile.in Makefile lib/Makefile - lib/libx52/Makefile - lib/libx52/libx52.pc - lib/libusbx52/Makefile - lib/libx52util/Makefile - lib/libx52io/Makefile - udev/Makefile + libx52/libx52.pc + lib/pinelog/Makefile udev/60-saitek-x52-x52pro.rules - utils/Makefile - utils/cli/Makefile - utils/test/Makefile - utils/evtest/Makefile - tests/Makefile ]) AC_OUTPUT diff --git a/daemon/Makefile.am b/daemon/Makefile.am new file mode 100644 index 0000000..81fa1f4 --- /dev/null +++ b/daemon/Makefile.am @@ -0,0 +1,44 @@ +# Automake for x52d +# +# Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 +bin_PROGRAMS += x52d + +# Service daemon that manages the X52 device +x52d_SOURCES = \ + daemon/x52d_main.c \ + daemon/x52d_config_parser.c \ + daemon/x52d_config.c \ + daemon/x52d_device.c \ + daemon/x52d_clock.c \ + daemon/x52d_led.c + +x52d_CFLAGS = \ + -I $(top_srcdir) \ + -I $(top_srcdir)/libx52io \ + -I $(top_srcdir)/libx52 \ + -I $(top_srcdir)/libx52util \ + -I $(top_srcdir)/lib/pinelog \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ + -DLOCALEDIR=\"$(localedir)\" \ + -DLOGDIR=\"$(localstatedir)/log\" \ + -DRUNDIR=\"$(runstatedir)\" \ + @INIH_CFLAGS@ @PTHREAD_CFLAGS@ $(WARN_CFLAGS) + +x52d_LDFLAGS = @INIH_LIBS@ @PTHREAD_LIBS@ $(WARN_LDFLAGS) +x52d_LDADD = \ + lib/pinelog/libpinelog.la \ + libx52.la \ + @LTLIBINTL@ + +x52dconfdir = @sysconfdir@/x52d +x52dconf_DATA = daemon/x52d.conf + +EXTRA_DIST += \ + daemon/x52d_clock.h \ + daemon/x52d_config.def \ + daemon/x52d_config.h \ + daemon/x52d_const.h \ + daemon/x52d_device.h \ + daemon/x52d.conf diff --git a/daemon/x52d.conf b/daemon/x52d.conf new file mode 100644 index 0000000..b1f44ea --- /dev/null +++ b/daemon/x52d.conf @@ -0,0 +1,97 @@ +####################################################################### +# X52 Daemon Configuration +###################################################################### + +# The settings below are the defaults. Note that the section and key +# strings are case insensitive, but the values are not necessarily so, +# especially for those referring to paths or timezone names. + +###################################################################### +# Clock Settings +###################################################################### +[Clock] + +# Enabled controls whether the clock is enabled or not. Set this to no to +# disable the clock update. Keep in mind that if the clock was originally +# enabled on the X52, then disabling it here won't make the clock disappear on +# the MFD. You will need to unplug and reattach the X52 to make the clock +# disappear +Enabled=yes + +# PrimaryIsLocal controls whether the primary clock displays local time or UTC. +# Set this to yes to display local time, no for UTC. +PrimaryIsLocal=yes + +# Secondary controls the timezone of the secondary clock. Use the standard +# timezone name as defined by the Olson time database. +Secondary=UTC + +# Tertiary controls the timezone of the tertiary clock. Use the standard +# timezone name as defined by the Olson time database. +Tertiary=UTC + +# PrimaryFormat controls the clock format of the primary clock. This is +# either 12hr or 24hr, and can be abbreviated to 12 or 24 +FormatPrimary=12hr + +# SecondaryFormat controls the clock format of the secondary clock. This is +# either 12hr or 24hr, and can be abbreviated to 12 or 24 +FormatSecondary=12hr + +# TertiaryFormat controls the clock format of the tertiary clock. This is +# either 12hr or 24hr, and can be abbreviated to 12 or 24 +FormatTertiary=12hr + +# DateFormat controls the format of the date display. This can be one of +# ddmmyy, mmddyy or yymmdd. Alternate representations of these are +# dd-mm-yy, mm-dd-yy or yy-mm-dd respectively. +DateFormat=ddmmyy + +###################################################################### +# LED Settings - only applicable to X52Pro +###################################################################### +[LED] + +# The LED settings map a color code or state to the corresponding LED. +Fire=on +Throttle=on +A=green +B=green +D=green +E=green +T1=green +T2=green +T3=green +POV=green +Clutch=green + +###################################################################### +# Brightness Settings +###################################################################### +[Brightness] + +# The brightness settings map the brightness value to the LEDs/MFD. +MFD=128 +LED=128 + +###################################################################### +# Profiles - only valid on Linux +###################################################################### +[Profiles] + +# Directory is the location of the folder containing the individual profiles. +Directory=/etc/x52d/profiles.d + +# ClutchEnabled determines if the clutch button is treated specially +ClutchEnabled=no + +# ClutchLatched controls if the clutch button (if enabled) is a latched button +# (press once to enter clutch mode, press again to exit clutch mode), or must +# be held down to remain in clutch mode. +ClutchLatched=no + +################## +#X52 Input Servic# +#Version 0.2.2 # +#OS: Linux # +################## diff --git a/daemon/x52d_clock.c b/daemon/x52d_clock.c new file mode 100644 index 0000000..0958502 --- /dev/null +++ b/daemon/x52d_clock.c @@ -0,0 +1,202 @@ +/* + * Saitek X52 Pro MFD & LED driver - Clock manager + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include +#include +#include +#include + +#include "pinelog.h" +#include "x52d_config.h" +#include "x52d_clock.h" +#include "x52d_const.h" +#include "x52d_device.h" + +static bool clock_enabled = false; +static int clock_primary_is_local = false; + +void x52d_cfg_set_Clock_Enabled(bool enabled) +{ + PINELOG_DEBUG(_("Setting clock enable to %s"), + enabled ? _("on") : _("off")); + clock_enabled = enabled; +} + +void x52d_cfg_set_Clock_PrimaryIsLocal(bool param) +{ + PINELOG_DEBUG(_("Setting %s clock timezone to %s"), + libx52_clock_id_to_str(LIBX52_CLOCK_1), + param ? _("local") : _("UTC")); + clock_primary_is_local = !!param; +} + +static int get_tz_offset(const char *tz) +{ + char *orig_tz = NULL; + char *orig_tz_copy = NULL; + time_t t; + struct tm *timeval; + char *new_tz = NULL; + size_t new_tz_len; + int offset = 0; + + new_tz_len = strlen(tz) + 2; + new_tz = malloc(new_tz_len); + if (new_tz == NULL) { + PINELOG_WARN(_("Unable to allocate memory for timezone. Falling back to UTC")); + goto cleanup; + } + snprintf(new_tz, new_tz_len, ":%s", tz); + + orig_tz = getenv("TZ"); + if (orig_tz != NULL) { + /* TZ was set in the environment */ + orig_tz_copy = strdup(orig_tz); + if (orig_tz_copy == NULL) { + PINELOG_WARN(_("Unable to backup timezone environment. Falling back to UTC")); + goto cleanup; + } + } + + setenv("TZ", new_tz, true); + t = time(NULL); + timeval = localtime(&t); + if (timeval != NULL) { + #if HAVE_STRUCT_TM_TM_GMTOFF + /* If valid, then timeval.tm_gmtoff contains the offset in seconds east + * of GMT. Divide by 60 to get the offset in minutes east of GMT. + */ + offset = (int)(timeval->tm_gmtoff / 60); + #else + /* The compiler does not provide tm_gmtoff. Fallback to using the + * timezone variable, which is in seconds west of GMT. Divide by -60 to + * get the offset in minutes east of GMT. + * + * ============ + * XXX NOTE XXX + * ============ + * timezone is always the default (non-summer) timezone offset from GMT. + * Therefore, this may not be accurate during the summer time months + * for the region in question. + */ + offset = (int)(timezone / -60); + #endif + } + +cleanup: + if (orig_tz == NULL) { + unsetenv("TZ"); + } else { + setenv("TZ", orig_tz_copy, true); + free(orig_tz_copy); + } + + if (new_tz != NULL) { + free(new_tz); + } + + tzset(); + PINELOG_TRACE("Offset for timezone '%s' is %d", tz, offset); + return offset; +} + +static void set_clock_offset(libx52_clock_id id, const char *param) +{ + PINELOG_DEBUG(_("Setting %s clock timezone to %s"), + libx52_clock_id_to_str(id), param); + x52d_dev_set_clock_timezone(id, get_tz_offset(param)); +} + +void x52d_cfg_set_Clock_Secondary(char* param) +{ + set_clock_offset(LIBX52_CLOCK_2, param); +} + +void x52d_cfg_set_Clock_Tertiary(char* param) +{ + set_clock_offset(LIBX52_CLOCK_3, param); +} + +static void set_clock_format(libx52_clock_id id, libx52_clock_format fmt) +{ + PINELOG_DEBUG(_("Setting %s clock format to %s"), + libx52_clock_id_to_str(id), libx52_clock_format_to_str(fmt)); + x52d_dev_set_clock_format(id, fmt); +} + +void x52d_cfg_set_Clock_FormatPrimary(libx52_clock_format fmt) +{ + set_clock_format(LIBX52_CLOCK_1, fmt); +} + +void x52d_cfg_set_Clock_FormatSecondary(libx52_clock_format fmt) +{ + set_clock_format(LIBX52_CLOCK_2, fmt); +} + +void x52d_cfg_set_Clock_FormatTertiary(libx52_clock_format fmt) +{ + set_clock_format(LIBX52_CLOCK_3, fmt); +} + +void x52d_cfg_set_Clock_DateFormat(libx52_date_format fmt) +{ + PINELOG_DEBUG(_("Setting date format to %s"), libx52_date_format_to_str(fmt)); + x52d_dev_set_date_format(fmt); +} + +static pthread_t clock_thr; + +static void * x52_clock_thr(void *param) +{ + int rc; + + PINELOG_INFO(_("Starting X52 clock manager thread")); + for (;;) { + time_t cur_time; + + sleep(1); + if (!clock_enabled) { + /* Clock thread is disabled, check again next time */ + continue; + } + + if (time(&cur_time) < 0) { + PINELOG_WARN(_("Error %d retrieving current time: %s"), + errno, strerror(errno)); + continue; + } + rc = x52d_dev_set_clock(cur_time, clock_primary_is_local); + if (rc == LIBX52_SUCCESS) { + // Device manager will update the clock, this is only for debugging + PINELOG_TRACE("Setting X52 clock to %ld", cur_time); + } + } + + return NULL; +} + +void x52d_clock_init(void) +{ + int rc; + + PINELOG_TRACE("Initializing clock manager"); + rc = pthread_create(&clock_thr, NULL, x52_clock_thr, NULL); + if (rc != 0) { + PINELOG_FATAL(_("Error %d initializing clock thread: %s"), + rc, strerror(rc)); + } +} + +void x52d_clock_exit(void) +{ + PINELOG_INFO(_("Shutting down X52 clock manager thread")); + pthread_cancel(clock_thr); +} diff --git a/daemon/x52d_clock.h b/daemon/x52d_clock.h new file mode 100644 index 0000000..3bfd631 --- /dev/null +++ b/daemon/x52d_clock.h @@ -0,0 +1,15 @@ +/* + * Saitek X52 Pro MFD & LED driver - Clock manager + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#ifndef X52D_CLOCK_H +#define X52D_CLOCK_H + +void x52d_clock_init(void); +void x52d_clock_exit(void); + +#endif // !defined X52D_CLOCK_H diff --git a/daemon/x52d_config.c b/daemon/x52d_config.c new file mode 100644 index 0000000..193e837 --- /dev/null +++ b/daemon/x52d_config.c @@ -0,0 +1,56 @@ +/* + * Saitek X52 Pro MFD & LED driver - Configuration parser + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include "pinelog.h" +#include "x52d_config.h" +#include "x52d_const.h" + +static struct x52d_config x52d_config; + +void x52d_config_load(const char *cfg_file) +{ + int rc; + + if (cfg_file == NULL) { + cfg_file = X52D_SYS_CFG_FILE; + } + + rc = x52d_config_set_defaults(&x52d_config); + if (rc != 0) { + PINELOG_FATAL(_("Error %d setting configuration defaults: %s"), + rc, strerror(rc)); + } + + rc = x52d_config_load_file(&x52d_config, cfg_file); + if (rc != 0) { + exit(EXIT_FAILURE); + } + + // Apply overrides + rc = x52d_config_apply_overrides(&x52d_config); + x52d_config_clear_overrides(); + if (rc != 0) { + exit(EXIT_FAILURE); + } +} + +/* Callback stubs + * TODO: Remove the ones below when their implementation is complete + */ +void x52d_cfg_set_Profiles_Directory(char* param) { (void)param; } +void x52d_cfg_set_Profiles_ClutchEnabled(bool param) { (void)param; } +void x52d_cfg_set_Profiles_ClutchLatched(bool param) { (void)param; } + +void x52d_config_apply(void) +{ + #define CFG(section, key, name, parser, def) \ + PINELOG_TRACE("Calling configuration callback for " #section "." #key); \ + x52d_cfg_set_ ## section ## _ ## key(x52d_config . name); + #include "x52d_config.def" +} diff --git a/daemon/x52d_config.def b/daemon/x52d_config.def new file mode 100644 index 0000000..8e221dc --- /dev/null +++ b/daemon/x52d_config.def @@ -0,0 +1,82 @@ +/********************************************************************** + * X52 Daemon Configuration + *********************************************************************/ + +// The settings below are the defaults. Note that the section and key +// strings are case insensitive, but the values are not necessarily so, +// especially for those referring to paths or timezone names. + +/* CFG(section, key, name, parser, default) */ +/********************************************************************** + * Clock Settings + *********************************************************************/ + +// Enabled controls whether the clock is enabled or not. Set this to no to +// disable the clock update. Keep in mind that if the clock was originally +// enabled on the X52, then disabling it here won't make the clock disappear +// on the MFD. You will need to unplug and reattach the X52 to make the +// clock disappear +CFG(Clock, Enabled, clock_enabled, bool_parser, true) + +// PrimaryIsLocal controls whether the primary clock displays local time or UTC. +// Set this to yes to display local time, no for UTC. +CFG(Clock, PrimaryIsLocal, primary_clock_local, bool_parser, true) + +// Secondary controls the timezone of the secondary clock. Use the standard +// timezone name as defined by the Olson time database. +CFG(Clock, Secondary, clock_2_tz, string_parser, UTC) + +// Tertiary controls the timezone of the tertiary clock. Use the standard +// timezone name as defined by the Olson time database. +CFG(Clock, Tertiary, clock_3_tz, string_parser, UTC) + +// Clock format for the primary clock +CFG(Clock, FormatPrimary, clock_format[LIBX52_CLOCK_1], clock_format_parser, 12hr) + +// Clock format for the secondary clock +CFG(Clock, FormatSecondary, clock_format[LIBX52_CLOCK_2], clock_format_parser, 12hr) + +// Clock format for the tertiary clock +CFG(Clock, FormatTertiary, clock_format[LIBX52_CLOCK_3], clock_format_parser, 12hr) + +// Date format for the date display +CFG(Clock, DateFormat, date_format, date_format_parser, ddmmyy) + +/********************************************************************** + * LED Settings - only applicable to X52Pro + *********************************************************************/ +// The LED settings map a color code or state to the corresponding LED. +CFG(LED, Fire, leds[LIBX52_LED_FIRE], led_parser, on) +CFG(LED, Throttle, leds[LIBX52_LED_THROTTLE], led_parser, on) +CFG(LED, A, leds[LIBX52_LED_A], led_parser, green) +CFG(LED, B, leds[LIBX52_LED_B], led_parser, green) +CFG(LED, D, leds[LIBX52_LED_D], led_parser, green) +CFG(LED, E, leds[LIBX52_LED_E], led_parser, green) +CFG(LED, T1, leds[LIBX52_LED_T1], led_parser, green) +CFG(LED, T2, leds[LIBX52_LED_T2], led_parser, green) +CFG(LED, T3, leds[LIBX52_LED_T3], led_parser, green) +CFG(LED, POV, leds[LIBX52_LED_POV], led_parser, green) +CFG(LED, Clutch, leds[LIBX52_LED_CLUTCH], led_parser, green) + +/********************************************************************** + * Brightness Settings + *********************************************************************/ +// The brightness settings map the brightness value to the LEDs/MFD. +CFG(Brightness, MFD, brightness[0], int_parser, 128) +CFG(Brightness, LED, brightness[1], int_parser, 128) + +/********************************************************************** + * Profiles - only valid on Linux + *********************************************************************/ +// Directory is the location of the folder containing the individual profiles. +CFG(Profiles, Directory, profiles_dir, string_parser, /etc/x52d/profiles.d) + +// ClutchEnabled determines if the clutch button is treated specially +CFG(Profiles, ClutchEnabled, clutch_enabled, bool_parser, false) + +// ClutchLatched controls if the clutch button (if enabled) is a latched button +// (press once to enter clutch mode, press again to exit clutch mode), or must +// be held down to remain in clutch mode. +CFG(Profiles, ClutchLatched, clutch_latched, bool_parser, false) + +#undef CFG diff --git a/daemon/x52d_config.h b/daemon/x52d_config.h new file mode 100644 index 0000000..416a72f --- /dev/null +++ b/daemon/x52d_config.h @@ -0,0 +1,86 @@ +/* + * Saitek X52 Pro MFD & LED driver - Configuration parser header + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#ifndef X52D_CONFIG_H +#define X52D_CONFIG_H + +#include +#include +#include +#include "libx52.h" + +/** + * @brief Configuration structure + * + * Keep this in sync with the sample configuration + */ +struct x52d_config { + bool clock_enabled; + bool primary_clock_local; + + // Since we don't have a _MAX identifier for libx52_clock_id, use + // the maximum clock ID + 1 as the length + libx52_clock_format clock_format[LIBX52_CLOCK_3 + 1]; + libx52_date_format date_format; + + char clock_2_tz[NAME_MAX]; + char clock_3_tz[NAME_MAX]; + + // Since we don't have a _MAX identifier for libx52_led_id, hardcode + // the length in the following declaration. + libx52_led_state leds[21]; + + uint16_t brightness[2]; + + bool clutch_enabled; + bool clutch_latched; + + char profiles_dir[NAME_MAX]; +}; + +/* Callback functions for configuration */ +// These functions are defined in the individual modules +void x52d_cfg_set_Clock_Enabled(bool param); +void x52d_cfg_set_Clock_PrimaryIsLocal(bool param); +void x52d_cfg_set_Clock_Secondary(char* param); +void x52d_cfg_set_Clock_Tertiary(char* param); +void x52d_cfg_set_Clock_FormatPrimary(libx52_clock_format param); +void x52d_cfg_set_Clock_FormatSecondary(libx52_clock_format param); +void x52d_cfg_set_Clock_FormatTertiary(libx52_clock_format param); +void x52d_cfg_set_Clock_DateFormat(libx52_date_format param); +void x52d_cfg_set_LED_Fire(libx52_led_state param); +void x52d_cfg_set_LED_Throttle(libx52_led_state param); +void x52d_cfg_set_LED_A(libx52_led_state param); +void x52d_cfg_set_LED_B(libx52_led_state param); +void x52d_cfg_set_LED_D(libx52_led_state param); +void x52d_cfg_set_LED_E(libx52_led_state param); +void x52d_cfg_set_LED_T1(libx52_led_state param); +void x52d_cfg_set_LED_T2(libx52_led_state param); +void x52d_cfg_set_LED_T3(libx52_led_state param); +void x52d_cfg_set_LED_POV(libx52_led_state param); +void x52d_cfg_set_LED_Clutch(libx52_led_state param); +void x52d_cfg_set_Brightness_MFD(uint16_t param); +void x52d_cfg_set_Brightness_LED(uint16_t param); +void x52d_cfg_set_Profiles_Directory(char* param); +void x52d_cfg_set_Profiles_ClutchEnabled(bool param); +void x52d_cfg_set_Profiles_ClutchLatched(bool param); + +int x52d_config_set_defaults(struct x52d_config *cfg); + +int x52d_config_load_file(struct x52d_config *cfg, const char *cfg_file); + +int x52d_config_save_override(const char *override_str); + +int x52d_config_apply_overrides(struct x52d_config *cfg); + +void x52d_config_clear_overrides(void); + +void x52d_config_load(const char *cfg_file); +void x52d_config_apply(void); + +#endif // !defined X52D_CONFIG_H diff --git a/daemon/x52d_config_parser.c b/daemon/x52d_config_parser.c new file mode 100644 index 0000000..1132e10 --- /dev/null +++ b/daemon/x52d_config_parser.c @@ -0,0 +1,357 @@ +/* + * Saitek X52 Pro MFD & LED driver - Configuration parser + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include + +#include "ini.h" +#include "pinelog.h" +#include "x52d_config.h" +#include "x52d_const.h" + +/* Parser function typedef */ +typedef int (*parser_fn)(struct x52d_config *, size_t, const char *); + +// Check if the parameters are all valid +#define CHECK_PARAMS() do { if (cfg == NULL || value == NULL) { return EINVAL; } } while(0) + +// Create a pointer "name" of type "type", which stores the pointer to the +// corresponding element within the config struct. +#define CONFIG_PTR(type, name) type name = (type)((uintptr_t)cfg + offset) + +static int bool_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(bool *, config); + CHECK_PARAMS(); + + if (!strcasecmp(value, "yes") || !strcasecmp(value, "true")) { + *config = true; + } else if (!strcasecmp(value, "no") || !strcasecmp(value, "false")) { + *config = false; + } else { + return EINVAL; + } + + return 0; +} + +static int string_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(char *, config); + CHECK_PARAMS(); + + /* String parameters are all NAME_MAX len */ + strncpy(config, value, NAME_MAX-1); + config[NAME_MAX-1] = '\0'; + + return 0; +} + +static int int_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(int *, config); + char *endptr; + int retval; + + CHECK_PARAMS(); + + errno = 0; + retval = strtol(value, &endptr, 0); + if (errno != 0) { + return errno; + } + + *config = retval; + return 0; +} + +static int led_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(libx52_led_state *, config); + CHECK_PARAMS(); + + #define MATCH_STATE(val) if (!strcasecmp(value, #val)) { *config = LIBX52_LED_STATE_ ## val ; } + MATCH_STATE(OFF) + else MATCH_STATE(ON) + else MATCH_STATE(RED) + else MATCH_STATE(AMBER) + else MATCH_STATE(GREEN) + else return EINVAL; + #undef MATCH_STATE + + return 0; +} + +static int clock_format_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(libx52_clock_format *, config); + CHECK_PARAMS(); + + if (!strcasecmp(value, "12hr") || !strcasecmp(value, "12")) { + *config = LIBX52_CLOCK_FORMAT_12HR; + } else if (!strcasecmp(value, "24hr") || !strcasecmp(value, "24")) { + *config = LIBX52_CLOCK_FORMAT_24HR; + } else { + return EINVAL; + } + + return 0; +} + +static int date_format_parser(struct x52d_config *cfg, size_t offset, const char *value) +{ + CONFIG_PTR(libx52_date_format *, config); + CHECK_PARAMS(); + + if (!strcasecmp(value, "ddmmyy") || !strcasecmp(value, "dd-mm-yy")) { + *config = LIBX52_DATE_FORMAT_DDMMYY; + } else if (!strcasecmp(value, "mmddyy") || !strcasecmp(value, "mm-dd-yy")) { + *config = LIBX52_DATE_FORMAT_MMDDYY; + } else if (!strcasecmp(value, "yymmdd") || !strcasecmp(value, "yy-mm-dd")) { + *config = LIBX52_DATE_FORMAT_YYMMDD; + } else { + return EINVAL; + } + + return 0; +} + +/* Map for config->param */ +#define CFG(section, key, name, parser, def) {#section, #key, parser, offsetof(struct x52d_config, name)}, +const struct config_map { + const char *section; + const char *key; + parser_fn parser; + size_t offset; +} config_map[] = { + #include "x52d_config.def" + + // Terminating entry + {NULL, NULL, NULL, 0} +}; + +static int process_config_kv(void *user, const char *section, const char *key, const char *value) +{ + int i; + int rc = 0; + bool found = false; + struct x52d_config *cfg = (struct x52d_config*)user; + + for (i = 0; config_map[i].key != NULL; i++) { + rc = 0; + if (!strcasecmp(config_map[i].key, key) && + !strcasecmp(config_map[i].section, section)) { + found = true; + PINELOG_TRACE("Setting '%s.%s'='%s'", + config_map[i].section, config_map[i].key, value); + rc = config_map[i].parser(cfg, config_map[i].offset, value); + break; + } + } + + if (!found) { + // Print error message, but continue + PINELOG_INFO(_("Ignoring unknown key '%s.%s'"), section, key); + } + + return rc; +} + +/** + * @brief Set configuration defaults + * + * @param[in] cfg Pointer to config struct + * + * @returns 0 on success, non-zero error code on failure + */ +int x52d_config_set_defaults(struct x52d_config *cfg) { + int rc; + + if (cfg == NULL) { + return EINVAL; + } + + PINELOG_TRACE("Setting configuration defaults"); + #define CFG(section, key, name, parser, def) \ + rc = process_config_kv(cfg, #section, #key, #def); \ + if (rc != 0) { \ + return rc; \ + } + #include "x52d_config.def" + + return 0; +} + +int x52d_config_load_file(struct x52d_config *cfg, const char *cfg_file) +{ + int rc; + if (cfg == NULL || cfg_file == NULL) { + return EINVAL; + } + + PINELOG_TRACE("Loading configuration from file %s", cfg_file); + rc = ini_parse(cfg_file, process_config_kv, cfg); + if (rc < 0) { + PINELOG_ERROR(_("Failed processing configuration file %s - code %d"), + cfg_file, rc); + return EIO; + } + + return 0; +} + +struct x52d_config_override { + char *section; + char *key; + char *value; + struct x52d_config_override *next; +}; + +static struct x52d_config_override *override_head; +static struct x52d_config_override *override_tail; + +int x52d_config_save_override(const char *override_str) +{ + // Parse override string of the form section.key=value + struct x52d_config_override *override; + char *string = NULL; + char *free_ptr = NULL; + char *ptr; + int rc; + + PINELOG_TRACE("Allocating memory (%lu bytes) for override structure", sizeof(*override)); + override = calloc(1, sizeof(*override)); + if (override == NULL) { + PINELOG_ERROR(_("Failed to allocate memory for override structure")); + rc = ENOMEM; + goto cleanup; + } + + errno = 0; + PINELOG_TRACE("Duplicating override string"); + string = strdup(override_str); + if (string == NULL) { + PINELOG_ERROR(_("Failed to allocate memory for override string")); + rc = errno; + goto cleanup; + } + free_ptr = string; + + override->section = string; + // Ensure that the string is of the form ([^.]+\.[^=]+=.*) + ptr = strchr(string, '.'); + if (ptr == NULL || ptr == string) { + // No section found + PINELOG_ERROR(_("No section found in override string '%s'"), string); + rc = EINVAL; + goto cleanup; + } + // Reset the . to NUL + *ptr = '\0'; + ptr++; + PINELOG_TRACE("Splitting override string to '%s' and '%s'", string, ptr); + string = ptr; + + override->key = string; + ptr = strchr(string, '='); + if (ptr == NULL || ptr == string) { + // No key found + PINELOG_ERROR(_("No key found in override string '%s'"), string); + rc = EINVAL; + goto cleanup; + } + // Reset the = to NUL + *ptr = '\0'; + ptr++; + PINELOG_TRACE("Splitting override string to '%s' and '%s'", string, ptr); + + if (*ptr == '\0') { + // No value found + PINELOG_ERROR(_("No value found in override string '%s'"), string); + rc = EINVAL; + goto cleanup; + } + + override->value = ptr; + + // Add the override to the linked list + if (override_tail != NULL) { + PINELOG_TRACE("Linking override to list tail"); + override_tail->next = override; + } + PINELOG_TRACE("Setting list tail to override"); + override_tail = override; + + if (override_head == NULL) { + PINELOG_TRACE("Setting list head to override"); + override_head = override; + } + + return 0; + +cleanup: + if (free_ptr != NULL) { + free(free_ptr); + } + if (override != NULL) { + free(override); + } + return rc; +} + +int x52d_config_apply_overrides(struct x52d_config *cfg) +{ + int rc; + struct x52d_config_override *tmp = override_head; + + if (cfg == NULL) { + return EINVAL; + } + + while (tmp != NULL) { + PINELOG_TRACE("Processing override '%s.%s=%s'", + tmp->section, + tmp->key, + tmp->value); + rc = process_config_kv(cfg, + tmp->section, + tmp->key, + tmp->value); + if (rc != 0) { + PINELOG_ERROR(_("Error processing override '%s.%s=%s'"), + tmp->section, + tmp->key, + tmp->value); + return rc; + } + tmp = tmp->next; + } + + return 0; +} + +void x52d_config_clear_overrides(void) +{ + struct x52d_config_override *tmp; + while (override_head != NULL) { + tmp = override_head; + override_head = override_head->next; + PINELOG_TRACE("Freeing override '%s.%s=%s'", + tmp->section, + tmp->key, + tmp->value); + free(tmp); + } + + override_tail = NULL; +} diff --git a/daemon/x52d_const.h b/daemon/x52d_const.h new file mode 100644 index 0000000..f7702e5 --- /dev/null +++ b/daemon/x52d_const.h @@ -0,0 +1,22 @@ +/* + * Saitek X52 Pro MFD & LED driver - Application constants + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#ifndef X52D_CONST_H +#define X52D_CONST_H + +#define X52D_APP_NAME "x52d" + +#define X52D_LOG_FILE LOGDIR "/" X52D_APP_NAME ".log" + +#define X52D_SYS_CFG_FILE SYSCONFDIR "/" X52D_APP_NAME "/" X52D_APP_NAME ".conf" + +#include "gettext.h" +#define N_(x) gettext_noop(x) +#define _(x) gettext(x) + +#endif // !defined X52D_CONST_H diff --git a/daemon/x52d_device.c b/daemon/x52d_device.c new file mode 100644 index 0000000..0ec4926 --- /dev/null +++ b/daemon/x52d_device.c @@ -0,0 +1,228 @@ +/* + * Saitek X52 Pro MFD & LED driver - Device manager + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include + +#include "x52d_const.h" +#include "x52d_device.h" +#include "libx52.h" +#include "libx52io.h" +#include "pinelog.h" + +static libx52_device *x52_dev; + +static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* + * Device acquisition thread + * This is a thread that scans for and opens a supported X52 joystick. + */ +static pthread_t device_acq_thr; +static volatile bool device_acq_thr_enable; +static volatile bool device_upd_thr_enable; + +static void *x52_dev_acq(void *param) +{ + int rc; + + PINELOG_INFO(_("Starting X52 device acquisition thread")); + // Check if the device is connected in a loop + for (;;) { + #define RECONNECT_DELAY 5 + if (!device_acq_thr_enable) { + PINELOG_TRACE("Device acquisition thread disabled. Checking again in %d seconds", RECONNECT_DELAY); + sleep(RECONNECT_DELAY); + continue; + } + + if (!libx52_is_connected(x52_dev)) { + PINELOG_TRACE("Attempting to connect to X52 device"); + rc = libx52_connect(x52_dev); + if (rc != LIBX52_SUCCESS) { + if (rc != LIBX52_ERROR_NO_DEVICE) { + PINELOG_ERROR(_("Error %d connecting to device: %s"), + rc, libx52_strerror(rc)); + } else { + PINELOG_TRACE("No compatible X52 device found"); + } + PINELOG_TRACE("Sleeping for %d seconds before trying to acquire device again", RECONNECT_DELAY); + sleep(RECONNECT_DELAY); + } else { + PINELOG_TRACE("Found device, disabling acquisition thread, enable update thread"); + device_acq_thr_enable = false; + device_upd_thr_enable = true; + } + } else { + PINELOG_TRACE("Device is connected, disable acquisition thread, enable update thread"); + device_acq_thr_enable = false; + device_upd_thr_enable = true; + } + #undef RECONNECT_DELAY + } + + return NULL; +} + +/* + * Device update thread + * This is a thread that updates the joystick. + */ +static pthread_t device_upd_thr; +static volatile bool device_update_needed; + +static void *x52_dev_upd(void *param) +{ + PINELOG_INFO(_("Starting X52 device update thread")); + // Check if the device needs to be updated in a loop + for (;;) { + #define UPDATE_CHECK_DELAY 50000 // Wait for this many useconds + if (!device_update_needed || !device_upd_thr_enable) { + usleep(UPDATE_CHECK_DELAY); + continue; + } + + (void)x52d_dev_update(); + #undef UPDATE_CHECK_DELAY + } + + return NULL; +} + +void x52d_dev_init(void) +{ + int rc; + PINELOG_INFO(_("Initializing libx52")); + rc = libx52_init(&x52_dev); + + if (rc != LIBX52_SUCCESS) { + PINELOG_FATAL(_("Failure %d initializing libx52: %s"), + rc, libx52_strerror(rc)); + } + + // Create and initialize the threads + pthread_create(&device_acq_thr, NULL, x52_dev_acq, NULL); + // With libx52.so.2.3.0, libx52_init will also attempt to connect to a + // supported joystick. Check if a device is already connected before + // enabling the device acquisition thread. + device_acq_thr_enable = !libx52_is_connected(x52_dev); + + pthread_create(&device_upd_thr, NULL, x52_dev_upd, NULL); + device_update_needed = false; + device_upd_thr_enable = libx52_is_connected(x52_dev); +} + +void x52d_dev_exit(void) +{ + // Shutdown any threads + PINELOG_INFO(_("Shutting down X52 device acquisition thread")); + pthread_cancel(device_acq_thr); + + PINELOG_INFO(_("Shutting down X52 device update thread")); + pthread_cancel(device_upd_thr); + + libx52_exit(x52_dev); +} + +#define WRAP_LIBX52(func) \ + int rc; \ + pthread_mutex_lock(&device_mutex); \ + rc = func; \ + pthread_mutex_unlock(&device_mutex); \ + if (rc != LIBX52_SUCCESS) { \ + if (rc != LIBX52_ERROR_TRY_AGAIN) { \ + PINELOG_ERROR(_("Error %d when updating X52 parameter: %s"), \ + rc, libx52_strerror(rc)); \ + } \ + } else { \ + device_update_needed = true; \ + } \ + return rc + +int x52d_dev_set_text(uint8_t line, const char *text, uint8_t length) +{ + WRAP_LIBX52(libx52_set_text(x52_dev, line, text, length)); +} +int x52d_dev_set_led_state(libx52_led_id led, libx52_led_state state) +{ + if (libx52_check_feature(x52_dev, LIBX52_FEATURE_LED) != LIBX52_ERROR_NOT_SUPPORTED) { + WRAP_LIBX52(libx52_set_led_state(x52_dev, led, state)); + } + + // If the target device does not support setting individual LEDs, + // then ignore the set and let the caller think it succeeded. + PINELOG_TRACE("Ignoring set LED state call as the device does not support it"); + return LIBX52_SUCCESS; +} +int x52d_dev_set_clock(time_t time, int local) +{ + WRAP_LIBX52(libx52_set_clock(x52_dev, time, local)); +} +int x52d_dev_set_clock_timezone(libx52_clock_id clock, int offset) +{ + WRAP_LIBX52(libx52_set_clock_timezone(x52_dev, clock, offset)); +} +int x52d_dev_set_clock_format(libx52_clock_id clock, libx52_clock_format format) +{ + WRAP_LIBX52(libx52_set_clock_format(x52_dev, clock, format)); +} +int x52d_dev_set_time(uint8_t hour, uint8_t minute) +{ + WRAP_LIBX52(libx52_set_time(x52_dev, hour, minute)); +} +int x52d_dev_set_date(uint8_t dd, uint8_t mm, uint8_t yy) +{ + WRAP_LIBX52(libx52_set_date(x52_dev, dd, mm, yy)); +} +int x52d_dev_set_date_format(libx52_date_format format) +{ + WRAP_LIBX52(libx52_set_date_format(x52_dev, format)); +} +int x52d_dev_set_brightness(uint8_t mfd, uint16_t brightness) +{ + WRAP_LIBX52(libx52_set_brightness(x52_dev, mfd, brightness)); +} +int x52d_dev_set_shift(uint8_t state) +{ + WRAP_LIBX52(libx52_set_shift(x52_dev, state)); +} +int x52d_dev_set_blink(uint8_t state) +{ + WRAP_LIBX52(libx52_set_blink(x52_dev, state)); +} + +int x52d_dev_update(void) +{ + int rc; + + pthread_mutex_lock(&device_mutex); + rc = libx52_update(x52_dev); + pthread_mutex_unlock(&device_mutex); + + if (rc != LIBX52_SUCCESS) { + if (rc == LIBX52_ERROR_NO_DEVICE) { + // Detach and spawn thread to reconnect + PINELOG_TRACE("Disconnecting detached device"); + libx52_disconnect(x52_dev); + + PINELOG_TRACE("Disabling device update thread"); + device_upd_thr_enable = false; + + PINELOG_TRACE("Signaling device search thread"); + device_acq_thr_enable = true; + } else { + PINELOG_ERROR(_("Error %d when updating X52 device: %s"), + rc, libx52_strerror(rc)); + } + } else { + device_update_needed = false; + } + + return rc; +} diff --git a/daemon/x52d_device.h b/daemon/x52d_device.h new file mode 100644 index 0000000..e7f024c --- /dev/null +++ b/daemon/x52d_device.h @@ -0,0 +1,31 @@ +/* + * Saitek X52 Pro MFD & LED driver - Device manager header + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#ifndef X52D_DEVICE_H +#define X52D_DEVICE_H + +#include "libx52.h" + +void x52d_dev_init(void); +void x52d_dev_exit(void); + +/* Wrapper methods for libx52 calls */ +int x52d_dev_set_text(uint8_t line, const char *text, uint8_t length); +int x52d_dev_set_led_state(libx52_led_id led, libx52_led_state state); +int x52d_dev_set_clock(time_t time, int local); +int x52d_dev_set_clock_timezone(libx52_clock_id clock, int offset); +int x52d_dev_set_clock_format(libx52_clock_id clock, libx52_clock_format format); +int x52d_dev_set_time(uint8_t hour, uint8_t minute); +int x52d_dev_set_date(uint8_t dd, uint8_t mm, uint8_t yy); +int x52d_dev_set_date_format(libx52_date_format format); +int x52d_dev_set_brightness(uint8_t mfd, uint16_t brightness); +int x52d_dev_set_shift(uint8_t state); +int x52d_dev_set_blink(uint8_t state); +int x52d_dev_update(void); + +#endif // !defined X52D_DEVICE_H diff --git a/daemon/x52d_led.c b/daemon/x52d_led.c new file mode 100644 index 0000000..f24729f --- /dev/null +++ b/daemon/x52d_led.c @@ -0,0 +1,94 @@ +/* + * Saitek X52 Pro MFD & LED driver - Clock manager + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include +#include +#include +#include + +#include "pinelog.h" +#include "x52d_config.h" +#include "x52d_const.h" +#include "x52d_device.h" + +#define SET_LED_STATE(led, state) \ + PINELOG_TRACE("Setting LED %s state to %s", \ + libx52_led_id_to_str(LIBX52_LED_ ## led), \ + libx52_led_state_to_str(state)); \ + x52d_dev_set_led_state(LIBX52_LED_ ## led, state); + +void x52d_cfg_set_LED_Fire(libx52_led_state state) +{ + SET_LED_STATE(FIRE, state); +} + +void x52d_cfg_set_LED_Throttle(libx52_led_state state) +{ + SET_LED_STATE(THROTTLE, state); +} + +void x52d_cfg_set_LED_A(libx52_led_state state) +{ + SET_LED_STATE(A, state); +} + +void x52d_cfg_set_LED_B(libx52_led_state state) +{ + SET_LED_STATE(B, state); +} + +void x52d_cfg_set_LED_D(libx52_led_state state) +{ + SET_LED_STATE(D, state); +} + +void x52d_cfg_set_LED_E(libx52_led_state state) +{ + SET_LED_STATE(E, state); +} + +void x52d_cfg_set_LED_T1(libx52_led_state state) +{ + SET_LED_STATE(T1, state); +} + +void x52d_cfg_set_LED_T2(libx52_led_state state) +{ + SET_LED_STATE(T2, state); +} + +void x52d_cfg_set_LED_T3(libx52_led_state state) +{ + SET_LED_STATE(T3, state); +} + +void x52d_cfg_set_LED_POV(libx52_led_state state) +{ + SET_LED_STATE(POV, state); +} + +void x52d_cfg_set_LED_Clutch(libx52_led_state state) +{ + SET_LED_STATE(CLUTCH, state); +} + +#define SET_BRIGHTNESS(mfd, brightness) \ + PINELOG_TRACE("Setting %s brightness to %u", mfd ? "MFD" : "LED", brightness); \ + x52d_dev_set_brightness(mfd, brightness); + +void x52d_cfg_set_Brightness_MFD(uint16_t brightness) +{ + SET_BRIGHTNESS(1, brightness); +} + +void x52d_cfg_set_Brightness_LED(uint16_t brightness) +{ + SET_BRIGHTNESS(0, brightness); +} diff --git a/daemon/x52d_main.c b/daemon/x52d_main.c new file mode 100644 index 0000000..06a515d --- /dev/null +++ b/daemon/x52d_main.c @@ -0,0 +1,201 @@ +/* + * Saitek X52 Pro MFD & LED driver - Service daemon + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include + +#include "x52d_clock.h" +#include "x52d_const.h" +#include "x52d_config.h" +#include "x52d_device.h" +#include "pinelog.h" + +static volatile int flag_quit; + +static void termination_handler(int signum) +{ + flag_quit = signum; +} + +static volatile bool flag_reload; +static void reload_handler(int signum) +{ + flag_reload = true; +} + +static void set_log_file(bool foreground, const char *log_file) +{ + int rc = 0; + if (log_file != NULL) { + rc = pinelog_set_output_file(log_file); + } else { + if (foreground) { + rc = pinelog_set_output_stream(stdout); + } else { + rc = pinelog_set_output_file(X52D_LOG_FILE); + } + } + + if (rc != 0) { + fprintf(stderr, _("Error %d setting log file: %s\n"), rc, strerror(rc)); + exit(EXIT_FAILURE); + } +} + +static void listen_signal(int signum, void (*handler)(int)) +{ + struct sigaction action; + int rc; + + action.sa_handler = handler; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + + rc = sigaction(signum, &action, NULL); + if (rc < 0) { + PINELOG_FATAL(_("Error %d installing handler for signal %d: %s"), + errno, signum, strerror(errno)); + } +} + +#if HAVE_FUNC_ATTRIBUTE_NORETURN +__attribute__((noreturn)) +#endif +static void usage(int exit_code) +{ + fprintf(stderr, + _("Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n"), + X52D_APP_NAME); + exit(exit_code); +} + +int main(int argc, char **argv) +{ + int verbosity = 0; + bool quiet = false; + bool foreground = false; + char *log_file = NULL; + char *conf_file = NULL; + int opt; + + /* Initialize gettext */ + #if ENABLE_NLS + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + #endif + + /* Set system defaults */ + pinelog_set_level(PINELOG_LVL_WARNING); + + /* + * Parse command line arguments + * + * -f run in foreground + * -c path to config file + * -o option overrides + * -v verbose logging + * -q silent behavior + * -l path to log file + */ + while ((opt = getopt(argc, argv, "fvql:o:c:h")) != -1) { + switch (opt) { + case 'f': + foreground = true; + break; + + case 'v': + if (!quiet) { + if (verbosity <= PINELOG_LVL_TRACE) { + verbosity++; + pinelog_set_level(pinelog_get_level() + 1); + } + } + break; + + case 'q': + quiet = true; + pinelog_set_level(PINELOG_LVL_ERROR); + break; + + case 'l': + log_file = optarg; + break; + + case 'o': + if (x52d_config_save_override(optarg)) { + fprintf(stderr, + _("Unable to parse configuration override '%s'\n"), + optarg); + exit(EXIT_FAILURE); + } + break; + + case 'c': + conf_file = optarg; + break; + + case 'h': + usage(EXIT_SUCCESS); + break; + + default: + usage(EXIT_FAILURE); + break; + } + } + + PINELOG_DEBUG(_("Foreground = %s"), foreground ? _("true") : _("false")); + PINELOG_DEBUG(_("Quiet = %s"), quiet ? _("true") : _("false")); + PINELOG_DEBUG(_("Verbosity = %d"), verbosity); + PINELOG_DEBUG(_("Log file = %s"), log_file); + PINELOG_DEBUG(_("Config file = %s"), conf_file); + + set_log_file(foreground, log_file); + x52d_config_load(conf_file); + + // Initialize signal handlers + listen_signal(SIGINT, termination_handler); + listen_signal(SIGTERM, termination_handler); + listen_signal(SIGQUIT, termination_handler); + listen_signal(SIGHUP, reload_handler); + + // Start device threads + x52d_dev_init(); + x52d_clock_init(); + + // Apply configuration + x52d_config_apply(); + + flag_quit = 0; + while(!flag_quit) { + // TODO: Replace with main event loop + // Let all threads run in background forever + sleep(600); + + /* Check if we need to reload configuration */ + if (flag_reload) { + PINELOG_INFO(_("Reloading X52 configuration")); + x52d_config_load(conf_file); + x52d_config_apply(); + flag_reload = false; + } + } + + // Stop device threads + x52d_clock_exit(); + x52d_dev_exit(); + PINELOG_INFO(_("Shutting down X52 daemon")); + + return 0; +} diff --git a/utils/evtest/Makefile.am b/evtest/Makefile.am similarity index 52% rename from utils/evtest/Makefile.am rename to evtest/Makefile.am index b676c05..c5722d2 100644 --- a/utils/evtest/Makefile.am +++ b/evtest/Makefile.am @@ -4,12 +4,10 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -ACLOCAL_AMFLAGS = -I m4 - -bin_PROGRAMS = x52evtest +bin_PROGRAMS += x52evtest # Event test utility that works similarly to the Linux evtest -x52evtest_SOURCES = ev_test.c -x52evtest_CFLAGS = -I $(top_srcdir)/lib/libx52io -I $(top_srcdir) -DLOCALEDIR=\"$(localedir)\" $(WARN_CFLAGS) +x52evtest_SOURCES = evtest/ev_test.c +x52evtest_CFLAGS = -I $(top_srcdir)/libx52io -I $(top_srcdir) -DLOCALEDIR=\"$(localedir)\" $(WARN_CFLAGS) x52evtest_LDFLAGS = $(WARN_LDFLAGS) -x52evtest_LDADD = ../../lib/libx52io/libx52io.la +x52evtest_LDADD = libx52io.la diff --git a/utils/evtest/ev_test.c b/evtest/ev_test.c similarity index 100% rename from utils/evtest/ev_test.c rename to evtest/ev_test.c diff --git a/joytest/Makefile.am b/joytest/Makefile.am new file mode 100644 index 0000000..cf87f71 --- /dev/null +++ b/joytest/Makefile.am @@ -0,0 +1,20 @@ +# Automake for x52test +# +# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + +bin_PROGRAMS += x52test + +# Test utility that exercises all the library functions +x52test_SOURCES = \ + joytest/x52_test.c \ + joytest/x52_test_mfd.c \ + joytest/x52_test_led.c \ + joytest/x52_test_clock.c +x52test_CFLAGS = -I $(top_srcdir)/libx52 -I $(top_srcdir) -DLOCALEDIR=\"$(localedir)\" $(WARN_CFLAGS) +x52test_LDFLAGS = $(WARN_LDFLAGS) +x52test_LDADD = libx52.la + +# Extra files that need to be in the distribution +EXTRA_DIST += joytest/x52_test_common.h diff --git a/utils/test/x52_test.c b/joytest/x52_test.c similarity index 100% rename from utils/test/x52_test.c rename to joytest/x52_test.c diff --git a/utils/test/x52_test_clock.c b/joytest/x52_test_clock.c similarity index 100% rename from utils/test/x52_test_clock.c rename to joytest/x52_test_clock.c diff --git a/utils/test/x52_test_common.h b/joytest/x52_test_common.h similarity index 100% rename from utils/test/x52_test_common.h rename to joytest/x52_test_common.h diff --git a/utils/test/x52_test_led.c b/joytest/x52_test_led.c similarity index 100% rename from utils/test/x52_test_led.c rename to joytest/x52_test_led.c diff --git a/utils/test/x52_test_mfd.c b/joytest/x52_test_mfd.c similarity index 100% rename from utils/test/x52_test_mfd.c rename to joytest/x52_test_mfd.c diff --git a/lib/Makefile.am b/lib/Makefile.am index e6c3dca..e067e74 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,5 +4,5 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -SUBDIRS = libx52 libx52util libusbx52 libx52io +SUBDIRS = pinelog diff --git a/lib/libusbx52/Makefile.am b/lib/libusbx52/Makefile.am deleted file mode 100644 index 6b0b4e1..0000000 --- a/lib/libusbx52/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -# Automake for libusbx52 and associated utilities -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -ACLOCAL_AMFLAGS = -I m4 - -# Use the pthread compiler variables -LIBS += $(PTHREAD_LIBS) -AM_CFLAGS = $(PTHREAD_CFLAGS) -CC = $(PTHREAD_CC) - -# libusb stub library for use by test programs -check_LTLIBRARIES = libusbx52.la - -libusbx52_la_SOURCES = usb_x52_stub.c fopen_env.c -libusbx52_la_CFLAGS = @LIBUSB_CFLAGS@ $(WARN_CFLAGS) -libusbx52_la_LDFLAGS = -rpath /nowhere -module $(WARN_LDFLAGS) - -# Utility programs for use by tests -check_PROGRAMS = x52test_create_device_list x52test_log_actions - -x52test_create_device_list_SOURCES = util/create_device_list.c $(libusbx52_la_SOURCES) -x52test_create_device_list_CFLAGS = @LIBUSB_CFLAGS@ $(WARN_CFLAGS) -x52test_create_device_list_LDFLAGS = $(WARN_LDFLAGS) - -x52test_log_actions_SOURCES = util/log_actions.c $(libusbx52_la_SOURCES) -x52test_log_actions_CFLAGS = @X52_INCLUDE@ @LIBUSB_CFLAGS@ $(WARN_CFLAGS) -x52test_log_actions_LDFLAGS = $(WARN_LDFLAGS) - -EXTRA_DIST = README.md libusbx52.h diff --git a/lib/libx52util/Makefile.am b/lib/libx52util/Makefile.am deleted file mode 100644 index 739eca2..0000000 --- a/lib/libx52util/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -# Automake for libx52util -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -ACLOCAL_AMFLAGS = -I m4 - -lib_LTLIBRARIES = libx52util.la - -# libx52 utility library -# This library provides extra utilities for ease of use -nodist_libx52util_la_SOURCES = util_char_map.c -libx52util_la_SOURCES = x52_char_map_lookup.c -libx52util_la_CFLAGS = -I $(top_srcdir)/lib/libx52 $(WARN_CFLAGS) -libx52util_la_LDFLAGS = -version-info 1:0:0 $(WARN_LDFLAGS) -libx52util_la_LIBADD = ../libx52/libx52.la - -# Header files that need to be copied -x52includedir = $(includedir)/libx52 -x52include_HEADERS = libx52util.h - -# Extra files that need to be in the distribution -EXTRA_DIST = x52_char_map.cfg \ - x52_char_map.h \ - x52_char_map_gen.py - -# Autogenerated file that needs to be cleaned up -CLEANFILES = util_char_map.c -util_char_map.c: $(srcdir)/x52_char_map.cfg x52_char_map_gen.py - $(AM_V_GEN) $(PYTHON) $(srcdir)/x52_char_map_gen.py $(srcdir)/x52_char_map.cfg $@ - diff --git a/lib/pinelog/.gitignore b/lib/pinelog/.gitignore new file mode 100644 index 0000000..6166c2c --- /dev/null +++ b/lib/pinelog/.gitignore @@ -0,0 +1,37 @@ +# Compiled object files +*.o + +# Generated objects (source, executables, tarballs, etc.) + +# Vim swap files +.*.swp + +# Autotools objects +.deps +.dirstamp +.libs +ar-lib +autom4te.cache +m4 +compile +config.* +configure +depcomp +install-sh +libtool +ltmain.sh +missing +Makefile +Makefile.in +*.la +*.lo +*.m4 +stamp-h1 +tap-driver.sh +test-driver +*.log +*.trs +*.pc + +# Build directory +/build/ diff --git a/lib/pinelog/LICENSE b/lib/pinelog/LICENSE new file mode 100644 index 0000000..ff3c685 --- /dev/null +++ b/lib/pinelog/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Nirenjan Krishnan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/pinelog/Makefile.am b/lib/pinelog/Makefile.am new file mode 100644 index 0000000..2eea553 --- /dev/null +++ b/lib/pinelog/Makefile.am @@ -0,0 +1,134 @@ +# Top level Automake for pinelog +# +# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: MIT + +ACLOCAL_AMFLAGS = -I m4 + +# Extra files that need to be in the distribution +EXTRA_DIST = \ + LICENSE \ + README.md \ + pinelog.h + +noinst_LTLIBRARIES = libpinelog.la + +# pinelog logging library +libpinelog_la_SOURCES = pinelog.c +libpinelog_la_CFLAGS = @PINELOG_CFLAGS@ $(WARN_CFLAGS) -I $(top_builddir) +libpinelog_la_LDFLAGS = $(WARN_LDFLAGS) + +test_SRCFILES = test_pinelog.c $(libpinelog_la_SOURCES) +bench_SRCFILES = bench_pinelog.c $(libpinelog_la_SOURCES) +test_CFLAGS = \ + -DPINELOG_FATAL_STR='"F"' \ + -DPINELOG_ERROR_STR='"E"' \ + -DPINELOG_WARNING_STR='"W"' \ + -DPINELOG_INFO_STR='"I"' \ + -DPINELOG_DEBUG_STR='"D"' \ + -DPINELOG_TRACE_STR='"T"' \ + -DPINELOG_DEFAULT_LEVEL=PINELOG_LVL_TRACE \ + -DPINELOG_DEFAULT_STREAM=stderr \ + -DPINELOG_TEST -I $(top_builddir) + +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh +TESTS = \ + test_ts_lvl_tr \ + test_ts_lvl_notr \ + test_ts_nolvl_tr \ + test_ts_nolvl_notr \ + test_nots_lvl_tr \ + test_nots_lvl_notr \ + test_nots_nolvl_tr \ + test_nots_nolvl_notr \ + bench_ts_lvl_tr \ + bench_ts_lvl_notr \ + bench_ts_nolvl_tr \ + bench_ts_nolvl_notr \ + bench_nots_lvl_tr \ + bench_nots_lvl_notr \ + bench_nots_nolvl_tr \ + bench_nots_nolvl_notr + +check_PROGRAMS = $(TESTS) +test_ts_lvl_tr_SOURCES = $(test_SRCFILES) +test_ts_lvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1 +test_ts_lvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +test_ts_lvl_notr_SOURCES = $(test_SRCFILES) +test_ts_lvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=0 +test_ts_lvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +test_ts_nolvl_tr_SOURCES = $(test_SRCFILES) +test_ts_nolvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=1 +test_ts_nolvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +test_ts_nolvl_notr_SOURCES = $(test_SRCFILES) +test_ts_nolvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=0 +test_ts_nolvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +test_nots_lvl_tr_SOURCES = $(test_SRCFILES) +test_nots_lvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1 +test_nots_lvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +test_nots_lvl_notr_SOURCES = $(test_SRCFILES) +test_nots_lvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=0 +test_nots_lvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +test_nots_nolvl_tr_SOURCES = $(test_SRCFILES) +test_nots_nolvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=1 +test_nots_nolvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +test_nots_nolvl_notr_SOURCES = $(test_SRCFILES) +test_nots_nolvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=0 +test_nots_nolvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +bench_ts_lvl_tr_SOURCES = $(bench_SRCFILES) +bench_ts_lvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1 +bench_ts_lvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +bench_ts_lvl_notr_SOURCES = $(bench_SRCFILES) +bench_ts_lvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=0 +bench_ts_lvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +bench_ts_nolvl_tr_SOURCES = $(bench_SRCFILES) +bench_ts_nolvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=1 +bench_ts_nolvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +bench_ts_nolvl_notr_SOURCES = $(bench_SRCFILES) +bench_ts_nolvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=0 +bench_ts_nolvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +bench_nots_lvl_tr_SOURCES = $(bench_SRCFILES) +bench_nots_lvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1 +bench_nots_lvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +bench_nots_lvl_notr_SOURCES = $(bench_SRCFILES) +bench_nots_lvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=0 +bench_nots_lvl_notr_LDFLAGS = $(WARN_LDFLAGS) + +bench_nots_nolvl_tr_SOURCES = $(bench_SRCFILES) +bench_nots_nolvl_tr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=1 +bench_nots_nolvl_tr_LDFLAGS = $(WARN_LDFLAGS) + +bench_nots_nolvl_notr_SOURCES = $(bench_SRCFILES) +bench_nots_nolvl_notr_CFLAGS = $(WARN_CFLAGS) $(test_CFLAGS) \ + -DPINELOG_SHOW_DATE=0 -DPINELOG_SHOW_LEVEL=0 -DPINELOG_SHOW_BACKTRACE=0 +bench_nots_nolvl_notr_LDFLAGS = $(WARN_LDFLAGS) + diff --git a/lib/pinelog/README.md b/lib/pinelog/README.md new file mode 100644 index 0000000..c8423c2 --- /dev/null +++ b/lib/pinelog/README.md @@ -0,0 +1,135 @@ +Pinelog - a lightweight logging API +=================================== + +Pinelog is a lightweight logging API for C programs that's designed to be +included in your program source code. Parameters for Pinelog are configured at +build time by means of preprocessor flags. + +# Usage +## Logging macros + +Pinelog uses `printf` style formatting, using the following list of macros. The +macro indicates the level at which the message is logged. + +* `PINELOG_FATAL` +* `PINELOG_ERROR` +* `PINELOG_WARN` +* `PINELOG_INFO` +* `PINELOG_DEBUG` +* `PINELOG_TRACE` + +**Note:** `PINELOG_FATAL` is used when the program encounters a fatal condition +and needs to abort. This will log the fatal message and terminate the program +with an exit code of 1. + +### Example + +```C +PINELOG_INFO("configuration file %s not found, using defaults", config_file); +``` + +## Logging levels + +The default logging level is `ERROR`, and this can be controlled by the +preprocessor flag `PINELOG_DEFAULT_LEVEL`. + +The program can control the level at which messages can be logged at runtime, +by using the `pinelog_set_level` function. This function takes in the level +definition, which is one of the following, in increasing order of priority. + +* `PINELOG_LVL_TRACE` +* `PINELOG_LVL_DEBUG` +* `PINELOG_LVL_INFO` +* `PINELOG_LVL_WARNING` +* `PINELOG_LVL_ERROR` +* `PINELOG_LVL_FATAL` +* `PINELOG_LVL_NONE` + +Setting the level to a given priority suppresses all log messages of lower +priority, i.e., if the level is set to `PINELOG_LVL_ERROR`, messages at +`WARNING` level and below will be suppressed, but `ERROR` and `FATAL` messages +will be logged. + +**Note:** `PINELOG_LVL_NONE` suppresses all log messages, but `PINELOG_FATAL` +will still terminate the program, even though nothing is logged. + +### Example + +```C +pinelog_set_level(PINELOG_LVL_WARNING); +``` + +``` +-DPINELOG_DEFAULT_LEVEL=PINELOG_LVL_WARNING +``` + +## Output redirection + +Pinelog defaults to writing the log messages to standard output, and this can +be controlled by the preprocessor flag `PINELOG_DEFAULT_STREAM`. + +However, the application can redirect log messages at runtime to a different +`FILE *` stream, or to a file by using one of the following two methods: + +```C +FILE *out = fopen("/run/app.fifo", "w"); +pinelog_set_output_stream(out); +pinelog_set_output_file("/var/log/app.log"); +``` + +``` +-DPINELOG_DEFAULT_STREAM=stderr +``` + +## Logging format + +Pinelog uses an opinionated logging format that is fixed as follows. Fields +within `[]` are optional and controlled by build time flags. + + [2021-07-14 11:08:04 ][ERROR: ][./test_pinelog.c:108 ]formatted message. + +The program can be controlled by the following preprocessor flags, all of which +default to `0` (disabled). Set the flag to `1` to enable it. + +* `PINELOG_SHOW_DATE` - Display the ISO 8601 date and time when the message is + logged. +* `PINELOG_SHOW_LEVEL` - Display the level at which the message is logged. +* `PINELOG_SHOW_BACKTRACE` - Display the file and line where the message is + logged. + +Set these flags by using the `-D` compiler argument, .e.g. +`-DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_DATE=1` + +### Level strings + +The application can control the level strings displayed by means of preprocessor +flags, if the application wishes to display the log messages in a language other +than English. This can be achieved by means of the following preprocessor +definitions. + +* `PINELOG_FATAL_STR` +* `PINELOG_ERROR_STR` +* `PINELOG_WARNING_STR` +* `PINELOG_INFO_STR` +* `PINELOG_DEBUG_STR` +* `PINELOG_TRACE_STR` + +### Example + +``` +-DPINELOG_ERROR_STR=\"E\" -DPINELOG_FATAL_STR=\"F\" +``` + +# Integrating Pinelog + +Pinelog is intended to be integrated into your application source tree, either +by means of including the sources directly, or by including the repository as +a Git submodule or subtree. + +The default build of Pinelog uses an autotools generated `config.h` file, which +includes checks for the following GCC attributes. If you don't care about these, +then either create a dummy config.h which includes the macros +`HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR`, `HAVE_FUNC_ATTRIBUTE_DESTRUCTOR` and +`HAVE_FUNC_ATTRIBUTE_FORMAT`, or use the `AX_GCC_FUNC_ATTRIBUTE` macro to check +for the `constructor`, `destructor` and `format` attributes in your +application's `configure.ac` file. diff --git a/lib/pinelog/autogen.sh b/lib/pinelog/autogen.sh new file mode 100755 index 0000000..e10d140 --- /dev/null +++ b/lib/pinelog/autogen.sh @@ -0,0 +1,3 @@ +#!/bin/sh -x + +autoreconf --install diff --git a/lib/pinelog/bench_pinelog.c b/lib/pinelog/bench_pinelog.c new file mode 100644 index 0000000..419f61b --- /dev/null +++ b/lib/pinelog/bench_pinelog.c @@ -0,0 +1,83 @@ +/* + * Pinelog lightweight logging library - test harness + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: MIT + */ + + +#define pinelog_exit(_) +#include "pinelog.h" + +#include +#include +#include +#include + +#define BENCH_COUNT 100000 + +static void print_time_difference(const char *type, struct timespec *ts) +{ + struct timespec ret; + uint64_t timeper; + uint64_t tp_usec; + uint64_t tp_nsec; + + // ts is a pointer to a 2 element array, second is always later + ret.tv_sec = ts[1].tv_sec - ts[0].tv_sec; + ret.tv_nsec = ts[1].tv_nsec - ts[0].tv_nsec; + + if (ts[0].tv_nsec > ts[1].tv_nsec) { + ret.tv_nsec += 1000000000; + ret.tv_sec--; + } + + timeper = (ret.tv_sec * 1000000000 + ret.tv_nsec) / BENCH_COUNT; + tp_usec = timeper / 1000; + tp_nsec = timeper % 1000; + + printf("# %s %"PRIu64".%03"PRIu64"\u03BCs/log (Total %lu.%09lds)\n", + type, tp_usec, tp_nsec, ret.tv_sec, ret.tv_nsec); +} + +int main(int argc, char **argv) +{ + struct timespec ts_wall[2]; + struct timespec ts_cpu[2]; + int i; + + /* Set up defaults */ + pinelog_set_level(PINELOG_LVL_ERROR); + pinelog_set_output_file("/dev/null"); + + printf("# Timing logging for %u iterations\n", BENCH_COUNT); + + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_cpu[0]) < 0) { + perror("clock_gettime cputime 0"); + return 1; + } + if (clock_gettime(CLOCK_MONOTONIC, &ts_wall[0]) < 0) { + perror("clock_gettime monotonic 0"); + return 1; + } + + for (i = 0; i < BENCH_COUNT; i++) { + PINELOG_ERROR("Testing error log #%u of %u", i, BENCH_COUNT); + } + + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_cpu[1]); + clock_gettime(CLOCK_MONOTONIC, &ts_wall[1]); + + // Add a test plan and to avoid the TAP harness from flagging this as a + // failed test. + puts("1..1"); + printf("ok 1 Benchmark pinelog %stimestamp, %slevel, %sbacktrace\n", + PINELOG_SHOW_DATE ? "": "no ", + PINELOG_SHOW_LEVEL ? "": "no ", + PINELOG_SHOW_BACKTRACE ? "": "no "); + print_time_difference("cpu time", ts_cpu); + print_time_difference("wall time", ts_wall); + + return 0; +} diff --git a/lib/pinelog/configure.ac b/lib/pinelog/configure.ac new file mode 100644 index 0000000..b9d83a7 --- /dev/null +++ b/lib/pinelog/configure.ac @@ -0,0 +1,29 @@ +# Autoconf settings for pinelog +# +# Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: MIT + +AC_INIT([pinelog], [1.0.0], [nirenjan@nirenjan.org]) +AC_CONFIG_MACRO_DIR([m4]) +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +AC_REQUIRE_AUX_FILE([tap-driver.sh]) +AC_PROG_CC +AC_PROG_CC_STDC +AC_PROG_AWK +AM_PROG_AR +LT_INIT +PKG_PROG_PKG_CONFIG +PKG_INSTALLDIR +AX_COMPILER_FLAGS +AX_GCC_FUNC_ATTRIBUTE([constructor]) +AX_GCC_FUNC_ATTRIBUTE([destructor]) +AX_GCC_FUNC_ATTRIBUTE([format]) + +AC_SUBST([PINELOG_CFLAGS]) + +# Configuration headers +AC_CONFIG_HEADERS([config.h]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/lib/pinelog/m4/ax_append_compile_flags.m4 b/lib/pinelog/m4/ax_append_compile_flags.m4 new file mode 100644 index 0000000..9c85635 --- /dev/null +++ b/lib/pinelog/m4/ax_append_compile_flags.m4 @@ -0,0 +1,46 @@ +# ============================================================================ +# https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# For every FLAG1, FLAG2 it is checked whether the compiler works with the +# flag. If it does, the flag is added FLAGS-VARIABLE +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. During the check the flag is always added to the +# current language's flags. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: This macro depends on the AX_APPEND_FLAG and +# AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with +# AX_APPEND_LINK_FLAGS. +# +# LICENSE +# +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AC_DEFUN([AX_APPEND_COMPILE_FLAGS], +[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) +AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) +for flag in $1; do + AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4]) +done +])dnl AX_APPEND_COMPILE_FLAGS diff --git a/lib/pinelog/m4/ax_append_flag.m4 b/lib/pinelog/m4/ax_append_flag.m4 new file mode 100644 index 0000000..dd6d8b6 --- /dev/null +++ b/lib/pinelog/m4/ax_append_flag.m4 @@ -0,0 +1,50 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) +# +# DESCRIPTION +# +# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space +# added in between. +# +# If FLAGS-VARIABLE is not specified, the current language's flags (e.g. +# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains +# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly +# FLAG. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AC_DEFUN([AX_APPEND_FLAG], +[dnl +AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF +AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) +AS_VAR_SET_IF(FLAGS,[ + AS_CASE([" AS_VAR_GET(FLAGS) "], + [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], + [ + AS_VAR_APPEND(FLAGS,[" $1"]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) + ], + [ + AS_VAR_SET(FLAGS,[$1]) + AC_RUN_LOG([: FLAGS="$FLAGS"]) + ]) +AS_VAR_POPDEF([FLAGS])dnl +])dnl AX_APPEND_FLAG diff --git a/lib/pinelog/m4/ax_append_link_flags.m4 b/lib/pinelog/m4/ax_append_link_flags.m4 new file mode 100644 index 0000000..99b9fa5 --- /dev/null +++ b/lib/pinelog/m4/ax_append_link_flags.m4 @@ -0,0 +1,44 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_append_link_flags.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_APPEND_LINK_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# For every FLAG1, FLAG2 it is checked whether the linker works with the +# flag. If it does, the flag is added FLAGS-VARIABLE +# +# If FLAGS-VARIABLE is not specified, the linker's flags (LDFLAGS) is +# used. During the check the flag is always added to the linker's flags. +# +# If EXTRA-FLAGS is defined, it is added to the linker's default flags +# when the check is done. The check is thus made with the flags: "LDFLAGS +# EXTRA-FLAGS FLAG". This can for example be used to force the linker to +# issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: This macro depends on the AX_APPEND_FLAG and AX_CHECK_LINK_FLAG. +# Please keep this macro in sync with AX_APPEND_COMPILE_FLAGS. +# +# LICENSE +# +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AC_DEFUN([AX_APPEND_LINK_FLAGS], +[AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) +AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) +for flag in $1; do + AX_CHECK_LINK_FLAG([$flag], [AX_APPEND_FLAG([$flag], [m4_default([$2], [LDFLAGS])])], [], [$3], [$4]) +done +])dnl AX_APPEND_LINK_FLAGS diff --git a/lib/pinelog/m4/ax_check_compile_flag.m4 b/lib/pinelog/m4/ax_check_compile_flag.m4 new file mode 100644 index 0000000..bd753b3 --- /dev/null +++ b/lib/pinelog/m4/ax_check_compile_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/lib/pinelog/m4/ax_check_link_flag.m4 b/lib/pinelog/m4/ax_check_link_flag.m4 new file mode 100644 index 0000000..03a30ce --- /dev/null +++ b/lib/pinelog/m4/ax_check_link_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the linker or gives an error. +# (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the linker's default flags +# when the check is done. The check is thus made with the flags: "LDFLAGS +# EXTRA-FLAGS FLAG". This can for example be used to force the linker to +# issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_LINK_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_LINK_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl +AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ + ax_check_save_flags=$LDFLAGS + LDFLAGS="$LDFLAGS $4 $1" + AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + LDFLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_LINK_FLAGS diff --git a/lib/pinelog/m4/ax_compiler_flags.m4 b/lib/pinelog/m4/ax_compiler_flags.m4 new file mode 100644 index 0000000..ddb0456 --- /dev/null +++ b/lib/pinelog/m4/ax_compiler_flags.m4 @@ -0,0 +1,158 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COMPILER_FLAGS([CFLAGS-VARIABLE], [LDFLAGS-VARIABLE], [IS-RELEASE], [EXTRA-BASE-CFLAGS], [EXTRA-YES-CFLAGS], [UNUSED], [UNUSED], [UNUSED], [EXTRA-BASE-LDFLAGS], [EXTRA-YES-LDFLAGS], [UNUSED], [UNUSED], [UNUSED]) +# +# DESCRIPTION +# +# Check for the presence of an --enable-compile-warnings option to +# configure, defaulting to "error" in normal operation, or "yes" if +# IS-RELEASE is equal to "yes". Return the value in the variable +# $ax_enable_compile_warnings. +# +# Depending on the value of --enable-compile-warnings, different compiler +# warnings are checked to see if they work with the current compiler and, +# if so, are appended to CFLAGS-VARIABLE and LDFLAGS-VARIABLE. This +# allows a consistent set of baseline compiler warnings to be used across +# a code base, irrespective of any warnings enabled locally by individual +# developers. By standardising the warnings used by all developers of a +# project, the project can commit to a zero-warnings policy, using -Werror +# to prevent compilation if new warnings are introduced. This makes +# catching bugs which are flagged by warnings a lot easier. +# +# By providing a consistent --enable-compile-warnings argument across all +# projects using this macro, continuous integration systems can easily be +# configured the same for all projects. Automated systems or build +# systems aimed at beginners may want to pass the --disable-Werror +# argument to unconditionally prevent warnings being fatal. +# +# --enable-compile-warnings can take the values: +# +# * no: Base compiler warnings only; not even -Wall. +# * yes: The above, plus a broad range of useful warnings. +# * error: The above, plus -Werror so that all warnings are fatal. +# Use --disable-Werror to override this and disable fatal +# warnings. +# +# The set of base and enabled flags can be augmented using the +# EXTRA-*-CFLAGS and EXTRA-*-LDFLAGS variables, which are tested and +# appended to the output variable if --enable-compile-warnings is not +# "no". Flags should not be disabled using these arguments, as the entire +# point of AX_COMPILER_FLAGS is to enforce a consistent set of useful +# compiler warnings on code, using warnings which have been chosen for low +# false positive rates. If a compiler emits false positives for a +# warning, a #pragma should be used in the code to disable the warning +# locally. See: +# +# https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas +# +# The EXTRA-* variables should only be used to supply extra warning flags, +# and not general purpose compiler flags, as they are controlled by +# configure options such as --disable-Werror. +# +# IS-RELEASE can be used to disable -Werror when making a release, which +# is useful for those hairy moments when you just want to get the release +# done as quickly as possible. Set it to "yes" to disable -Werror. By +# default, it uses the value of $ax_is_release, so if you are using the +# AX_IS_RELEASE macro, there is no need to pass this parameter. For +# example: +# +# AX_IS_RELEASE([git-directory]) +# AX_COMPILER_FLAGS() +# +# CFLAGS-VARIABLE defaults to WARN_CFLAGS, and LDFLAGS-VARIABLE defaults +# to WARN_LDFLAGS. Both variables are AC_SUBST-ed by this macro, but must +# be manually added to the CFLAGS and LDFLAGS variables for each target in +# the code base. +# +# If C++ language support is enabled with AC_PROG_CXX, which must occur +# before this macro in configure.ac, warning flags for the C++ compiler +# are AC_SUBST-ed as WARN_CXXFLAGS, and must be manually added to the +# CXXFLAGS variables for each target in the code base. EXTRA-*-CFLAGS can +# be used to augment the base and enabled flags. +# +# Warning flags for g-ir-scanner (from GObject Introspection) are +# AC_SUBST-ed as WARN_SCANNERFLAGS. This variable must be manually added +# to the SCANNERFLAGS variable for each GIR target in the code base. If +# extra g-ir-scanner flags need to be enabled, the AX_COMPILER_FLAGS_GIR +# macro must be invoked manually. +# +# AX_COMPILER_FLAGS may add support for other tools in future, in addition +# to the compiler and linker. No extra EXTRA-* variables will be added +# for those tools, and all extra support will still use the single +# --enable-compile-warnings configure option. For finer grained control +# over the flags for individual tools, use AX_COMPILER_FLAGS_CFLAGS, +# AX_COMPILER_FLAGS_LDFLAGS and AX_COMPILER_FLAGS_* for new tools. +# +# The UNUSED variables date from a previous version of this macro, and are +# automatically appended to the preceding non-UNUSED variable. They should +# be left empty in new uses of the macro. +# +# LICENSE +# +# Copyright (c) 2014, 2015 Philip Withnall +# Copyright (c) 2015 David King +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 14 + +# _AX_COMPILER_FLAGS_LANG([LANGNAME]) +m4_defun([_AX_COMPILER_FLAGS_LANG], +[m4_ifdef([_AX_COMPILER_FLAGS_LANG_]$1[_enabled], [], + [m4_define([_AX_COMPILER_FLAGS_LANG_]$1[_enabled], [])dnl + AX_REQUIRE_DEFINED([AX_COMPILER_FLAGS_]$1[FLAGS])])dnl +]) + +AC_DEFUN([AX_COMPILER_FLAGS],[ + # C support is enabled by default. + _AX_COMPILER_FLAGS_LANG([C]) + # Only enable C++ support if AC_PROG_CXX is called. The redefinition of + # AC_PROG_CXX is so that a fatal error is emitted if this macro is called + # before AC_PROG_CXX, which would otherwise cause no C++ warnings to be + # checked. + AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AX_COMPILER_FLAGS_LANG([CXX])], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[_AX_COMPILER_FLAGS_LANG([CXX])])]) + AX_REQUIRE_DEFINED([AX_COMPILER_FLAGS_LDFLAGS]) + + # Default value for IS-RELEASE is $ax_is_release + ax_compiler_flags_is_release=m4_tolower(m4_normalize(ifelse([$3],, + [$ax_is_release], + [$3]))) + + AC_ARG_ENABLE([compile-warnings], + AS_HELP_STRING([--enable-compile-warnings=@<:@no/yes/error@:>@], + [Enable compiler warnings and errors]),, + [AS_IF([test "$ax_compiler_flags_is_release" = "yes"], + [enable_compile_warnings="yes"], + [enable_compile_warnings="error"])]) + AC_ARG_ENABLE([Werror], + AS_HELP_STRING([--disable-Werror], + [Unconditionally make all compiler warnings non-fatal]),, + [enable_Werror=maybe]) + + # Return the user's chosen warning level + AS_IF([test "$enable_Werror" = "no" -a \ + "$enable_compile_warnings" = "error"],[ + enable_compile_warnings="yes" + ]) + + ax_enable_compile_warnings=$enable_compile_warnings + + AX_COMPILER_FLAGS_CFLAGS([$1],[$ax_compiler_flags_is_release], + [$4],[$5 $6 $7 $8]) + m4_ifdef([_AX_COMPILER_FLAGS_LANG_CXX_enabled], + [AX_COMPILER_FLAGS_CXXFLAGS([WARN_CXXFLAGS], + [$ax_compiler_flags_is_release], + [$4],[$5 $6 $7 $8])]) + AX_COMPILER_FLAGS_LDFLAGS([$2],[$ax_compiler_flags_is_release], + [$9],[$10 $11 $12 $13]) + AX_COMPILER_FLAGS_GIR([WARN_SCANNERFLAGS],[$ax_compiler_flags_is_release]) +])dnl AX_COMPILER_FLAGS diff --git a/lib/pinelog/m4/ax_compiler_flags_cflags.m4 b/lib/pinelog/m4/ax_compiler_flags_cflags.m4 new file mode 100644 index 0000000..916f918 --- /dev/null +++ b/lib/pinelog/m4/ax_compiler_flags_cflags.m4 @@ -0,0 +1,161 @@ +# ============================================================================= +# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html +# ============================================================================= +# +# SYNOPSIS +# +# AX_COMPILER_FLAGS_CFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS]) +# +# DESCRIPTION +# +# Add warning flags for the C compiler to VARIABLE, which defaults to +# WARN_CFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be +# manually added to the CFLAGS variable for each target in the code base. +# +# This macro depends on the environment set up by AX_COMPILER_FLAGS. +# Specifically, it uses the value of $ax_enable_compile_warnings to decide +# which flags to enable. +# +# LICENSE +# +# Copyright (c) 2014, 2015 Philip Withnall +# Copyright (c) 2017, 2018 Reini Urban +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 17 + +AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[ + AC_REQUIRE([AC_PROG_SED]) + AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS]) + AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) + AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) + + # Variable names + m4_define([ax_warn_cflags_variable], + [m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))]) + + AC_LANG_PUSH([C]) + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ + [#ifndef __cplusplus + #error "no C++" + #endif]])], + [ax_compiler_cxx=yes;], + [ax_compiler_cxx=no;]) + + # Always pass -Werror=unknown-warning-option to get Clang to fail on bad + # flags, otherwise they are always appended to the warn_cflags variable, and + # Clang warns on them for every compilation unit. + # If this is passed to GCC, it will explode, so the flag must be enabled + # conditionally. + AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[ + ax_compiler_flags_test="-Werror=unknown-warning-option" + ],[ + ax_compiler_flags_test="" + ]) + + # Check that -Wno-suggest-attribute=format is supported + AX_CHECK_COMPILE_FLAG([-Wno-suggest-attribute=format],[ + ax_compiler_no_suggest_attribute_flags="-Wno-suggest-attribute=format" + ],[ + ax_compiler_no_suggest_attribute_flags="" + ]) + + # Base flags + AX_APPEND_COMPILE_FLAGS([ dnl + -fno-strict-aliasing dnl + $3 dnl + ],ax_warn_cflags_variable,[$ax_compiler_flags_test]) + + AS_IF([test "$ax_enable_compile_warnings" != "no"],[ + if test "$ax_compiler_cxx" = "no" ; then + # C-only flags. Warn in C++ + AX_APPEND_COMPILE_FLAGS([ dnl + -Wnested-externs dnl + -Wmissing-prototypes dnl + -Wstrict-prototypes dnl + -Wdeclaration-after-statement dnl + -Wimplicit-function-declaration dnl + -Wold-style-definition dnl + -Wjump-misses-init dnl + ],ax_warn_cflags_variable,[$ax_compiler_flags_test]) + fi + + # "yes" flags + AX_APPEND_COMPILE_FLAGS([ dnl + -Wall dnl + -Wextra dnl + -Wundef dnl + -Wwrite-strings dnl + -Wpointer-arith dnl + -Wmissing-declarations dnl + -Wredundant-decls dnl + -Wno-unused-parameter dnl + -Wno-missing-field-initializers dnl + -Wformat=2 dnl + -Wcast-align dnl + -Wformat-nonliteral dnl + -Wformat-security dnl + -Wsign-compare dnl + -Wstrict-aliasing dnl + -Wshadow dnl + -Winline dnl + -Wpacked dnl + -Wmissing-format-attribute dnl + -Wmissing-noreturn dnl + -Winit-self dnl + -Wredundant-decls dnl + -Wmissing-include-dirs dnl + -Wunused-but-set-variable dnl + -Warray-bounds dnl + -Wreturn-type dnl + -Wswitch-enum dnl + -Wswitch-default dnl + -Wduplicated-cond dnl + -Wduplicated-branches dnl + -Wlogical-op dnl + -Wrestrict dnl + -Wnull-dereference dnl + -Wdouble-promotion dnl + $4 dnl + $5 dnl + $6 dnl + $7 dnl + ],ax_warn_cflags_variable,[$ax_compiler_flags_test]) + ]) + AS_IF([test "$ax_enable_compile_warnings" = "error"],[ + # "error" flags; -Werror has to be appended unconditionally because + # it's not possible to test for + # + # suggest-attribute=format is disabled because it gives too many false + # positives + AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable) + + AX_APPEND_COMPILE_FLAGS([ dnl + [$ax_compiler_no_suggest_attribute_flags] dnl + ],ax_warn_cflags_variable,[$ax_compiler_flags_test]) + ]) + + # In the flags below, when disabling specific flags, always add *both* + # -Wno-foo and -Wno-error=foo. This fixes the situation where (for example) + # we enable -Werror, disable a flag, and a build bot passes CFLAGS=-Wall, + # which effectively turns that flag back on again as an error. + for flag in $ax_warn_cflags_variable; do + AS_CASE([$flag], + [-Wno-*=*],[], + [-Wno-*],[ + AX_APPEND_COMPILE_FLAGS([-Wno-error=$(AS_ECHO([$flag]) | $SED 's/^-Wno-//')], + ax_warn_cflags_variable, + [$ax_compiler_flags_test]) + ]) + done + + AC_LANG_POP([C]) + + # Substitute the variables + AC_SUBST(ax_warn_cflags_variable) +])dnl AX_COMPILER_FLAGS diff --git a/lib/pinelog/m4/ax_compiler_flags_gir.m4 b/lib/pinelog/m4/ax_compiler_flags_gir.m4 new file mode 100644 index 0000000..5b4924a --- /dev/null +++ b/lib/pinelog/m4/ax_compiler_flags_gir.m4 @@ -0,0 +1,60 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_gir.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COMPILER_FLAGS_GIR([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS]) +# +# DESCRIPTION +# +# Add warning flags for the g-ir-scanner (from GObject Introspection) to +# VARIABLE, which defaults to WARN_SCANNERFLAGS. VARIABLE is AC_SUBST-ed +# by this macro, but must be manually added to the SCANNERFLAGS variable +# for each GIR target in the code base. +# +# This macro depends on the environment set up by AX_COMPILER_FLAGS. +# Specifically, it uses the value of $ax_enable_compile_warnings to decide +# which flags to enable. +# +# LICENSE +# +# Copyright (c) 2015 Philip Withnall +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_COMPILER_FLAGS_GIR],[ + AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) + + # Variable names + m4_define([ax_warn_scannerflags_variable], + [m4_normalize(ifelse([$1],,[WARN_SCANNERFLAGS],[$1]))]) + + # Base flags + AX_APPEND_FLAG([$3],ax_warn_scannerflags_variable) + + AS_IF([test "$ax_enable_compile_warnings" != "no"],[ + # "yes" flags + AX_APPEND_FLAG([ dnl + --warn-all dnl + $4 dnl + $5 dnl + $6 dnl + $7 dnl + ],ax_warn_scannerflags_variable) + ]) + AS_IF([test "$ax_enable_compile_warnings" = "error"],[ + # "error" flags + AX_APPEND_FLAG([ dnl + --warn-error dnl + ],ax_warn_scannerflags_variable) + ]) + + # Substitute the variables + AC_SUBST(ax_warn_scannerflags_variable) +])dnl AX_COMPILER_FLAGS diff --git a/lib/pinelog/m4/ax_compiler_flags_ldflags.m4 b/lib/pinelog/m4/ax_compiler_flags_ldflags.m4 new file mode 100644 index 0000000..976d119 --- /dev/null +++ b/lib/pinelog/m4/ax_compiler_flags_ldflags.m4 @@ -0,0 +1,111 @@ +# ============================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html +# ============================================================================== +# +# SYNOPSIS +# +# AX_COMPILER_FLAGS_LDFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS]) +# +# DESCRIPTION +# +# Add warning flags for the linker to VARIABLE, which defaults to +# WARN_LDFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be +# manually added to the LDFLAGS variable for each target in the code base. +# +# This macro depends on the environment set up by AX_COMPILER_FLAGS. +# Specifically, it uses the value of $ax_enable_compile_warnings to decide +# which flags to enable. +# +# LICENSE +# +# Copyright (c) 2014, 2015 Philip Withnall +# Copyright (c) 2017, 2018 Reini Urban +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 9 + +AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[ + AX_REQUIRE_DEFINED([AX_APPEND_LINK_FLAGS]) + AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) + AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) + AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) + + # Variable names + m4_define([ax_warn_ldflags_variable], + [m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))]) + + # Always pass -Werror=unknown-warning-option to get Clang to fail on bad + # flags, otherwise they are always appended to the warn_ldflags variable, + # and Clang warns on them for every compilation unit. + # If this is passed to GCC, it will explode, so the flag must be enabled + # conditionally. + AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[ + ax_compiler_flags_test="-Werror=unknown-warning-option" + ],[ + ax_compiler_flags_test="" + ]) + + AX_CHECK_LINK_FLAG([-Wl,--as-needed], [ + AX_APPEND_LINK_FLAGS([-Wl,--as-needed], + [AM_LDFLAGS],[$ax_compiler_flags_test]) + ]) + AX_CHECK_LINK_FLAG([-Wl,-z,relro], [ + AX_APPEND_LINK_FLAGS([-Wl,-z,relro], + [AM_LDFLAGS],[$ax_compiler_flags_test]) + ]) + AX_CHECK_LINK_FLAG([-Wl,-z,now], [ + AX_APPEND_LINK_FLAGS([-Wl,-z,now], + [AM_LDFLAGS],[$ax_compiler_flags_test]) + ]) + AX_CHECK_LINK_FLAG([-Wl,-z,noexecstack], [ + AX_APPEND_LINK_FLAGS([-Wl,-z,noexecstack], + [AM_LDFLAGS],[$ax_compiler_flags_test]) + ]) + # textonly, retpolineplt not yet + + # macOS and cygwin linker do not have --as-needed + AX_CHECK_LINK_FLAG([-Wl,--no-as-needed], [ + ax_compiler_flags_as_needed_option="-Wl,--no-as-needed" + ], [ + ax_compiler_flags_as_needed_option="" + ]) + + # macOS linker speaks with a different accent + ax_compiler_flags_fatal_warnings_option="" + AX_CHECK_LINK_FLAG([-Wl,--fatal-warnings], [ + ax_compiler_flags_fatal_warnings_option="-Wl,--fatal-warnings" + ]) + AX_CHECK_LINK_FLAG([-Wl,-fatal_warnings], [ + ax_compiler_flags_fatal_warnings_option="-Wl,-fatal_warnings" + ]) + + # Base flags + AX_APPEND_LINK_FLAGS([ dnl + $ax_compiler_flags_as_needed_option dnl + $3 dnl + ],ax_warn_ldflags_variable,[$ax_compiler_flags_test]) + + AS_IF([test "$ax_enable_compile_warnings" != "no"],[ + # "yes" flags + AX_APPEND_LINK_FLAGS([$4 $5 $6 $7], + ax_warn_ldflags_variable, + [$ax_compiler_flags_test]) + ]) + AS_IF([test "$ax_enable_compile_warnings" = "error"],[ + # "error" flags; -Werror has to be appended unconditionally because + # it's not possible to test for + # + # suggest-attribute=format is disabled because it gives too many false + # positives + AX_APPEND_LINK_FLAGS([ dnl + $ax_compiler_flags_fatal_warnings_option dnl + ],ax_warn_ldflags_variable,[$ax_compiler_flags_test]) + ]) + + # Substitute the variables + AC_SUBST(ax_warn_ldflags_variable) +])dnl AX_COMPILER_FLAGS diff --git a/lib/pinelog/m4/ax_gcc_func_attribute.m4 b/lib/pinelog/m4/ax_gcc_func_attribute.m4 new file mode 100644 index 0000000..fa4e089 --- /dev/null +++ b/lib/pinelog/m4/ax_gcc_func_attribute.m4 @@ -0,0 +1,242 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) +# +# DESCRIPTION +# +# This macro checks if the compiler supports one of GCC's function +# attributes; many other compilers also provide function attributes with +# the same syntax. Compiler warnings are used to detect supported +# attributes as unsupported ones are ignored by default so quieting +# warnings when using this macro will yield false positives. +# +# The ATTRIBUTE parameter holds the name of the attribute to be checked. +# +# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_. +# +# The macro caches its result in the ax_cv_have_func_attribute_ +# variable. +# +# The macro currently supports the following function attributes: +# +# alias +# aligned +# alloc_size +# always_inline +# artificial +# cold +# const +# constructor +# constructor_priority for constructor attribute with priority +# deprecated +# destructor +# dllexport +# dllimport +# error +# externally_visible +# fallthrough +# flatten +# format +# format_arg +# gnu_format +# gnu_inline +# hot +# ifunc +# leaf +# malloc +# noclone +# noinline +# nonnull +# noreturn +# nothrow +# optimize +# pure +# sentinel +# sentinel_position +# unused +# used +# visibility +# warning +# warn_unused_result +# weak +# weakref +# +# Unsupported function attributes will be tested with a prototype +# returning an int and not accepting any arguments and the result of the +# check might be wrong or meaningless so use with care. +# +# LICENSE +# +# Copyright (c) 2013 Gabriele Svelto +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 13 + +AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ + AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) + + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([ + m4_case([$1], + [alias], [ + int foo( void ) { return 0; } + int bar( void ) __attribute__(($1("foo"))); + ], + [aligned], [ + int foo( void ) __attribute__(($1(32))); + ], + [alloc_size], [ + void *foo(int a) __attribute__(($1(1))); + ], + [always_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [artificial], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [cold], [ + int foo( void ) __attribute__(($1)); + ], + [const], [ + int foo( void ) __attribute__(($1)); + ], + [constructor_priority], [ + int foo( void ) __attribute__((__constructor__(65535/2))); + ], + [constructor], [ + int foo( void ) __attribute__(($1)); + ], + [deprecated], [ + int foo( void ) __attribute__(($1(""))); + ], + [destructor], [ + int foo( void ) __attribute__(($1)); + ], + [dllexport], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [dllimport], [ + int foo( void ) __attribute__(($1)); + ], + [error], [ + int foo( void ) __attribute__(($1(""))); + ], + [externally_visible], [ + int foo( void ) __attribute__(($1)); + ], + [fallthrough], [ + void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }}; + ], + [flatten], [ + int foo( void ) __attribute__(($1)); + ], + [format], [ + int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); + ], + [gnu_format], [ + int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2))); + ], + [format_arg], [ + char *foo(const char *p) __attribute__(($1(1))); + ], + [gnu_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [hot], [ + int foo( void ) __attribute__(($1)); + ], + [ifunc], [ + int my_foo( void ) { return 0; } + static int (*resolve_foo(void))(void) { return my_foo; } + int foo( void ) __attribute__(($1("resolve_foo"))); + ], + [leaf], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [malloc], [ + void *foo( void ) __attribute__(($1)); + ], + [noclone], [ + int foo( void ) __attribute__(($1)); + ], + [noinline], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [nonnull], [ + int foo(char *p) __attribute__(($1(1))); + ], + [noreturn], [ + void foo( void ) __attribute__(($1)); + ], + [nothrow], [ + int foo( void ) __attribute__(($1)); + ], + [optimize], [ + __attribute__(($1(3))) int foo( void ) { return 0; } + ], + [pure], [ + int foo( void ) __attribute__(($1)); + ], + [sentinel], [ + int foo(void *p, ...) __attribute__(($1)); + ], + [sentinel_position], [ + int foo(void *p, ...) __attribute__(($1(1))); + ], + [returns_nonnull], [ + void *foo( void ) __attribute__(($1)); + ], + [unused], [ + int foo( void ) __attribute__(($1)); + ], + [used], [ + int foo( void ) __attribute__(($1)); + ], + [visibility], [ + int foo_def( void ) __attribute__(($1("default"))); + int foo_hid( void ) __attribute__(($1("hidden"))); + int foo_int( void ) __attribute__(($1("internal"))); + int foo_pro( void ) __attribute__(($1("protected"))); + ], + [warning], [ + int foo( void ) __attribute__(($1(""))); + ], + [warn_unused_result], [ + int foo( void ) __attribute__(($1)); + ], + [weak], [ + int foo( void ) __attribute__(($1)); + ], + [weakref], [ + static int foo( void ) { return 0; } + static int bar( void ) __attribute__(($1("foo"))); + ], + [ + m4_warn([syntax], [Unsupported attribute $1, the test may fail]) + int foo( void ) __attribute__(($1)); + ] + )], []) + ], + dnl GCC doesn't exit with an error if an unknown attribute is + dnl provided but only outputs a warning, so accept the attribute + dnl only if no warning were issued. + [AS_IF([grep -- -Wattributes conftest.err], + [AS_VAR_SET([ac_var], [no])], + [AS_VAR_SET([ac_var], [yes])])], + [AS_VAR_SET([ac_var], [no])]) + ]) + + AS_IF([test yes = AS_VAR_GET([ac_var])], + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, + [Define to 1 if the system has the `$1' function attribute])], []) + + AS_VAR_POPDEF([ac_var]) +]) diff --git a/lib/pinelog/m4/ax_require_defined.m4 b/lib/pinelog/m4/ax_require_defined.m4 new file mode 100644 index 0000000..17c3eab --- /dev/null +++ b/lib/pinelog/m4/ax_require_defined.m4 @@ -0,0 +1,37 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_REQUIRE_DEFINED(MACRO) +# +# DESCRIPTION +# +# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have +# been defined and thus are available for use. This avoids random issues +# where a macro isn't expanded. Instead the configure script emits a +# non-fatal: +# +# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found +# +# It's like AC_REQUIRE except it doesn't expand the required macro. +# +# Here's an example: +# +# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) +# +# LICENSE +# +# Copyright (c) 2014 Mike Frysinger +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + +AC_DEFUN([AX_REQUIRE_DEFINED], [dnl + m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) +])dnl AX_REQUIRE_DEFINED diff --git a/lib/pinelog/pinelog.c b/lib/pinelog/pinelog.c new file mode 100644 index 0000000..e2e7c42 --- /dev/null +++ b/lib/pinelog/pinelog.c @@ -0,0 +1,217 @@ +/* + * Pinelog lightweight logging library + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: MIT + */ + +#include "config.h" +#include +#include +#include +#include + +#include "pinelog.h" + +/********************************************************************** + * Configure defaults + *********************************************************************/ +#ifndef PINELOG_DEFAULT_STREAM +#define PINELOG_DEFAULT_STREAM stdout +#endif + +#ifndef PINELOG_DEFAULT_LEVEL +#define PINELOG_DEFAULT_LEVEL PINELOG_LVL_ERROR +#endif + +/********************************************************************** + * Configure logging parameters + *********************************************************************/ +#ifndef PINELOG_SHOW_DATE +#define PINELOG_SHOW_DATE 0 +#endif + +#ifndef PINELOG_SHOW_LEVEL +#define PINELOG_SHOW_LEVEL 0 +#endif + +#ifndef PINELOG_SHOW_BACKTRACE +#define PINELOG_SHOW_BACKTRACE 0 +#endif + +/********************************************************************** + * Configure level strings + *********************************************************************/ +#ifndef PINELOG_FATAL_STR +#define PINELOG_FATAL_STR "FATAL" +#endif + +#ifndef PINELOG_ERROR_STR +#define PINELOG_ERROR_STR "ERROR" +#endif + +#ifndef PINELOG_WARNING_STR +#define PINELOG_WARNING_STR "WARNING" +#endif + +#ifndef PINELOG_INFO_STR +#define PINELOG_INFO_STR "INFO" +#endif + +#ifndef PINELOG_DEBUG_STR +#define PINELOG_DEBUG_STR "DEBUG" +#endif + +#ifndef PINELOG_TRACE_STR +#define PINELOG_TRACE_STR "TRACE" +#endif + +/********************************************************************** + * Global variables + *********************************************************************/ + +/** Stream buffer */ +static FILE *output_stream = NULL; + +/** Default logging level */ +static int log_level = PINELOG_DEFAULT_LEVEL; + +/* Initialize defaults */ +#if HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR +__attribute__((constructor)) +#endif +void pinelog_set_defaults(void) +{ + output_stream = PINELOG_DEFAULT_STREAM; + log_level = PINELOG_DEFAULT_LEVEL; +} + +#if HAVE_FUNC_ATTRIBUTE_DESTRUCTOR +__attribute__((destructor)) +#endif +void pinelog_close_output_stream(void) +{ + /* If current output stream is not stdout or stderr, then close it */ + if (output_stream != NULL && output_stream != stdout && output_stream != stderr) { + fclose(output_stream); + } + output_stream = PINELOG_DEFAULT_STREAM; +} + +int pinelog_set_output_stream(FILE *stream) +{ + if (stream == NULL) { + return EINVAL; + } + + pinelog_close_output_stream(); + + setlinebuf(stream); + output_stream = stream; + return 0; +} + +#ifdef PINELOG_TEST +FILE * pinelog_get_output_stream(void) +{ + return output_stream; +} +#endif + +int pinelog_set_output_file(const char *file) +{ + FILE *stream; + if (file == NULL) { + return EINVAL; + } + + errno = 0; + stream = fopen(file, "w"); + if (stream == NULL) { + return errno; + } + + return pinelog_set_output_stream(stream); +} + +int pinelog_get_level(void) +{ + return log_level; +} + +int pinelog_set_level(int level) +{ + if (level < PINELOG_LVL_NONE || level > PINELOG_LVL_TRACE) { + return EINVAL; + } + + log_level = level; + return 0; +} + +/********************************************************************** + * Log the message to the output stream + *********************************************************************/ +void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...) +{ + va_list ap; + + /* Don't log anything if the level is not severe enough */ + if (level > log_level || level < 0) { + return; + } + + /* Cap the log level */ + if (level > PINELOG_LVL_TRACE) { + level = PINELOG_LVL_TRACE; + } + + #if !HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR + /* + * Validate and set output stream. Only necessary if the compiler doesn't + * support the constructor attribute + */ + if (output_stream == NULL) { + output_stream = PINELOG_DEFAULT_STREAM; + } + #endif + + #if PINELOG_SHOW_DATE + do { + time_t t; + struct tm *tmp; + char date_string[30]; + t = time(NULL); + tmp = localtime(&t); + strftime(date_string, sizeof(date_string), "%F %T ", tmp); + fputs(date_string, output_stream); + } while (0); + #endif + + #if PINELOG_SHOW_LEVEL + do { + static const char *level_strings[] = { + PINELOG_FATAL_STR, + PINELOG_ERROR_STR, + PINELOG_WARNING_STR, + PINELOG_INFO_STR, + PINELOG_DEBUG_STR, + PINELOG_TRACE_STR, + }; + + fputs(level_strings[level], output_stream); + fputs(": ", output_stream); + } while (0); + #endif + + #if PINELOG_SHOW_BACKTRACE + fprintf(output_stream, "%s:%d ", file, line); + #endif + + va_start(ap, fmt); + vfprintf(output_stream, fmt, ap); + va_end(ap); + // Append a trailing newline to flush the log message + fputs("\n", output_stream); +} diff --git a/lib/pinelog/pinelog.h b/lib/pinelog/pinelog.h new file mode 100644 index 0000000..b061922 --- /dev/null +++ b/lib/pinelog/pinelog.h @@ -0,0 +1,183 @@ +/* + * Pinelog lightweight logging library + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: MIT + */ + +/** + * @file logging.h + * @brief Logging utility library + * + * This file contains the prototypes for the pinelog logging library + * used by any programs that need to log messages. + * + * @author Nirenjan Krishnan (nirenjan@nirenjan.org) + */ +#ifndef LOGGING_H +#define LOGGING_H + +#include "config.h" +#include +#ifndef PINELOG_TEST +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Logging levels + * + * The log levels indicate the lowest severity level that will actually be + * logged to the logging framework. + */ +enum { + /** No messages will be logged */ + PINELOG_LVL_NONE = -1, + + /** Only fatal messages will be logged */ + PINELOG_LVL_FATAL, + + /** Error messages. This is the default log level */ + PINELOG_LVL_ERROR, + + /** Warning messages */ + PINELOG_LVL_WARNING, + + /** Informational messages */ + PINELOG_LVL_INFO, + + /** Debug messages */ + PINELOG_LVL_DEBUG, + + /** Trace messages */ + PINELOG_LVL_TRACE, +}; + +/** + * @brief Set the default log level and output stream + */ +void pinelog_set_defaults(void); + +/** + * @brief Close the output stream and terminate the logs + */ +void pinelog_close_output_stream(void); + +#ifdef PINELOG_TEST +/** + * @brief Get the pointer to the output stream. Only used in test harness. + * + * @returns FILE pointer to output stream + */ +FILE * pinelog_get_output_stream(void); +#endif + +/** + * @brief Set the output stream. Must be a FILE pointer. + * + * @param[in] stream Pointer to the output stream + * + * @returns 0 on success, EINVAL if the pointer is not valid. + */ +int pinelog_set_output_stream(FILE *stream); + +/** + * @brief Set the output file. + * + * @param[in] file Filename to write to + * + * @returns 0 on success, EINVAL if the filename pointer is not valid, other + * error if the file could not be opened for writing. + */ +int pinelog_set_output_file(const char *file); + +/** + * @brief Set the logging level + * + * @param[in] level Level to filter + * + * @returns 0 on success, EINVAL if the level is not valid + */ +int pinelog_set_level(int level); + +/** + * @brief Get the logging level + * + * @returns the configured logging level + */ +int pinelog_get_level(void); + +/** + * @brief Log a message to the logger + * + * This is the actual function that logs the message. The application should + * never need to call this directly, but instead, should always use the + * \code PINELOG_* macros. + * + * @param[in] level Level to log the message at + * @param[in] fmt Format string + * + * @returns None + */ +#if HAVE_FUNC_ATTRIBUTE_FORMAT +__attribute__((format(printf, 4, 5))) +#endif + +void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...); + +// Test harness will redefine pinelog_exit +#ifndef PINELOG_TEST +#define pinelog_exit exit +#endif + +#define PINELOG_FATAL(fmt, ...) do { \ + if (PINELOG_LVL_FATAL <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_FATAL, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ + pinelog_exit(1); \ +} while (0) + +#define PINELOG_ERROR(fmt, ...) do { \ + if (PINELOG_LVL_ERROR <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ +} while (0) + +#define PINELOG_WARN(fmt, ...) do { \ + if (PINELOG_LVL_WARNING <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_WARNING, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ +} while(0) + +#define PINELOG_INFO(fmt, ...) do { \ + if (PINELOG_LVL_INFO <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ +} while(0) + +#define PINELOG_DEBUG(fmt, ...) do { \ + if (PINELOG_LVL_DEBUG <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_DEBUG, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ +} while(0) + +/* PINELOG_DISABLE_TRACE allows all traces to be compiled out */ +#ifndef PINELOG_DISABLE_TRACE +#define PINELOG_TRACE(fmt, ...) do { \ + if (PINELOG_LVL_TRACE <= pinelog_get_level()) { \ + pinelog_log_message(PINELOG_LVL_TRACE, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ +} while(0) +#else +#define PINELOG_TRACE(fmt, ...) do { } while(0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif // !defined LOGGING_H diff --git a/lib/pinelog/test_pinelog.c b/lib/pinelog/test_pinelog.c new file mode 100644 index 0000000..0f59117 --- /dev/null +++ b/lib/pinelog/test_pinelog.c @@ -0,0 +1,191 @@ +/* + * Pinelog lightweight logging library - test harness + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: MIT + */ + +#include "pinelog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/********************************************************************** + * Global variables + *********************************************************************/ +// Test ID (of current test case) +static unsigned int test_id; + +// Observed output stream +static FILE *observed_stream_w; +static FILE *observed_stream_r; + +// Temporary pipe for observed data +static char observed_fifo[NAME_MAX]; + +// Buffer for expected output +static char expected_output[1024]; +static size_t expected_len; + +static void test_case(const char *desc, bool test) +{ + test_id++; + if (test) { + printf("ok %u %s\n", test_id, desc); + } else { + printf("not ok %u %s\n", test_id, desc); + } +} + +static void pinelog_exit(int status) +{ + fprintf(observed_stream_w, "EXIT(%d)\n", status); + expected_len += snprintf(&expected_output[expected_len], + sizeof(expected_output) - expected_len, + "EXIT(%d)\n", status); +} + +static void dump_data(const char *type, size_t len, char *data) +{ + char *line; + printf("# %s (%lu bytes):\n", type, len); + line = strtok(data, "\n"); + while (line != NULL) { + printf("#\t%s\n", line); + line = strtok(NULL, "\n"); + } + printf("\n"); +} + +static int test_setup(int level, int filter, const char *file, int line) +{ + expected_len = 0; + memset(expected_output, 0, sizeof(expected_output)); + + if (level <= filter) { + if (PINELOG_SHOW_DATE) { + time_t t; + struct tm *tmp; + + t = time(NULL); + tmp = localtime(&t); + expected_len += strftime(&expected_output[expected_len], + sizeof(expected_output) - expected_len, + "%F %T ", tmp); + } + + if (PINELOG_SHOW_LEVEL) { + const char * level_string[] = { + PINELOG_FATAL_STR, + PINELOG_ERROR_STR, + PINELOG_WARNING_STR, + PINELOG_INFO_STR, + PINELOG_DEBUG_STR, + PINELOG_TRACE_STR, + }; + expected_len += snprintf(&expected_output[expected_len], + sizeof(expected_output) - expected_len, + "%s: ", level_string[level]); + } + + if (PINELOG_SHOW_BACKTRACE) { + expected_len += snprintf(&expected_output[expected_len], + sizeof(expected_output) - expected_len, + "%s:%d ", file, line); + } + + return 1; + } + + return 0; +} + +static void test_teardown(const char *desc) +{ + // Compare the output + static char observed[1024]; + size_t observed_len; + int result; + + observed_len = fread(observed, 1, sizeof(observed), observed_stream_r); + + result = ((expected_len == observed_len) && + (memcmp(expected_output, observed, expected_len) == 0)); + test_case(desc, result); + if (!result) { + dump_data("expected", expected_len, expected_output); + dump_data("observed", observed_len, observed); + } +} + +static void verify_defaults(void) +{ + test_case("Get default output stream", + pinelog_get_output_stream() == PINELOG_DEFAULT_STREAM); + test_case("Get default logging level", + pinelog_get_level() == PINELOG_DEFAULT_LEVEL); +} + +#define PINELOG_WARNING PINELOG_WARN + +#define TEST_LOG(lvl, filter, fmt, ...) do { \ + if (test_setup(PINELOG_LVL_ ## lvl, PINELOG_LVL_ ## filter, \ + __FILE__, __LINE__)) \ + expected_len += snprintf(&expected_output[expected_len], \ + sizeof(expected_output) - expected_len, \ + fmt "\n", ##__VA_ARGS__); \ + PINELOG_ ## lvl (fmt, ##__VA_ARGS__); \ + test_teardown("Log " #lvl " filter " #filter); \ +} while(0) + +#define TEST(filter, fmt, ...) do { \ + pinelog_set_level(PINELOG_LVL_ ## filter); \ + TEST_LOG(TRACE, filter, fmt, ##__VA_ARGS__); \ + TEST_LOG(DEBUG, filter, fmt, ##__VA_ARGS__); \ + TEST_LOG(INFO, filter, fmt, ##__VA_ARGS__); \ + TEST_LOG(WARNING, filter, fmt, ##__VA_ARGS__); \ + TEST_LOG(ERROR, filter, fmt, ##__VA_ARGS__); \ + TEST_LOG(FATAL, filter, fmt, ##__VA_ARGS__); \ +} while (0) + +int main(int argc, char **argv) +{ + int fifo_fd_r, fifo_fd_w; + snprintf(observed_fifo, sizeof(observed_fifo), "%s.fifo", argv[0]); + mkfifo(observed_fifo, 0777); + + fifo_fd_r = open(observed_fifo, O_RDONLY | O_NONBLOCK); + fifo_fd_w = open(observed_fifo, O_WRONLY | O_NONBLOCK); + observed_stream_r = fdopen(fifo_fd_r, "r"); + observed_stream_w = fdopen(fifo_fd_w, "w"); + + verify_defaults(); + + pinelog_set_output_stream(observed_stream_w); + TEST(TRACE, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(DEBUG, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(INFO, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(WARNING, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(ERROR, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(FATAL, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + TEST(NONE, "testing %s... %d, %f, %u", "testing", -1, 0.0, 1); + + printf("1..%u\n", test_id); + + pinelog_close_output_stream(); + fclose(observed_stream_r); + close(fifo_fd_w); + close(fifo_fd_r); + unlink(observed_fifo); + + return 0; +} diff --git a/libusbx52/Makefile.am b/libusbx52/Makefile.am new file mode 100644 index 0000000..1f82b6f --- /dev/null +++ b/libusbx52/Makefile.am @@ -0,0 +1,25 @@ +# Automake for libusbx52 and associated utilities +# +# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + +# libusb stub library for use by test programs +check_LTLIBRARIES += libusbx52.la + +libusbx52_la_SOURCES = libusbx52/usb_x52_stub.c libusbx52/fopen_env.c +libusbx52_la_CFLAGS = -I $(top_srcdir)/libusbx52 @LIBUSB_CFLAGS@ $(WARN_CFLAGS) +libusbx52_la_LDFLAGS = -rpath /nowhere -module $(WARN_LDFLAGS) + +# Utility programs for use by tests +check_PROGRAMS += x52test_create_device_list x52test_log_actions + +x52test_create_device_list_SOURCES = libusbx52/util/create_device_list.c $(libusbx52_la_SOURCES) +x52test_create_device_list_CFLAGS = $(libusbx52_la_CFLAGS) +x52test_create_device_list_LDFLAGS = $(WARN_LDFLAGS) + +x52test_log_actions_SOURCES = libusbx52/util/log_actions.c $(libusbx52_la_SOURCES) +x52test_log_actions_CFLAGS = -I $(top_srcdir)/libx52 $(libusbx52_la_CFLAGS) +x52test_log_actions_LDFLAGS = $(WARN_LDFLAGS) + +EXTRA_DIST += libusbx52/README.md libusbx52/libusbx52.h diff --git a/lib/libusbx52/README.md b/libusbx52/README.md similarity index 100% rename from lib/libusbx52/README.md rename to libusbx52/README.md diff --git a/lib/libusbx52/fopen_env.c b/libusbx52/fopen_env.c similarity index 100% rename from lib/libusbx52/fopen_env.c rename to libusbx52/fopen_env.c diff --git a/lib/libusbx52/libusbx52.h b/libusbx52/libusbx52.h similarity index 100% rename from lib/libusbx52/libusbx52.h rename to libusbx52/libusbx52.h diff --git a/lib/libusbx52/usb_x52_stub.c b/libusbx52/usb_x52_stub.c similarity index 100% rename from lib/libusbx52/usb_x52_stub.c rename to libusbx52/usb_x52_stub.c diff --git a/lib/libusbx52/util/create_device_list.c b/libusbx52/util/create_device_list.c similarity index 100% rename from lib/libusbx52/util/create_device_list.c rename to libusbx52/util/create_device_list.c diff --git a/lib/libusbx52/util/log_actions.c b/libusbx52/util/log_actions.c similarity index 100% rename from lib/libusbx52/util/log_actions.c rename to libusbx52/util/log_actions.c diff --git a/lib/libx52/Makefile.am b/libx52/Makefile.am similarity index 51% rename from lib/libx52/Makefile.am rename to libx52/Makefile.am index 01230d7..3166c68 100644 --- a/lib/libx52/Makefile.am +++ b/libx52/Makefile.am @@ -4,20 +4,27 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -ACLOCAL_AMFLAGS = -I m4 - -lib_LTLIBRARIES = libx52.la +lib_LTLIBRARIES += libx52.la # Core libx52 library # This library handles the USB communication between the host and the X52 # Libtool Version Info # See: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -libx52_v_CUR=5 -libx52_v_AGE=3 +libx52_v_CUR=6 +libx52_v_AGE=4 libx52_v_REV=0 -libx52_la_SOURCES = x52_control.c x52_core.c x52_date_time.c x52_mfd_led.c \ - x52_strerror.c -libx52_la_CFLAGS = @LIBUSB_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS) +libx52_la_SOURCES = \ + libx52/x52_control.c \ + libx52/x52_core.c \ + libx52/x52_date_time.c \ + libx52/x52_mfd_led.c \ + libx52/x52_strerror.c \ + libx52/x52_stringify.c +libx52_la_CFLAGS = \ + @LIBUSB_CFLAGS@ \ + -DLOCALEDIR=\"$(localedir)\" \ + -I $(top_srcdir) \ + $(WARN_CFLAGS) libx52_la_LDFLAGS = \ -export-symbols-regex '^libx52_' \ -version-info $(libx52_v_CUR):$(libx52_v_REV):$(libx52_v_AGE) @LIBUSB_LIBS@ \ @@ -25,37 +32,36 @@ libx52_la_LDFLAGS = \ libx52_la_LIBADD = @LTLIBINTL@ # Header files that need to be copied -x52includedir = $(includedir)/libx52 -x52include_HEADERS = libx52.h +x52include_HEADERS += libx52/libx52.h # pkg-config files -pkgconfig_DATA = libx52.pc +pkgconfig_DATA += libx52/libx52.pc if HAVE_CMOCKA -LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh -TESTS = libx52test -check_PROGRAMS = libx52test +TESTS += libx52test +check_PROGRAMS += libx52test -nodist_libx52test_SOURCES = test_libx52.c +nodist_libx52test_SOURCES = libx52/test_libx52.c libx52test_SOURCES = $(libx52_la_SOURCES) -libx52test_CFLAGS = @LIBUSB_CFLAGS@ -DLOCALEDIR='"$(localedir)"' -I $(top_srcdir) +libx52test_CFLAGS = @LIBUSB_CFLAGS@ -DLOCALEDIR='"$(localedir)"' -I $(top_srcdir) -I $(top_srcdir)/libx52 libx52test_CFLAGS += -Dlibusb_control_transfer=__wrap_libusb_control_transfer libx52test_LDFLAGS = @CMOCKA_LIBS@ @LIBUSB_LIBS@ libx52test_LDADD = libx52.la -CLEANFILES = test_libx52.c -test_libx52.c: $(srcdir)/x52_test_gen.py $(srcdir)/x52_tests.json - $(AM_V_GEN) $(PYTHON) $(srcdir)/x52_test_gen.py $(srcdir)/x52_tests.json > $@ +CLEANFILES += libx52/test_libx52.c +$(builddir)/libx52/test_libx52.c: $(srcdir)/libx52/x52_test_gen.py $(srcdir)/libx52/x52_tests.json + $(AM_V_GEN) $(PYTHON) $(srcdir)/libx52/x52_test_gen.py $(srcdir)/libx52/x52_tests.json > $@ endif # Extra files that need to be in the distribution -EXTRA_DIST = libx52.h x52_commands.h x52_common.h README.md +EXTRA_DIST += \ + libx52/libx52.h libx52/x52_commands.h libx52/x52_common.h libx52/README.md # Add test files to the distribution -EXTRA_DIST += x52_test_gen.py x52_tests.json +EXTRA_DIST += libx52/x52_test_gen.py libx52/x52_tests.json # Add documentation files to the distribution EXTRA_DIST += \ - doc/main.dox \ - doc/caveats.dox \ - doc/integration.dox + libx52/doc/main.dox \ + libx52/doc/caveats.dox \ + libx52/doc/integration.dox diff --git a/lib/libx52/README.md b/libx52/README.md similarity index 100% rename from lib/libx52/README.md rename to libx52/README.md diff --git a/lib/libx52/doc/caveats.dox b/libx52/doc/caveats.dox similarity index 100% rename from lib/libx52/doc/caveats.dox rename to libx52/doc/caveats.dox diff --git a/lib/libx52/doc/integration.dox b/libx52/doc/integration.dox similarity index 100% rename from lib/libx52/doc/integration.dox rename to libx52/doc/integration.dox diff --git a/lib/libx52/doc/main.dox b/libx52/doc/main.dox similarity index 100% rename from lib/libx52/doc/main.dox rename to libx52/doc/main.dox diff --git a/lib/libx52/libx52.h b/libx52/libx52.h similarity index 92% rename from lib/libx52/libx52.h rename to libx52/libx52.h index 05c7060..94e4b4a 100644 --- a/lib/libx52/libx52.h +++ b/libx52/libx52.h @@ -673,6 +673,16 @@ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value); */ int libx52_check_feature(libx52_device *x52, libx52_feature feature); +/** @} */ + +/** + * @defgroup libx52str Stringification + * + * Translation APIs from enumerations to string, primarily for logging. + * + * @{ + */ + /** * @brief Return a string representation of the error code * @@ -683,6 +693,56 @@ int libx52_check_feature(libx52_device *x52, libx52_feature feature); */ const char * libx52_strerror(libx52_error_code error); +/** + * @brief Returns a string representation of the clock ID + * + * @param[in] id Clock ID + * + * @returns Pointer to a NULL terminated string describing the clock ID. + * Returned pointer must not be freed. + */ +const char * libx52_clock_id_to_str(libx52_clock_id id); + +/** + * @brief Returns a string representation of the clock format + * + * @param[in] format Clock format + * + * @returns Pointer to a NULL terminated string describing the clock format. + * Returned pointer must not be freed. + */ +const char * libx52_clock_format_to_str(libx52_clock_format format); + +/** + * @brief Returns a string representation of the date format + * + * @param[in] format Date format + * + * @returns Pointer to a NULL terminated string describing the date format. + * Returned pointer must not be freed. + */ +const char * libx52_date_format_to_str(libx52_date_format format); + +/** + * @brief Returns a string representation of the LED + * + * @param[in] id LED ID + * + * @returns Pointer to a NULL terminated string describing the LED. + * Returned pointer must not be freed. + */ +const char * libx52_led_id_to_str(libx52_led_id id); + +/** + * @brief Returns a string representation of the LED state + * + * @param[in] state LED state + * + * @returns Pointer to a NULL terminated string describing the LED state. + * Returned pointer must not be freed. + */ +const char * libx52_led_state_to_str(libx52_led_state state); + /** @} */ #ifdef __cplusplus diff --git a/lib/libx52/libx52.pc.in b/libx52/libx52.pc.in similarity index 100% rename from lib/libx52/libx52.pc.in rename to libx52/libx52.pc.in diff --git a/lib/libx52/x52_commands.h b/libx52/x52_commands.h similarity index 100% rename from lib/libx52/x52_commands.h rename to libx52/x52_commands.h diff --git a/lib/libx52/x52_common.h b/libx52/x52_common.h similarity index 100% rename from lib/libx52/x52_common.h rename to libx52/x52_common.h diff --git a/lib/libx52/x52_control.c b/libx52/x52_control.c similarity index 100% rename from lib/libx52/x52_control.c rename to libx52/x52_control.c diff --git a/lib/libx52/x52_core.c b/libx52/x52_core.c similarity index 100% rename from lib/libx52/x52_core.c rename to libx52/x52_core.c diff --git a/lib/libx52/x52_date_time.c b/libx52/x52_date_time.c similarity index 100% rename from lib/libx52/x52_date_time.c rename to libx52/x52_date_time.c diff --git a/lib/libx52/x52_mfd_led.c b/libx52/x52_mfd_led.c similarity index 100% rename from lib/libx52/x52_mfd_led.c rename to libx52/x52_mfd_led.c diff --git a/lib/libx52/x52_strerror.c b/libx52/x52_strerror.c similarity index 59% rename from lib/libx52/x52_strerror.c rename to libx52/x52_strerror.c index 6cdbaa3..a193140 100644 --- a/lib/libx52/x52_strerror.c +++ b/libx52/x52_strerror.c @@ -1,7 +1,7 @@ /* * Saitek X52 Pro MFD & LED driver * - * Copyright (C) 2012-2017 Nirenjan Krishnan (nirenjan@nirenjan.org) + * Copyright (C) 2012-2021 Nirenjan Krishnan (nirenjan@nirenjan.org) * * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 */ @@ -12,65 +12,54 @@ #include "libx52.h" #include "gettext.h" -/** For future use in i18n */ +#define N_(str) gettext_noop(str) #define _(str) dgettext(PACKAGE, str) /* Error buffer used for building custom error strings */ static char error_buffer[256]; +/* List of error strings */ +static const char *error_string[] = { + N_("Success"), + N_("Initialization failure"), + N_("Insufficient memory"), + N_("Invalid parameter"), + N_("Operation not supported"), + N_("Try again"), + N_("Input parameter out of range"), + N_("USB transaction failure"), + N_("USB input/output error"), + N_("Access denied"), + N_("No such device"), + N_("Entity not found"), + N_("Resource busy"), + N_("Operation timeout"), + N_("Overflow"), + N_("Pipe error"), + N_("System call interrupted"), +}; + const char * libx52_strerror(libx52_error_code error) { switch (error) { case LIBX52_SUCCESS: - return _("Success"); - case LIBX52_ERROR_INIT_FAILURE: - return _("Initialization failure"); - case LIBX52_ERROR_OUT_OF_MEMORY: - return _("Insufficient memory"); - case LIBX52_ERROR_INVALID_PARAM: - return _("Invalid parameter"); - case LIBX52_ERROR_NOT_SUPPORTED: - return _("Operation not supported"); - case LIBX52_ERROR_TRY_AGAIN: - return _("Try again"); - case LIBX52_ERROR_OUT_OF_RANGE: - return _("Input parameter out of range"); - case LIBX52_ERROR_USB_FAILURE: - return _("USB transaction failure"); - case LIBX52_ERROR_IO: - return _("USB input/output error"); - case LIBX52_ERROR_PERM: - return _("Access denied"); - case LIBX52_ERROR_NO_DEVICE: - return _("No such device"); - case LIBX52_ERROR_NOT_FOUND: - return _("Entity not found"); - case LIBX52_ERROR_BUSY: - return _("Resource busy"); - case LIBX52_ERROR_TIMEOUT: - return _("Operation timeout"); - case LIBX52_ERROR_OVERFLOW: - return _("Overflow"); - case LIBX52_ERROR_PIPE: - return _("Pipe error"); - case LIBX52_ERROR_INTERRUPTED: - return _("System call interrupted"); + return _(error_string[error]); default: snprintf(error_buffer, sizeof(error_buffer), diff --git a/libx52/x52_stringify.c b/libx52/x52_stringify.c new file mode 100644 index 0000000..3daad2c --- /dev/null +++ b/libx52/x52_stringify.c @@ -0,0 +1,96 @@ +/* + * Saitek X52 Pro MFD & LED driver - stringification + * + * Copyright (C) 2012-2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include + +#include "libx52.h" +#include "gettext.h" + +#define N_(str) gettext_noop(str) +#define _(str) dgettext(PACKAGE, str) + +#define STRINGIFY(name, max_id, errstr, ...) \ +const char * libx52_ ## name ## _to_str (libx52_ ## name param) { \ + static char invalid[256]; \ + static const char *desc[] = { __VA_ARGS__ }; \ + if (param >= 0 && param <= max_id) { \ + return _(desc[param]); \ + } \ + snprintf(invalid, sizeof(invalid), _(errstr), param); \ + return invalid; \ +} + +STRINGIFY(clock_id, LIBX52_CLOCK_3, N_("Unknown clock ID %d"), + N_("primary"), + N_("secondary"), + N_("tertiary"), +) + +STRINGIFY(clock_format, LIBX52_CLOCK_FORMAT_24HR, N_("Unknown clock format %d"), + N_("12 hour"), + N_("24 hour"), +) + +STRINGIFY(date_format, LIBX52_DATE_FORMAT_YYMMDD, N_("Unknown date format %d"), + N_("DD-MM-YY"), + N_("MM-DD-YY"), + N_("YY-MM-DD"), +) + +STRINGIFY(led_state, LIBX52_LED_STATE_GREEN, N_("Unknown LED state %d") + N_("off"), + N_("on"), + N_("red"), + N_("amber"), + N_("green"), +) + +const char * libx52_led_id_to_str(libx52_led_id id) +{ + static char invalid[256]; + + switch (id) { + case LIBX52_LED_FIRE: + return _("Fire"); + + case LIBX52_LED_A: + return _("A"); + + case LIBX52_LED_B: + return _("B"); + + case LIBX52_LED_D: + return _("D"); + + case LIBX52_LED_E: + return _("E"); + + case LIBX52_LED_T1: + return _("T1"); + + case LIBX52_LED_T2: + return _("T2"); + + case LIBX52_LED_T3: + return _("T3"); + + case LIBX52_LED_POV: + return _("POV"); + + case LIBX52_LED_CLUTCH: + return _("Clutch"); + + case LIBX52_LED_THROTTLE: + return _("Throttle"); + + default: + snprintf(invalid, sizeof(invalid), _("Unknown LED ID %d"), id); + return invalid; + } +} diff --git a/lib/libx52/x52_test_gen.py b/libx52/x52_test_gen.py similarity index 100% rename from lib/libx52/x52_test_gen.py rename to libx52/x52_test_gen.py diff --git a/lib/libx52/x52_tests.json b/libx52/x52_tests.json similarity index 100% rename from lib/libx52/x52_tests.json rename to libx52/x52_tests.json diff --git a/lib/libx52io/Makefile.am b/libx52io/Makefile.am similarity index 67% rename from lib/libx52io/Makefile.am rename to libx52io/Makefile.am index 9fb534e..d60937c 100644 --- a/lib/libx52io/Makefile.am +++ b/libx52io/Makefile.am @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -lib_LTLIBRARIES = libx52io.la +lib_LTLIBRARIES += libx52io.la # X52 IO library # This library handles the HID parsing of the X52 USB reports @@ -13,7 +13,12 @@ lib_LTLIBRARIES = libx52io.la libx52io_v_CUR=0 libx52io_v_AGE=0 libx52io_v_REV=0 -libx52io_la_SOURCES = io_core.c io_axis.c io_parser.c io_strings.c io_device.c +libx52io_la_SOURCES = \ + libx52io/io_core.c \ + libx52io/io_axis.c \ + libx52io/io_parser.c \ + libx52io/io_strings.c \ + libx52io/io_device.c libx52io_la_CFLAGS = @HIDAPI_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS) libx52io_la_LDFLAGS = \ -export-symbols-regex '^libx52io_' \ @@ -22,30 +27,31 @@ libx52io_la_LDFLAGS = \ libx52io_la_LIBADD = @LTLIBINTL@ # Header files that need to be copied -x52includedir = $(includedir)/libx52 -x52include_HEADERS = libx52io.h +x52include_HEADERS += libx52io/libx52io.h # pkg-config files # pkgconfig_DATA = libx52io.pc if HAVE_CMOCKA -LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh -TESTS = test-axis test-parser -check_PROGRAMS = $(TESTS) +TESTS += test-axis test-parser +check_PROGRAMS += test-axis test-parser -test_axis_SOURCES = test_axis.c $(libx52io_la_SOURCES) +test_axis_SOURCES = libx52io/test_axis.c $(libx52io_la_SOURCES) test_axis_CFLAGS = $(libx52io_la_CFLAGS) test_axis_LDFLAGS = @CMOCKA_LIBS@ @HIDAPI_LIBS@ $(WARN_LDFLAGS) test_axis_LDADD = @LTLIBINTL@ -test_parser_SOURCES = test_parser.c $(libx52io_la_SOURCES) +test_parser_SOURCES = libx52io/test_parser.c $(libx52io_la_SOURCES) test_parser_CFLAGS = $(libx52io_la_CFLAGS) test_parser_LDFLAGS = @CMOCKA_LIBS@ @HIDAPI_LIBS@ $(WARN_LDFLAGS) test_parser_LDADD = @LTLIBINTL@ # Add a dependency on test_parser_tests.c -test_parser.c: test_parser_tests.c +libx52io/test_parser.c: libx52io/test_parser_tests.c endif # Extra files that need to be in the distribution -EXTRA_DIST = libx52io.h io_common.h test_parser_tests.c +EXTRA_DIST += \ + libx52io/libx52io.h \ + libx52io/io_common.h \ + libx52io/test_parser_tests.c diff --git a/lib/libx52io/io_axis.c b/libx52io/io_axis.c similarity index 100% rename from lib/libx52io/io_axis.c rename to libx52io/io_axis.c diff --git a/lib/libx52io/io_common.h b/libx52io/io_common.h similarity index 100% rename from lib/libx52io/io_common.h rename to libx52io/io_common.h diff --git a/lib/libx52io/io_core.c b/libx52io/io_core.c similarity index 100% rename from lib/libx52io/io_core.c rename to libx52io/io_core.c diff --git a/lib/libx52io/io_device.c b/libx52io/io_device.c similarity index 100% rename from lib/libx52io/io_device.c rename to libx52io/io_device.c diff --git a/lib/libx52io/io_parser.c b/libx52io/io_parser.c similarity index 100% rename from lib/libx52io/io_parser.c rename to libx52io/io_parser.c diff --git a/lib/libx52io/io_strings.c b/libx52io/io_strings.c similarity index 92% rename from lib/libx52io/io_strings.c rename to libx52io/io_strings.c index 4f3eaaa..794a704 100644 --- a/lib/libx52io/io_strings.c +++ b/libx52io/io_strings.c @@ -95,31 +95,31 @@ const char * libx52io_button_to_str(libx52io_button button) /* Error buffer used for building custom error strings */ static char error_buffer[256]; +#define N_(str) gettext_noop(str) + +static const char *error_string[] = { + N_("Success"), + N_("Initialization failure"), + N_("No device"), + N_("Invalid arguments"), + N_("Connection failure"), + N_("I/O error"), + N_("Read timeout"), +}; + #define _(str) dgettext(PACKAGE, str) const char * libx52io_strerror(libx52io_error_code code) { switch (code) { case LIBX52IO_SUCCESS: - return _("Success"); - case LIBX52IO_ERROR_INIT_FAILURE: - return _("Initialization failure"); - case LIBX52IO_ERROR_NO_DEVICE: - return _("No device"); - case LIBX52IO_ERROR_INVALID: - return _("Invalid arguments"); - case LIBX52IO_ERROR_CONN: - return _("Connection failure"); - case LIBX52IO_ERROR_IO: - return _("I/O error"); - case LIBX52IO_ERROR_TIMEOUT: - return _("Read timeout"); + return _(error_string[code]); default: snprintf(error_buffer, sizeof(error_buffer), _("Unknown error %d"), code); diff --git a/lib/libx52io/libx52io.h b/libx52io/libx52io.h similarity index 100% rename from lib/libx52io/libx52io.h rename to libx52io/libx52io.h diff --git a/lib/libx52io/test_axis.c b/libx52io/test_axis.c similarity index 100% rename from lib/libx52io/test_axis.c rename to libx52io/test_axis.c diff --git a/lib/libx52io/test_parser.c b/libx52io/test_parser.c similarity index 100% rename from lib/libx52io/test_parser.c rename to libx52io/test_parser.c diff --git a/lib/libx52io/test_parser_tests.c b/libx52io/test_parser_tests.c similarity index 100% rename from lib/libx52io/test_parser_tests.c rename to libx52io/test_parser_tests.c diff --git a/libx52util/Makefile.am b/libx52util/Makefile.am new file mode 100644 index 0000000..a7864bb --- /dev/null +++ b/libx52util/Makefile.am @@ -0,0 +1,32 @@ +# Automake for libx52util +# +# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + +lib_LTLIBRARIES += libx52util.la + +# libx52 utility library +# This library provides extra utilities for ease of use +nodist_libx52util_la_SOURCES = libx52util/util_char_map.c +libx52util_la_SOURCES = libx52util/x52_char_map_lookup.c +libx52util_la_CFLAGS = -I $(top_srcdir)/libx52util $(WARN_CFLAGS) +libx52util_la_LDFLAGS = -version-info 1:0:0 $(WARN_LDFLAGS) + +# Header files that need to be copied +x52include_HEADERS += libx52util/libx52util.h + +# Autogenerated file that needs to be cleaned up +CLEANFILES += libx52util/util_char_map.c +util_char_map_c_DEPENDS = \ + $(srcdir)/libx52util/x52_char_map_gen.py \ + $(srcdir)/libx52util/x52_char_map.cfg + +$(builddir)/libx52util/util_char_map.c: $(util_char_map_c_DEPENDS) + $(AM_V_GEN) $(PYTHON) $(util_char_map_c_DEPENDS) $@ + +# Extra files that need to be in the distribution +EXTRA_DIST += libx52util/x52_char_map.cfg \ + libx52util/x52_char_map.h \ + libx52util/x52_char_map_gen.py + diff --git a/lib/libx52util/libx52util.h b/libx52util/libx52util.h similarity index 100% rename from lib/libx52util/libx52util.h rename to libx52util/libx52util.h diff --git a/lib/libx52util/x52_char_map.cfg b/libx52util/x52_char_map.cfg similarity index 100% rename from lib/libx52util/x52_char_map.cfg rename to libx52util/x52_char_map.cfg diff --git a/lib/libx52util/x52_char_map.h b/libx52util/x52_char_map.h similarity index 100% rename from lib/libx52util/x52_char_map.h rename to libx52util/x52_char_map.h diff --git a/lib/libx52util/x52_char_map_gen.py b/libx52util/x52_char_map_gen.py similarity index 100% rename from lib/libx52util/x52_char_map_gen.py rename to libx52util/x52_char_map_gen.py diff --git a/lib/libx52util/x52_char_map_lookup.c b/libx52util/x52_char_map_lookup.c similarity index 100% rename from lib/libx52util/x52_char_map_lookup.c rename to libx52util/x52_char_map_lookup.c diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4 new file mode 100644 index 0000000..fa4e089 --- /dev/null +++ b/m4/ax_gcc_func_attribute.m4 @@ -0,0 +1,242 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) +# +# DESCRIPTION +# +# This macro checks if the compiler supports one of GCC's function +# attributes; many other compilers also provide function attributes with +# the same syntax. Compiler warnings are used to detect supported +# attributes as unsupported ones are ignored by default so quieting +# warnings when using this macro will yield false positives. +# +# The ATTRIBUTE parameter holds the name of the attribute to be checked. +# +# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_. +# +# The macro caches its result in the ax_cv_have_func_attribute_ +# variable. +# +# The macro currently supports the following function attributes: +# +# alias +# aligned +# alloc_size +# always_inline +# artificial +# cold +# const +# constructor +# constructor_priority for constructor attribute with priority +# deprecated +# destructor +# dllexport +# dllimport +# error +# externally_visible +# fallthrough +# flatten +# format +# format_arg +# gnu_format +# gnu_inline +# hot +# ifunc +# leaf +# malloc +# noclone +# noinline +# nonnull +# noreturn +# nothrow +# optimize +# pure +# sentinel +# sentinel_position +# unused +# used +# visibility +# warning +# warn_unused_result +# weak +# weakref +# +# Unsupported function attributes will be tested with a prototype +# returning an int and not accepting any arguments and the result of the +# check might be wrong or meaningless so use with care. +# +# LICENSE +# +# Copyright (c) 2013 Gabriele Svelto +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 13 + +AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ + AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) + + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([ + m4_case([$1], + [alias], [ + int foo( void ) { return 0; } + int bar( void ) __attribute__(($1("foo"))); + ], + [aligned], [ + int foo( void ) __attribute__(($1(32))); + ], + [alloc_size], [ + void *foo(int a) __attribute__(($1(1))); + ], + [always_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [artificial], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [cold], [ + int foo( void ) __attribute__(($1)); + ], + [const], [ + int foo( void ) __attribute__(($1)); + ], + [constructor_priority], [ + int foo( void ) __attribute__((__constructor__(65535/2))); + ], + [constructor], [ + int foo( void ) __attribute__(($1)); + ], + [deprecated], [ + int foo( void ) __attribute__(($1(""))); + ], + [destructor], [ + int foo( void ) __attribute__(($1)); + ], + [dllexport], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [dllimport], [ + int foo( void ) __attribute__(($1)); + ], + [error], [ + int foo( void ) __attribute__(($1(""))); + ], + [externally_visible], [ + int foo( void ) __attribute__(($1)); + ], + [fallthrough], [ + void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }}; + ], + [flatten], [ + int foo( void ) __attribute__(($1)); + ], + [format], [ + int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); + ], + [gnu_format], [ + int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2))); + ], + [format_arg], [ + char *foo(const char *p) __attribute__(($1(1))); + ], + [gnu_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [hot], [ + int foo( void ) __attribute__(($1)); + ], + [ifunc], [ + int my_foo( void ) { return 0; } + static int (*resolve_foo(void))(void) { return my_foo; } + int foo( void ) __attribute__(($1("resolve_foo"))); + ], + [leaf], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [malloc], [ + void *foo( void ) __attribute__(($1)); + ], + [noclone], [ + int foo( void ) __attribute__(($1)); + ], + [noinline], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [nonnull], [ + int foo(char *p) __attribute__(($1(1))); + ], + [noreturn], [ + void foo( void ) __attribute__(($1)); + ], + [nothrow], [ + int foo( void ) __attribute__(($1)); + ], + [optimize], [ + __attribute__(($1(3))) int foo( void ) { return 0; } + ], + [pure], [ + int foo( void ) __attribute__(($1)); + ], + [sentinel], [ + int foo(void *p, ...) __attribute__(($1)); + ], + [sentinel_position], [ + int foo(void *p, ...) __attribute__(($1(1))); + ], + [returns_nonnull], [ + void *foo( void ) __attribute__(($1)); + ], + [unused], [ + int foo( void ) __attribute__(($1)); + ], + [used], [ + int foo( void ) __attribute__(($1)); + ], + [visibility], [ + int foo_def( void ) __attribute__(($1("default"))); + int foo_hid( void ) __attribute__(($1("hidden"))); + int foo_int( void ) __attribute__(($1("internal"))); + int foo_pro( void ) __attribute__(($1("protected"))); + ], + [warning], [ + int foo( void ) __attribute__(($1(""))); + ], + [warn_unused_result], [ + int foo( void ) __attribute__(($1)); + ], + [weak], [ + int foo( void ) __attribute__(($1)); + ], + [weakref], [ + static int foo( void ) { return 0; } + static int bar( void ) __attribute__(($1("foo"))); + ], + [ + m4_warn([syntax], [Unsupported attribute $1, the test may fail]) + int foo( void ) __attribute__(($1)); + ] + )], []) + ], + dnl GCC doesn't exit with an error if an unknown attribute is + dnl provided but only outputs a warning, so accept the attribute + dnl only if no warning were issued. + [AS_IF([grep -- -Wattributes conftest.err], + [AS_VAR_SET([ac_var], [no])], + [AS_VAR_SET([ac_var], [yes])])], + [AS_VAR_SET([ac_var], [no])]) + ]) + + AS_IF([test yes = AS_VAR_GET([ac_var])], + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, + [Define to 1 if the system has the `$1' function attribute])], []) + + AS_VAR_POPDEF([ac_var]) +]) diff --git a/po/POTFILES.in b/po/POTFILES.in index 847dc15..4a869a0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,12 +1,19 @@ # List of source files which contain translatable strings. -lib/libx52/x52_strerror.c +libx52/x52_strerror.c +libx52/x52_stringify.c -lib/libx52io/io_strings.c +libx52io/io_strings.c -utils/evtest/ev_test.c +evtest/ev_test.c -utils/test/x52_test.c -utils/test/x52_test_clock.c -utils/test/x52_test_common.h -utils/test/x52_test_led.c -utils/test/x52_test_mfd.c +joytest/x52_test.c +joytest/x52_test_clock.c +joytest/x52_test_common.h +joytest/x52_test_led.c +joytest/x52_test_mfd.c + +daemon/x52d_main.c +daemon/x52d_clock.c +daemon/x52d_config.c +daemon/x52d_config_parser.c +daemon/x52d_device.c diff --git a/po/x52pro-linux.pot b/po/x52pro-linux.pot index 46ac85d..301bfd0 100644 --- a/po/x52pro-linux.pot +++ b/po/x52pro-linux.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: x52pro-linux 0.2.1\n" +"Project-Id-Version: x52pro-linux 0.2.2\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2020-07-16 04:24-0700\n" +"POT-Creation-Date: 2021-07-29 22:58-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,355 +17,674 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: lib/libx52/x52_strerror.c:25 lib/libx52io/io_strings.c:104 +#: libx52/x52_strerror.c:23 libx52io/io_strings.c:101 msgid "Success" msgstr "" -#: lib/libx52/x52_strerror.c:28 lib/libx52io/io_strings.c:107 +#: libx52/x52_strerror.c:24 libx52io/io_strings.c:102 msgid "Initialization failure" msgstr "" -#: lib/libx52/x52_strerror.c:31 +#: libx52/x52_strerror.c:25 msgid "Insufficient memory" msgstr "" -#: lib/libx52/x52_strerror.c:34 +#: libx52/x52_strerror.c:26 msgid "Invalid parameter" msgstr "" -#: lib/libx52/x52_strerror.c:37 +#: libx52/x52_strerror.c:27 msgid "Operation not supported" msgstr "" -#: lib/libx52/x52_strerror.c:40 +#: libx52/x52_strerror.c:28 msgid "Try again" msgstr "" -#: lib/libx52/x52_strerror.c:43 +#: libx52/x52_strerror.c:29 msgid "Input parameter out of range" msgstr "" -#: lib/libx52/x52_strerror.c:46 +#: libx52/x52_strerror.c:30 msgid "USB transaction failure" msgstr "" -#: lib/libx52/x52_strerror.c:49 +#: libx52/x52_strerror.c:31 msgid "USB input/output error" msgstr "" -#: lib/libx52/x52_strerror.c:52 +#: libx52/x52_strerror.c:32 msgid "Access denied" msgstr "" -#: lib/libx52/x52_strerror.c:55 +#: libx52/x52_strerror.c:33 msgid "No such device" msgstr "" -#: lib/libx52/x52_strerror.c:58 +#: libx52/x52_strerror.c:34 msgid "Entity not found" msgstr "" -#: lib/libx52/x52_strerror.c:61 +#: libx52/x52_strerror.c:35 msgid "Resource busy" msgstr "" -#: lib/libx52/x52_strerror.c:64 +#: libx52/x52_strerror.c:36 msgid "Operation timeout" msgstr "" -#: lib/libx52/x52_strerror.c:67 +#: libx52/x52_strerror.c:37 msgid "Overflow" msgstr "" -#: lib/libx52/x52_strerror.c:70 +#: libx52/x52_strerror.c:38 msgid "Pipe error" msgstr "" -#: lib/libx52/x52_strerror.c:73 +#: libx52/x52_strerror.c:39 msgid "System call interrupted" msgstr "" -#: lib/libx52/x52_strerror.c:77 lib/libx52io/io_strings.c:125 +#: libx52/x52_strerror.c:66 libx52io/io_strings.c:125 #, c-format msgid "Unknown error %d" msgstr "" -#: lib/libx52io/io_strings.c:110 +#: libx52/x52_stringify.c:29 +#, c-format +msgid "Unknown clock ID %d" +msgstr "" + +#: libx52/x52_stringify.c:30 +msgid "primary" +msgstr "" + +#: libx52/x52_stringify.c:31 +msgid "secondary" +msgstr "" + +#: libx52/x52_stringify.c:32 +msgid "tertiary" +msgstr "" + +#: libx52/x52_stringify.c:35 +#, c-format +msgid "Unknown clock format %d" +msgstr "" + +#: libx52/x52_stringify.c:36 +msgid "12 hour" +msgstr "" + +#: libx52/x52_stringify.c:37 +msgid "24 hour" +msgstr "" + +#: libx52/x52_stringify.c:40 +#, c-format +msgid "Unknown date format %d" +msgstr "" + +#: libx52/x52_stringify.c:41 +msgid "DD-MM-YY" +msgstr "" + +#: libx52/x52_stringify.c:42 +msgid "MM-DD-YY" +msgstr "" + +#: libx52/x52_stringify.c:43 +msgid "YY-MM-DD" +msgstr "" + +#: libx52/x52_stringify.c:46 +#, c-format +msgid "Unknown LED state %d" +msgstr "" + +#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 +msgid "off" +msgstr "" + +#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 +msgid "on" +msgstr "" + +#: libx52/x52_stringify.c:49 +msgid "red" +msgstr "" + +#: libx52/x52_stringify.c:50 +msgid "amber" +msgstr "" + +#: libx52/x52_stringify.c:51 +msgid "green" +msgstr "" + +#: libx52/x52_stringify.c:60 +msgid "Fire" +msgstr "" + +#: libx52/x52_stringify.c:63 +msgid "A" +msgstr "" + +#: libx52/x52_stringify.c:66 +msgid "B" +msgstr "" + +#: libx52/x52_stringify.c:69 +msgid "D" +msgstr "" + +#: libx52/x52_stringify.c:72 +msgid "E" +msgstr "" + +#: libx52/x52_stringify.c:75 +msgid "T1" +msgstr "" + +#: libx52/x52_stringify.c:78 +msgid "T2" +msgstr "" + +#: libx52/x52_stringify.c:81 +msgid "T3" +msgstr "" + +#: libx52/x52_stringify.c:84 +msgid "POV" +msgstr "" + +#: libx52/x52_stringify.c:87 +msgid "Clutch" +msgstr "" + +#: libx52/x52_stringify.c:90 +msgid "Throttle" +msgstr "" + +#: libx52/x52_stringify.c:93 +#, c-format +msgid "Unknown LED ID %d" +msgstr "" + +#: libx52io/io_strings.c:103 msgid "No device" msgstr "" -#: lib/libx52io/io_strings.c:113 +#: libx52io/io_strings.c:104 msgid "Invalid arguments" msgstr "" -#: lib/libx52io/io_strings.c:116 +#: libx52io/io_strings.c:105 msgid "Connection failure" msgstr "" -#: lib/libx52io/io_strings.c:119 +#: libx52io/io_strings.c:106 msgid "I/O error" msgstr "" -#: lib/libx52io/io_strings.c:122 +#: libx52io/io_strings.c:107 msgid "Read timeout" msgstr "" -#: utils/evtest/ev_test.c:109 +#: evtest/ev_test.c:109 #, c-format msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n" msgstr "" -#: utils/evtest/ev_test.c:113 +#: evtest/ev_test.c:113 #, c-format msgid "Device name: \"%s %s\"\n" msgstr "" -#: utils/evtest/ev_test.c:116 +#: evtest/ev_test.c:116 #, c-format msgid "Serial number: \"%s\"\n" msgstr "" -#: utils/evtest/ev_test.c:117 +#: evtest/ev_test.c:117 msgid "Testing (interrupt to exit)\n" msgstr "" -#: utils/evtest/ev_test.c:157 utils/evtest/ev_test.c:165 +#: evtest/ev_test.c:157 evtest/ev_test.c:165 #, c-format msgid "Event @ %ld.%06ld: %s, value %d\n" msgstr "" -#: utils/test/x52_test.c:97 +#: joytest/x52_test.c:97 msgid "Test brightness scale (~ 1m)" msgstr "" -#: utils/test/x52_test.c:98 +#: joytest/x52_test.c:98 msgid "Test LED states (~ 45s)" msgstr "" -#: utils/test/x52_test.c:99 +#: joytest/x52_test.c:99 msgid "Test MFD string display (~ 30s)" msgstr "" -#: utils/test/x52_test.c:100 +#: joytest/x52_test.c:100 msgid "Test MFD displays all characters (~ 2m 15s)" msgstr "" -#: utils/test/x52_test.c:101 +#: joytest/x52_test.c:101 msgid "Test the blink and shift commands (< 10s)" msgstr "" -#: utils/test/x52_test.c:102 +#: joytest/x52_test.c:102 msgid "Test the clock commands (~1m)" msgstr "" -#: utils/test/x52_test.c:126 +#: joytest/x52_test.c:126 msgid "" "x52test is a suite of tests to write to the X52 Pro device\n" "and test the extra functionality available in the LEDs and MFD\n" msgstr "" -#: utils/test/x52_test.c:130 +#: joytest/x52_test.c:130 msgid "These tests take roughly 6 minutes to run" msgstr "" -#: utils/test/x52_test.c:132 +#: joytest/x52_test.c:132 msgid "Press Enter to begin the tests, press Ctrl-C to abort anytime" msgstr "" -#: utils/test/x52_test.c:138 +#: joytest/x52_test.c:138 #, c-format msgid "Unable to initialize X52 library: %s\n" msgstr "" -#: utils/test/x52_test.c:153 +#: joytest/x52_test.c:153 msgid "All tests completed successfully" msgstr "" -#: utils/test/x52_test.c:155 +#: joytest/x52_test.c:155 #, c-format msgid "Got error %s\n" msgstr "" -#: utils/test/x52_test.c:157 +#: joytest/x52_test.c:157 #, c-format msgid "Received %s signal, quitting...\n" msgstr "" -#: utils/test/x52_test.c:176 +#: joytest/x52_test.c:176 msgid "" "These are the available tests with a description and\n" "approximate runtime. Not specifying any tests will run\n" "all the tests\n" msgstr "" -#: utils/test/x52_test.c:180 +#: joytest/x52_test.c:180 msgid "List of tests:" msgstr "" -#: utils/test/x52_test.c:230 +#: joytest/x52_test.c:230 #, c-format msgid "" "Usage: %s [list of tests]\n" "\n" msgstr "" -#: utils/test/x52_test.c:244 +#: joytest/x52_test.c:244 #, c-format msgid "" "Unrecognized test identifier: %s\n" "\n" msgstr "" -#: utils/test/x52_test.c:257 +#: joytest/x52_test.c:257 msgid "Not running any tests" msgstr "" -#: utils/test/x52_test_clock.c:32 +#: joytest/x52_test_clock.c:32 msgid "Clock" msgstr "" -#: utils/test/x52_test_clock.c:33 +#: joytest/x52_test_clock.c:33 msgid "This tests the clock display" msgstr "" -#: utils/test/x52_test_clock.c:38 +#: joytest/x52_test_clock.c:38 msgid "" "\n" "Testing clock time minute display for 90 minutes" msgstr "" -#: utils/test/x52_test_clock.c:44 +#: joytest/x52_test_clock.c:44 msgid "" "\n" "Testing clock time hour display for 36 hours, 12 hour mode" msgstr "" -#: utils/test/x52_test_clock.c:47 +#: joytest/x52_test_clock.c:47 msgid "" "\n" "Testing clock time hour display for 36 hours, 24 hour mode" msgstr "" -#: utils/test/x52_test_clock.c:52 +#: joytest/x52_test_clock.c:52 msgid "" "\n" "Testing clock date display for 31 days, dd-mm-yy" msgstr "" -#: utils/test/x52_test_clock.c:56 +#: joytest/x52_test_clock.c:56 msgid "" "\n" "Testing clock date display for 31 days, mm-dd-yy" msgstr "" -#: utils/test/x52_test_clock.c:60 +#: joytest/x52_test_clock.c:60 msgid "" "\n" "Testing clock date display for 31 days, yy-mm-dd" msgstr "" -#: utils/test/x52_test_common.h:26 +#: joytest/x52_test_common.h:26 #, c-format msgid "" "\n" "%s(%s) failed with %d(%s)\n" msgstr "" -#: utils/test/x52_test_common.h:32 +#: joytest/x52_test_common.h:32 #, c-format msgid "" "\n" "update failed with %d(%s)\n" msgstr "" -#: utils/test/x52_test_led.c:19 +#: joytest/x52_test_led.c:19 #, c-format msgid "LED %s - %s\n" msgstr "" -#: utils/test/x52_test_led.c:25 utils/test/x52_test_led.c:32 +#: joytest/x52_test_led.c:25 joytest/x52_test_led.c:32 #, c-format msgid "" "\n" "Testing LED %s\n" msgstr "" -#: utils/test/x52_test_led.c:42 +#: joytest/x52_test_led.c:42 msgid "LEDs" msgstr "" -#: utils/test/x52_test_led.c:48 +#: joytest/x52_test_led.c:48 msgid "Skipping LED tests since the device does not support LED control" msgstr "" -#: utils/test/x52_test_led.c:55 +#: joytest/x52_test_led.c:55 msgid "This cycles the LEDs through all possible states" msgstr "" -#: utils/test/x52_test_led.c:73 +#: joytest/x52_test_led.c:73 #, c-format msgid "" "\n" "Testing %s\n" msgstr "" -#: utils/test/x52_test_led.c:84 +#: joytest/x52_test_led.c:84 msgid "Blink & Shift" msgstr "" -#: utils/test/x52_test_led.c:85 +#: joytest/x52_test_led.c:85 msgid "This tests the blink indicator and shift functionality" msgstr "" -#: utils/test/x52_test_mfd.c:24 +#: joytest/x52_test_mfd.c:24 msgid "Brightness" msgstr "" -#: utils/test/x52_test_mfd.c:26 +#: joytest/x52_test_mfd.c:26 msgid "This test cycles through the MFD and LED brightness scales" msgstr "" -#: utils/test/x52_test_mfd.c:29 +#: joytest/x52_test_mfd.c:29 msgid "" "\n" "MFD: " msgstr "" -#: utils/test/x52_test_mfd.c:36 +#: joytest/x52_test_mfd.c:36 msgid "" "\n" "LED: " msgstr "" -#: utils/test/x52_test_mfd.c:55 +#: joytest/x52_test_mfd.c:55 msgid "MFD text" msgstr "" -#: utils/test/x52_test_mfd.c:56 +#: joytest/x52_test_mfd.c:56 msgid "This test tests the character displays of the MFD\n" msgstr "" -#: utils/test/x52_test_mfd.c:60 +#: joytest/x52_test_mfd.c:60 #, c-format msgid "Writing characters %s\n" msgstr "" -#: utils/test/x52_test_mfd.c:82 +#: joytest/x52_test_mfd.c:82 msgid "MFD display" msgstr "" -#: utils/test/x52_test_mfd.c:83 +#: joytest/x52_test_mfd.c:83 msgid "" "This test checks if the display elements can display all characters\n" "You should see the display cycling through each character, with every\n" "cell displaying the same character\n" msgstr "" -#: utils/test/x52_test_mfd.c:88 +#: joytest/x52_test_mfd.c:88 #, c-format msgid "Testing character 0x%02x..." msgstr "" -#: utils/test/x52_test_mfd.c:96 +#: joytest/x52_test_mfd.c:96 msgid "OK" msgstr "" + +#: daemon/x52d_main.c:50 +#, c-format +msgid "Error %d setting log file: %s\n" +msgstr "" + +#: daemon/x52d_main.c:66 +#, c-format +msgid "Error %d installing handler for signal %d: %s" +msgstr "" + +#: daemon/x52d_main.c:77 +#, c-format +msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n" +msgstr "" + +#: daemon/x52d_main.c:138 +#, c-format +msgid "Unable to parse configuration override '%s'\n" +msgstr "" + +#: daemon/x52d_main.c:158 +#, c-format +msgid "Foreground = %s" +msgstr "" + +#: daemon/x52d_main.c:158 daemon/x52d_main.c:159 +msgid "true" +msgstr "" + +#: daemon/x52d_main.c:158 daemon/x52d_main.c:159 +msgid "false" +msgstr "" + +#: daemon/x52d_main.c:159 +#, c-format +msgid "Quiet = %s" +msgstr "" + +#: daemon/x52d_main.c:160 +#, c-format +msgid "Verbosity = %d" +msgstr "" + +#: daemon/x52d_main.c:161 +#, c-format +msgid "Log file = %s" +msgstr "" + +#: daemon/x52d_main.c:162 +#, c-format +msgid "Config file = %s" +msgstr "" + +#: daemon/x52d_main.c:188 +msgid "Reloading X52 configuration" +msgstr "" + +#: daemon/x52d_main.c:198 +msgid "Shutting down X52 daemon" +msgstr "" + +#: daemon/x52d_clock.c:27 +#, c-format +msgid "Setting clock enable to %s" +msgstr "" + +#: daemon/x52d_clock.c:34 daemon/x52d_clock.c:112 +#, c-format +msgid "Setting %s clock timezone to %s" +msgstr "" + +#: daemon/x52d_clock.c:36 +msgid "local" +msgstr "" + +#: daemon/x52d_clock.c:36 +msgid "UTC" +msgstr "" + +#: daemon/x52d_clock.c:53 +msgid "Unable to allocate memory for timezone. Falling back to UTC" +msgstr "" + +#: daemon/x52d_clock.c:63 +msgid "Unable to backup timezone environment. Falling back to UTC" +msgstr "" + +#: daemon/x52d_clock.c:129 +#, c-format +msgid "Setting %s clock format to %s" +msgstr "" + +#: daemon/x52d_clock.c:151 +#, c-format +msgid "Setting date format to %s" +msgstr "" + +#: daemon/x52d_clock.c:161 +msgid "Starting X52 clock manager thread" +msgstr "" + +#: daemon/x52d_clock.c:172 +#, c-format +msgid "Error %d retrieving current time: %s" +msgstr "" + +#: daemon/x52d_clock.c:193 +#, c-format +msgid "Error %d initializing clock thread: %s" +msgstr "" + +#: daemon/x52d_clock.c:200 +msgid "Shutting down X52 clock manager thread" +msgstr "" + +#: daemon/x52d_config.c:26 +#, c-format +msgid "Error %d setting configuration defaults: %s" +msgstr "" + +#: daemon/x52d_config_parser.c:164 +#, c-format +msgid "Ignoring unknown key '%s.%s'" +msgstr "" + +#: daemon/x52d_config_parser.c:205 +#, c-format +msgid "Failed processing configuration file %s - code %d" +msgstr "" + +#: daemon/x52d_config_parser.c:235 +msgid "Failed to allocate memory for override structure" +msgstr "" + +#: daemon/x52d_config_parser.c:244 +msgid "Failed to allocate memory for override string" +msgstr "" + +#: daemon/x52d_config_parser.c:255 +#, c-format +msgid "No section found in override string '%s'" +msgstr "" + +#: daemon/x52d_config_parser.c:269 +#, c-format +msgid "No key found in override string '%s'" +msgstr "" + +#: daemon/x52d_config_parser.c:280 +#, c-format +msgid "No value found in override string '%s'" +msgstr "" + +#: daemon/x52d_config_parser.c:331 +#, c-format +msgid "Error processing override '%s.%s=%s'" +msgstr "" + +#: daemon/x52d_device.c:35 +msgid "Starting X52 device acquisition thread" +msgstr "" + +#: daemon/x52d_device.c:50 +#, c-format +msgid "Error %d connecting to device: %s" +msgstr "" + +#: daemon/x52d_device.c:82 +msgid "Starting X52 device update thread" +msgstr "" + +#: daemon/x52d_device.c:101 +msgid "Initializing libx52" +msgstr "" + +#: daemon/x52d_device.c:105 +#, c-format +msgid "Failure %d initializing libx52: %s" +msgstr "" + +#: daemon/x52d_device.c:124 +msgid "Shutting down X52 device acquisition thread" +msgstr "" + +#: daemon/x52d_device.c:127 +msgid "Shutting down X52 device update thread" +msgstr "" + +#: daemon/x52d_device.c:140 +#, c-format +msgid "Error %d when updating X52 parameter: %s" +msgstr "" + +#: daemon/x52d_device.c:220 +#, c-format +msgid "Error %d when updating X52 device: %s" +msgstr "" diff --git a/po/xx_PL.po b/po/xx_PL.po index 0f3d893..f5a4e9a 100644 --- a/po/xx_PL.po +++ b/po/xx_PL.po @@ -7,158 +7,279 @@ msgid "" msgstr "" "Project-Id-Version: x52pro-linux 0.2.1\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2020-07-16 04:24-0700\n" -"PO-Revision-Date: 2020-07-13 18:05-0700\n" +"POT-Creation-Date: 2021-07-29 22:58-0700\n" +"PO-Revision-Date: 2021-07-27 02:08-0700\n" "Last-Translator: Nirenjan Krishnan \n" "Language-Team: Dummy Language for testing i18n\n" "Language: xx_PL\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.3.1\n" +"X-Generator: Poedit 3.0\n" -#: lib/libx52/x52_strerror.c:25 lib/libx52io/io_strings.c:104 +#: libx52/x52_strerror.c:23 libx52io/io_strings.c:101 msgid "Success" msgstr "Uccesssay" -#: lib/libx52/x52_strerror.c:28 lib/libx52io/io_strings.c:107 +#: libx52/x52_strerror.c:24 libx52io/io_strings.c:102 msgid "Initialization failure" msgstr "Initializationay ailurefay" -#: lib/libx52/x52_strerror.c:31 +#: libx52/x52_strerror.c:25 msgid "Insufficient memory" msgstr "Insufficientay emorymay" -#: lib/libx52/x52_strerror.c:34 +#: libx52/x52_strerror.c:26 msgid "Invalid parameter" msgstr "Invaliday arameterpay" -#: lib/libx52/x52_strerror.c:37 +#: libx52/x52_strerror.c:27 msgid "Operation not supported" msgstr "Operationay otnay upportedsay" -#: lib/libx52/x52_strerror.c:40 +#: libx52/x52_strerror.c:28 msgid "Try again" msgstr "Ytray againay" -#: lib/libx52/x52_strerror.c:43 +#: libx52/x52_strerror.c:29 msgid "Input parameter out of range" msgstr "Inputay arameterpay outay ofay angeray" -#: lib/libx52/x52_strerror.c:46 +#: libx52/x52_strerror.c:30 msgid "USB transaction failure" -msgstr "USBay ransactiontay ailurefay" +msgstr "USBay ansactiontray ailurefay" -#: lib/libx52/x52_strerror.c:49 +#: libx52/x52_strerror.c:31 msgid "USB input/output error" msgstr "USBay inputay/outputay erroray" -#: lib/libx52/x52_strerror.c:52 +#: libx52/x52_strerror.c:32 msgid "Access denied" msgstr "Accessay eniedday" -#: lib/libx52/x52_strerror.c:55 +#: libx52/x52_strerror.c:33 msgid "No such device" msgstr "Onay uchsay eviceday" -#: lib/libx52/x52_strerror.c:58 +#: libx52/x52_strerror.c:34 msgid "Entity not found" msgstr "Entityay otnay oundfay" -#: lib/libx52/x52_strerror.c:61 +#: libx52/x52_strerror.c:35 msgid "Resource busy" msgstr "Esourceray usybay" -#: lib/libx52/x52_strerror.c:64 +#: libx52/x52_strerror.c:36 msgid "Operation timeout" msgstr "Operationay imeouttay" -#: lib/libx52/x52_strerror.c:67 +#: libx52/x52_strerror.c:37 msgid "Overflow" msgstr "Overfloway" -#: lib/libx52/x52_strerror.c:70 +#: libx52/x52_strerror.c:38 msgid "Pipe error" msgstr "Ipepay erroray" -#: lib/libx52/x52_strerror.c:73 +#: libx52/x52_strerror.c:39 msgid "System call interrupted" msgstr "Ystemsay allcay interrupteday" -#: lib/libx52/x52_strerror.c:77 lib/libx52io/io_strings.c:125 +#: libx52/x52_strerror.c:66 libx52io/io_strings.c:125 #, c-format msgid "Unknown error %d" msgstr "Unknownay erroray %d" -#: lib/libx52io/io_strings.c:110 +#: libx52/x52_stringify.c:29 +#, c-format +msgid "Unknown clock ID %d" +msgstr "Unknownay ockclay IDay %d" + +#: libx52/x52_stringify.c:30 +msgid "primary" +msgstr "imarypray" + +#: libx52/x52_stringify.c:31 +msgid "secondary" +msgstr "econdarysay" + +#: libx52/x52_stringify.c:32 +msgid "tertiary" +msgstr "ertiarytay" + +#: libx52/x52_stringify.c:35 +#, c-format +msgid "Unknown clock format %d" +msgstr "Unknownay ockclay ormatfay %d" + +#: libx52/x52_stringify.c:36 +msgid "12 hour" +msgstr "12 ourhay" + +#: libx52/x52_stringify.c:37 +msgid "24 hour" +msgstr "24 ourhay" + +#: libx52/x52_stringify.c:40 +#, c-format +msgid "Unknown date format %d" +msgstr "Unknownay ateday ormatfay %d" + +#: libx52/x52_stringify.c:41 +msgid "DD-MM-YY" +msgstr "DDay-MMay-YYay" + +#: libx52/x52_stringify.c:42 +msgid "MM-DD-YY" +msgstr "MMay-DDay-YYay" + +#: libx52/x52_stringify.c:43 +msgid "YY-MM-DD" +msgstr "YYay-MMay-DDay" + +#: libx52/x52_stringify.c:46 +#, c-format +msgid "Unknown LED state %d" +msgstr "Unknownay EDLay atestay %d" + +#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 +msgid "off" +msgstr "offay" + +#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 +msgid "on" +msgstr "onay" + +#: libx52/x52_stringify.c:49 +msgid "red" +msgstr "edray" + +#: libx52/x52_stringify.c:50 +msgid "amber" +msgstr "amberay" + +#: libx52/x52_stringify.c:51 +msgid "green" +msgstr "eengray" + +#: libx52/x52_stringify.c:60 +msgid "Fire" +msgstr "Irefay" + +#: libx52/x52_stringify.c:63 +msgid "A" +msgstr "Ay" + +#: libx52/x52_stringify.c:66 +msgid "B" +msgstr "Bay" + +#: libx52/x52_stringify.c:69 +msgid "D" +msgstr "Day" + +#: libx52/x52_stringify.c:72 +msgid "E" +msgstr "Eay" + +#: libx52/x52_stringify.c:75 +msgid "T1" +msgstr "Tay1" + +#: libx52/x52_stringify.c:78 +msgid "T2" +msgstr "Tay2" + +#: libx52/x52_stringify.c:81 +msgid "T3" +msgstr "Tay3" + +#: libx52/x52_stringify.c:84 +msgid "POV" +msgstr "OVPay" + +#: libx52/x52_stringify.c:87 +msgid "Clutch" +msgstr "Utchclay" + +#: libx52/x52_stringify.c:90 +msgid "Throttle" +msgstr "Ottlethray" + +#: libx52/x52_stringify.c:93 +#, c-format +msgid "Unknown LED ID %d" +msgstr "Unknownay EDLay IDay %d" + +#: libx52io/io_strings.c:103 msgid "No device" msgstr "Onay eviceday" -#: lib/libx52io/io_strings.c:113 +#: libx52io/io_strings.c:104 msgid "Invalid arguments" msgstr "Invaliday argumentsay" -#: lib/libx52io/io_strings.c:116 +#: libx52io/io_strings.c:105 msgid "Connection failure" msgstr "Onnectioncay ailurefay" -#: lib/libx52io/io_strings.c:119 +#: libx52io/io_strings.c:106 msgid "I/O error" msgstr "I/O erroray" -#: lib/libx52io/io_strings.c:122 +#: libx52io/io_strings.c:107 msgid "Read timeout" msgstr "Eadray imeouttay" -#: utils/evtest/ev_test.c:109 +#: evtest/ev_test.c:109 #, c-format msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n" msgstr "Eviceday IDay: endorvay 0x%04x oductpray 0x%04x ersionvay 0x%04x\n" -#: utils/evtest/ev_test.c:113 +#: evtest/ev_test.c:113 #, c-format msgid "Device name: \"%s %s\"\n" msgstr "Eviceday amenay: \"%s %s\"\n" -#: utils/evtest/ev_test.c:116 +#: evtest/ev_test.c:116 #, c-format msgid "Serial number: \"%s\"\n" msgstr "Erialsay umbernay: \"%s\"\n" -#: utils/evtest/ev_test.c:117 +#: evtest/ev_test.c:117 msgid "Testing (interrupt to exit)\n" msgstr "Estingtay (interruptay otay exitay)\n" -#: utils/evtest/ev_test.c:157 utils/evtest/ev_test.c:165 +#: evtest/ev_test.c:157 evtest/ev_test.c:165 #, c-format msgid "Event @ %ld.%06ld: %s, value %d\n" msgstr "Eventay @ %ld.%06ld: %s, aluevay %d\n" -#: utils/test/x52_test.c:97 +#: joytest/x52_test.c:97 msgid "Test brightness scale (~ 1m)" msgstr "Esttay ightnessbray alescay (~ 1m)" -#: utils/test/x52_test.c:98 +#: joytest/x52_test.c:98 msgid "Test LED states (~ 45s)" msgstr "Esstay EDLay atesstay (~ 45s)" -#: utils/test/x52_test.c:99 +#: joytest/x52_test.c:99 msgid "Test MFD string display (~ 30s)" msgstr "Esttay MFDay ingstray isplayday (~ 30s)" -#: utils/test/x52_test.c:100 +#: joytest/x52_test.c:100 msgid "Test MFD displays all characters (~ 2m 15s)" msgstr "Esttay MFDay isplaysday allay aracterschay (~ 2m 15s)" -#: utils/test/x52_test.c:101 +#: joytest/x52_test.c:101 msgid "Test the blink and shift commands (< 10s)" msgstr "Esttay ethay inkblay anday iftshay ommandscay (< 10s)" -#: utils/test/x52_test.c:102 +#: joytest/x52_test.c:102 msgid "Test the clock commands (~1m)" msgstr "Esttay ethay ockclay ommandscay (~1m)" -#: utils/test/x52_test.c:126 +#: joytest/x52_test.c:126 msgid "" "x52test is a suite of tests to write to the X52 Pro device\n" "and test the extra functionality available in the LEDs and MFD\n" @@ -167,36 +288,36 @@ msgstr "" "X52 Pro eviceday anday esttay ethay extray unctionalityfay\n" "availableay inay ethay EDsLay anday FDMay\n" -#: utils/test/x52_test.c:130 +#: joytest/x52_test.c:130 msgid "These tests take roughly 6 minutes to run" msgstr "Esethay eststay aketay oughlyray 6 inutesmay otay unray" -#: utils/test/x52_test.c:132 +#: joytest/x52_test.c:132 msgid "Press Enter to begin the tests, press Ctrl-C to abort anytime" msgstr "" "Esspray Enteray otay eginbay ethay eststay, esspray Ctrl-C otay abortay " "anytimeay" -#: utils/test/x52_test.c:138 +#: joytest/x52_test.c:138 #, c-format msgid "Unable to initialize X52 library: %s\n" msgstr "Unableay otay initializeay X52 ibrarylay: %s\n" -#: utils/test/x52_test.c:153 +#: joytest/x52_test.c:153 msgid "All tests completed successfully" msgstr "Allay eststay ompletedcay uccessfullysay" -#: utils/test/x52_test.c:155 +#: joytest/x52_test.c:155 #, c-format msgid "Got error %s\n" msgstr "Otgay erroray %s\n" -#: utils/test/x52_test.c:157 +#: joytest/x52_test.c:157 #, c-format msgid "Received %s signal, quitting...\n" msgstr "Eceivedray %s ignalsay, uittingqay...\n" -#: utils/test/x52_test.c:176 +#: joytest/x52_test.c:176 msgid "" "These are the available tests with a description and\n" "approximate runtime. Not specifying any tests will run\n" @@ -207,18 +328,18 @@ msgstr "" "ecifyingspay anyay eststay illway unray allay ethay\n" "eststay\n" -#: utils/test/x52_test.c:180 +#: joytest/x52_test.c:180 msgid "List of tests:" msgstr "Istlay ofay eststay:" -#: utils/test/x52_test.c:230 +#: joytest/x52_test.c:230 #, c-format msgid "" "Usage: %s [list of tests]\n" "\n" msgstr "Usageay: %s [istlay ofay eststay]\n" -#: utils/test/x52_test.c:244 +#: joytest/x52_test.c:244 #, c-format msgid "" "Unrecognized test identifier: %s\n" @@ -227,19 +348,19 @@ msgstr "" "Unrecognizeday esttay identifieray: %s\n" "\n" -#: utils/test/x52_test.c:257 +#: joytest/x52_test.c:257 msgid "Not running any tests" msgstr "Otnay unningray anyay eststay" -#: utils/test/x52_test_clock.c:32 +#: joytest/x52_test_clock.c:32 msgid "Clock" msgstr "Ockclay" -#: utils/test/x52_test_clock.c:33 +#: joytest/x52_test_clock.c:33 msgid "This tests the clock display" msgstr "Isthay eststay ethay ockclay isplayday" -#: utils/test/x52_test_clock.c:38 +#: joytest/x52_test_clock.c:38 msgid "" "\n" "Testing clock time minute display for 90 minutes" @@ -247,7 +368,7 @@ msgstr "" "\n" "Estingtay ockclay imetay inutemay isplayday orfay 90 inutesmay" -#: utils/test/x52_test_clock.c:44 +#: joytest/x52_test_clock.c:44 msgid "" "\n" "Testing clock time hour display for 36 hours, 12 hour mode" @@ -255,7 +376,7 @@ msgstr "" "\n" "Estingtay ockclay imetay ourhay isplayday orfay 36 ourshay, 12 ourhay odemay" -#: utils/test/x52_test_clock.c:47 +#: joytest/x52_test_clock.c:47 msgid "" "\n" "Testing clock time hour display for 36 hours, 24 hour mode" @@ -263,7 +384,7 @@ msgstr "" "\n" "Estingtay ockclay imetay ourhay isplayday orfay 36 ourshay, 24 ourhay odemay" -#: utils/test/x52_test_clock.c:52 +#: joytest/x52_test_clock.c:52 msgid "" "\n" "Testing clock date display for 31 days, dd-mm-yy" @@ -271,7 +392,7 @@ msgstr "" "\n" "Estingtay ockclay ateday isplayday orfay 31 aysday, dd-mm-yy" -#: utils/test/x52_test_clock.c:56 +#: joytest/x52_test_clock.c:56 msgid "" "\n" "Testing clock date display for 31 days, mm-dd-yy" @@ -279,7 +400,7 @@ msgstr "" "\n" "Estingtay ockclay ateday isplayday orfay 31 aysday, mm-dd-yy" -#: utils/test/x52_test_clock.c:60 +#: joytest/x52_test_clock.c:60 msgid "" "\n" "Testing clock date display for 31 days, yy-mm-dd" @@ -287,7 +408,7 @@ msgstr "" "\n" "Estingtay ockclay ateday isplayday orfay 31 aysday, yy-mm-dd" -#: utils/test/x52_test_common.h:26 +#: joytest/x52_test_common.h:26 #, c-format msgid "" "\n" @@ -296,7 +417,7 @@ msgstr "" "\n" "%s(%s) ailedfay ithway %d(%s)\n" -#: utils/test/x52_test_common.h:32 +#: joytest/x52_test_common.h:32 #, c-format msgid "" "\n" @@ -305,12 +426,12 @@ msgstr "" "\n" "updateay ailedfay ithway %d(%s)\n" -#: utils/test/x52_test_led.c:19 +#: joytest/x52_test_led.c:19 #, c-format msgid "LED %s - %s\n" msgstr "EDLay %s - %s\n" -#: utils/test/x52_test_led.c:25 utils/test/x52_test_led.c:32 +#: joytest/x52_test_led.c:25 joytest/x52_test_led.c:32 #, c-format msgid "" "\n" @@ -319,21 +440,21 @@ msgstr "" "\n" "Estingtay EDLay %s\n" -#: utils/test/x52_test_led.c:42 +#: joytest/x52_test_led.c:42 msgid "LEDs" msgstr "EDsLay" -#: utils/test/x52_test_led.c:48 +#: joytest/x52_test_led.c:48 msgid "Skipping LED tests since the device does not support LED control" msgstr "" "Ippingskay EDLay eststay incesay ethay eviceday oesday otnay\n" "upportsay EDLay ontrolcay" -#: utils/test/x52_test_led.c:55 +#: joytest/x52_test_led.c:55 msgid "This cycles the LEDs through all possible states" msgstr "Isthay yclescay ethay EDsLay oughthray allay ossiblepay tatessay" -#: utils/test/x52_test_led.c:73 +#: joytest/x52_test_led.c:73 #, c-format msgid "" "\n" @@ -342,25 +463,25 @@ msgstr "" "\n" "Estingtay %s\n" -#: utils/test/x52_test_led.c:84 +#: joytest/x52_test_led.c:84 msgid "Blink & Shift" msgstr "Inkblay & Iftshay" -#: utils/test/x52_test_led.c:85 +#: joytest/x52_test_led.c:85 msgid "This tests the blink indicator and shift functionality" msgstr "Isthay eststay ethay inkblay indicatoray anday iftshay unctionalityfay" -#: utils/test/x52_test_mfd.c:24 +#: joytest/x52_test_mfd.c:24 msgid "Brightness" msgstr "Ightnessbray" -#: utils/test/x52_test_mfd.c:26 +#: joytest/x52_test_mfd.c:26 msgid "This test cycles through the MFD and LED brightness scales" msgstr "" "Isthay esttay yclescay oughthray ethay FDMay anday EDLay ightnessbray " "alesscay" -#: utils/test/x52_test_mfd.c:29 +#: joytest/x52_test_mfd.c:29 msgid "" "\n" "MFD: " @@ -368,7 +489,7 @@ msgstr "" "\n" "FDMay: " -#: utils/test/x52_test_mfd.c:36 +#: joytest/x52_test_mfd.c:36 msgid "" "\n" "LED: " @@ -376,24 +497,24 @@ msgstr "" "\n" "EDLay: " -#: utils/test/x52_test_mfd.c:55 +#: joytest/x52_test_mfd.c:55 msgid "MFD text" msgstr "FDMay exttay" -#: utils/test/x52_test_mfd.c:56 +#: joytest/x52_test_mfd.c:56 msgid "This test tests the character displays of the MFD\n" msgstr "Isthay esttay eststay ethay aracterchay isplaysday ofay the FDMay\n" -#: utils/test/x52_test_mfd.c:60 +#: joytest/x52_test_mfd.c:60 #, c-format msgid "Writing characters %s\n" msgstr "Itingwray aracterschay %s\n" -#: utils/test/x52_test_mfd.c:82 +#: joytest/x52_test_mfd.c:82 msgid "MFD display" msgstr "FDMay isplayday" -#: utils/test/x52_test_mfd.c:83 +#: joytest/x52_test_mfd.c:83 msgid "" "This test checks if the display elements can display all characters\n" "You should see the display cycling through each character, with every\n" @@ -404,11 +525,214 @@ msgstr "" "oughthray eachay aracterchay, ithway everyay ellcay isplayingday ethay\n" "amesay aracterchay\n" -#: utils/test/x52_test_mfd.c:88 +#: joytest/x52_test_mfd.c:88 #, c-format msgid "Testing character 0x%02x..." msgstr "Estingtay aracterchay 0x%02x..." -#: utils/test/x52_test_mfd.c:96 +#: joytest/x52_test_mfd.c:96 msgid "OK" msgstr "OKay" + +#: daemon/x52d_main.c:50 +#, c-format +msgid "Error %d setting log file: %s\n" +msgstr "Erroray %d ettingsay oglay ilefay: %s\n" + +#: daemon/x52d_main.c:66 +#, c-format +msgid "Error %d installing handler for signal %d: %s" +msgstr "Erroray %d installingay andlerhay orfay ignalsay %d: %s" + +#: daemon/x52d_main.c:77 +#, c-format +msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n" +msgstr "" +"Usageay: %s [-f] [-v] [-q] [-l oglay-ilefay] [-o overrideay] [-c onfigcay-" +"ilefay]\n" + +#: daemon/x52d_main.c:138 +#, c-format +msgid "Unable to parse configuration override '%s'\n" +msgstr "Unableay otay arsepay onfigurationcay overrideay '%s'\n" + +#: daemon/x52d_main.c:158 +#, c-format +msgid "Foreground = %s" +msgstr "Oregroundfay = %s" + +#: daemon/x52d_main.c:158 daemon/x52d_main.c:159 +msgid "true" +msgstr "uetray" + +#: daemon/x52d_main.c:158 daemon/x52d_main.c:159 +msgid "false" +msgstr "alsefay" + +#: daemon/x52d_main.c:159 +#, c-format +msgid "Quiet = %s" +msgstr "Uietqay = %s" + +#: daemon/x52d_main.c:160 +#, c-format +msgid "Verbosity = %d" +msgstr "Erbosityvay = %d" + +#: daemon/x52d_main.c:161 +#, c-format +msgid "Log file = %s" +msgstr "Oglay ilefay = %s" + +#: daemon/x52d_main.c:162 +#, c-format +msgid "Config file = %s" +msgstr "Onfigcay ilefay = %s" + +#: daemon/x52d_main.c:188 +msgid "Reloading X52 configuration" +msgstr "Eloadingray X52 onfigurationcay" + +#: daemon/x52d_main.c:198 +msgid "Shutting down X52 daemon" +msgstr "Uttingshay ownday X52 aemonday" + +#: daemon/x52d_clock.c:27 +#, c-format +msgid "Setting clock enable to %s" +msgstr "Ettingsay ockclay enableay otay %s" + +#: daemon/x52d_clock.c:34 daemon/x52d_clock.c:112 +#, c-format +msgid "Setting %s clock timezone to %s" +msgstr "Ettingsay %s ockclay imezonetay otay %s" + +#: daemon/x52d_clock.c:36 +msgid "local" +msgstr "ocallay" + +#: daemon/x52d_clock.c:36 +msgid "UTC" +msgstr "UTCay" + +#: daemon/x52d_clock.c:53 +msgid "Unable to allocate memory for timezone. Falling back to UTC" +msgstr "" +"Unableay otay allocateay emorymay orfay imezonetay. Allingfay ackbay otay " +"UTCay" + +#: daemon/x52d_clock.c:63 +msgid "Unable to backup timezone environment. Falling back to UTC" +msgstr "" +"Unableay otay ackupbay imezonetay environmentay. Allingfay ackbay otay UTCay" + +#: daemon/x52d_clock.c:129 +#, c-format +msgid "Setting %s clock format to %s" +msgstr "Ettingsay %s ockclay ormatfay otay %s" + +#: daemon/x52d_clock.c:151 +#, c-format +msgid "Setting date format to %s" +msgstr "Ettingsay ateday ormatfay otay %s" + +#: daemon/x52d_clock.c:161 +msgid "Starting X52 clock manager thread" +msgstr "Artingstay X52 ockclay anagermay eadthray" + +#: daemon/x52d_clock.c:172 +#, c-format +msgid "Error %d retrieving current time: %s" +msgstr "Erroray %d etrievingray urrentcay imetay: %s" + +#: daemon/x52d_clock.c:193 +#, c-format +msgid "Error %d initializing clock thread: %s" +msgstr "Erroray %d initializingay ockclay eadthray: %s" + +#: daemon/x52d_clock.c:200 +msgid "Shutting down X52 clock manager thread" +msgstr "Uttingshay ownday X52 ockclay anagermay eadthray" + +#: daemon/x52d_config.c:26 +#, c-format +msgid "Error %d setting configuration defaults: %s" +msgstr "Erroray %d ettingsay onfigurationcay efaultsday: %s" + +#: daemon/x52d_config_parser.c:164 +#, c-format +msgid "Ignoring unknown key '%s.%s'" +msgstr "Ignoringay unknownay eykay '%s.%s'" + +#: daemon/x52d_config_parser.c:205 +#, c-format +msgid "Failed processing configuration file %s - code %d" +msgstr "Ailedfay ocessingpray onfigurationcay ilefay %s - odecay %d" + +#: daemon/x52d_config_parser.c:235 +msgid "Failed to allocate memory for override structure" +msgstr "Ailedfay otay allocateay emorymay orfay overrideay ucturestray" + +#: daemon/x52d_config_parser.c:244 +msgid "Failed to allocate memory for override string" +msgstr "Ailedfay otay allocateay emorymay orfay overrideay ingstray" + +#: daemon/x52d_config_parser.c:255 +#, c-format +msgid "No section found in override string '%s'" +msgstr "Onay ectionsay oundfay inay overrideay ingstray '%s'" + +#: daemon/x52d_config_parser.c:269 +#, c-format +msgid "No key found in override string '%s'" +msgstr "Onay eykay oundfay inay overrideay ingstray '%s'" + +#: daemon/x52d_config_parser.c:280 +#, c-format +msgid "No value found in override string '%s'" +msgstr "Onay aluevay oundfay inay overrideay ingstray '%s'" + +#: daemon/x52d_config_parser.c:331 +#, c-format +msgid "Error processing override '%s.%s=%s'" +msgstr "Erroray ocessingpray overriday '%s.%s=%s'" + +#: daemon/x52d_device.c:35 +msgid "Starting X52 device acquisition thread" +msgstr "Artingstay X52 eviceday acquisitionay eadthray" + +#: daemon/x52d_device.c:50 +#, c-format +msgid "Error %d connecting to device: %s" +msgstr "Erroray %d onnectingcay otay eviceday: %s" + +#: daemon/x52d_device.c:82 +msgid "Starting X52 device update thread" +msgstr "Artingstay X52 eviceday updateay eadthray" + +#: daemon/x52d_device.c:101 +msgid "Initializing libx52" +msgstr "Initializingay libx52" + +#: daemon/x52d_device.c:105 +#, c-format +msgid "Failure %d initializing libx52: %s" +msgstr "Ailurefay %d initializeay libx52: %s" + +#: daemon/x52d_device.c:124 +msgid "Shutting down X52 device acquisition thread" +msgstr "Uttingshay ownday X52 eviceday acquisitionay eadthray" + +#: daemon/x52d_device.c:127 +msgid "Shutting down X52 device update thread" +msgstr "Uttingshay ownday X52 eviceday updateay eadthray" + +#: daemon/x52d_device.c:140 +#, c-format +msgid "Error %d when updating X52 parameter: %s" +msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s" + +#: daemon/x52d_device.c:220 +#, c-format +msgid "Error %d when updating X52 device: %s" +msgstr "Erroray %d enwhay updatingay X52 eviceday: %s" diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 2007129..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# Automake for x52cli tests -# -# Copyright (C) 2012-2020 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -# Source: https://stackoverflow.com/a/20831065 -LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh - -TESTS = \ - x52cli/test_leds \ - x52cli/test_brightness \ - x52cli/test_indicator \ - x52cli/test_mfd \ - x52cli/test_clock \ - x52cli/test_timezone - -EXTRA_DIST = common_infra.sh $(TESTS) - diff --git a/tests/common_infra.sh b/tests/common_infra.sh deleted file mode 100644 index 80c0e57..0000000 --- a/tests/common_infra.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/bin/bash -# Common infrastructure for the test cases -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -# 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' - -X52_MFD_BRIGHTNESS_INDEX='00b1' -X52_LED_BRIGHTNESS_INDEX='00b2' - -X52_BLINK_INDICATOR_INDEX='00b4' -X52_SHIFT_INDICATOR_INDEX='00fd' -X52_INDICATOR_STATE_ON='0051' -X52_INDICATOR_STATE_OFF='0050' - -X52_CLOCK_1_INDEX='00c0' -X52_CLOCK_2_INDEX='00c1' -X52_CLOCK_3_INDEX='00c2' -X52_CLOCK_DATE_INDEX='00c4' -X52_CLOCK_YEAR_INDEX='00c8' - -X52_MFD_LINE_0_SET_INDEX='00d1' -X52_MFD_LINE_1_SET_INDEX='00d2' -X52_MFD_LINE_2_SET_INDEX='00d4' -X52_MFD_LINE_0_CLR_INDEX='00d9' -X52_MFD_LINE_1_CLR_INDEX='00da' -X52_MFD_LINE_2_CLR_INDEX='00dc' - -find_programs() -{ - # Tests and distcheck do not work on OSX, skip the tests - if [[ $(uname -s) == [Dd]arwin* ]] - then - echo "1..0 # skip Tests not supported on OSX" - exit 0 - fi - - # Find the X52cli script - X52CLI=$(find .. -path '*/cli/x52cli' -perm -+x) - - if [[ -z "$X52CLI" ]] - then - exit 1 - fi - - # Find the x52test_log_actions program - X52LOGACT=$(find .. -path '*/libusbx52/x52test_log_actions' -perm -+x) - if [[ -z "$X52LOGACT" ]] - then - exit 1 - fi - - # Find the x52test_create_device_list program - X52DEVLIST=$(find .. -path '*/libusbx52/x52test_create_device_list' -perm -+x) - if [[ -z "$X52DEVLIST" ]] - then - exit 1 - fi -} - -# This is for additional programs that are not needed by every test case -require_programs() -{ - local skip=false - for prog in "$@" - do - if ! command -v "$prog" - then - echo "1..0 # skip Required program '$prog' not found" - skip=true - fi - done - - if $skip - then - exit 0 - fi -} - -setup_preload() -{ - # Find the libusb stub library - LIBUSB=$(find .. -name 'libusbx52.so.*.*.*' -type f) - - if [[ -z "$LIBUSB" ]] - then - exit 1 - fi - - export LD_PRELOAD=$(realpath $LIBUSB) -} - -setup_test() -{ - export LIBUSBX52_DEVICE_LIST=$(mktemp) - EXPECTED_OUTPUT=$(mktemp) - OBSERVED_OUTPUT=$(mktemp) - trap "rm -f $EXPECTED_OUTPUT $OBSERVED_OUTPUT $LIBUSBX52_DEVICE_LIST" EXIT - - $X52DEVLIST 06a3 0762 - - TEST_COUNT=0 - TEST_PASS=0 - TEST_FAIL=0 -} - -expect_pattern() -{ - TEST_NUM=$((TEST_NUM + 1)) - # Save pattern to expected output file - export LIBUSBX52_OUTPUT_DATA=$EXPECTED_OUTPUT - $X52LOGACT $@ - - # Save actual API calls to observed output file - export LIBUSBX52_OUTPUT_DATA=$OBSERVED_OUTPUT -} - -verify_output() -{ - TEST_COUNT=$(($TEST_COUNT + 1)) - if diff -q $EXPECTED_OUTPUT $OBSERVED_OUTPUT - then - echo "ok $TEST_COUNT $TEST_ID" - TEST_PASS=$(($TEST_PASS + 1)) - else - echo "not ok $TEST_COUNT $TEST_ID" - echo '# Expected:' - echo '# =========' - sed 's/^/#\t/' $EXPECTED_OUTPUT - echo '#' - echo '# Observed:' - echo '# =========' - sed 's/^/#\t/' $OBSERVED_OUTPUT - TEST_FAIL=$(($TEST_FAIL + 1)) - fi -} - -verify_test_suite() -{ - local sep='--------' - sep="$sep$sep" - sep="$sep$sep" - sep="$sep$sep" - - echo '#' $sep - echo '#' $TEST_SUITE_ID - echo '#' $sep - echo -e "# Total Tests:\t$TEST_COUNT" - echo -e "# Tests Passed:\t$TEST_PASS" - echo -e "# Tests Failed:\t$TEST_FAIL" - echo '#' $sep - - echo "1..$TEST_COUNT" -} - -set -e -find_programs -setup_test -setup_preload - diff --git a/tests/x52cli/test_brightness b/tests/x52cli/test_brightness deleted file mode 100755 index b2d279f..0000000 --- a/tests/x52cli/test_brightness +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# MFD & LED brightness tests -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh - -TEST_SUITE_ID="libx52 MFD & LED brightness tests" - -brightness_test() -{ - local unit=$(echo $1 | tr a-z A-Z) - local bri=$(printf '0x%04x' $2) - local index="\$X52_${unit}_BRIGHTNESS_INDEX" - TEST_ID="Test setting $unit brightness to $bri" - - expect_pattern $(eval echo $index) $bri - - $X52CLI bri $unit $bri - - verify_output -} - -for unit in mfd led -do - for bri in $(seq 0 128) - do - brightness_test $unit $bri - done -done - -verify_test_suite - diff --git a/tests/x52cli/test_clock b/tests/x52cli/test_clock deleted file mode 100755 index def836d..0000000 --- a/tests/x52cli/test_clock +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env bash -# Clock tests -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh - -TEST_SUITE_ID="libx52 clock tests" - -clock_test_utc() -{ - local timezone=$1 - local time_format=$2 - local date_format=$3 - TEST_ID="Test setting clock to $timezone time, $time_format, $date_format" - - local dd=$(date +%_d) - local mm=$(date +%_m) - local yy=$(date +%_y) - local hr=$(date +%_H) - local mn=$(date +%_M) - - local clock_value=$(($hr * 256 + $mn)) - if [[ $time_format == 24hr ]] - then - clock_value=$(($clock_value + 32768)) - fi - - case $date_format in - ddmmyy) - date_value=$(($mm * 256 + $dd)) - year_value=$yy - ;; - mmddyy) - date_value=$(($dd * 256 + $mm)) - year_value=$yy - ;; - yymmdd) - date_value=$(($mm * 256 + $yy)) - year_value=$dd - ;; - *) - ;; - esac - - expect_pattern \ - $X52_CLOCK_DATE_INDEX $(printf '%04x' $date_value) \ - $X52_CLOCK_YEAR_INDEX $(printf '%04x' $year_value) \ - $X52_CLOCK_1_INDEX $(printf '%04x' $clock_value) \ - - $X52CLI clock $timezone $time_format $date_format - - verify_output -} - -offset_test() -{ - local clock_id=$1 - local offset=$2 - local time_format=$3 - TEST_ID="Test setting clock $clock_id offset to $offset, $time_format" - - local index="\$X52_CLOCK_${clock_id}_INDEX" - local value=0 - - # Handle negative case - if [[ $offset -lt 0 ]] - then - value=$((-$offset)) - value=$(($value & 0x3ff)) - value=$(($value | 1024)) - else - value=$offset - fi - - if [[ $time_format == 24hr ]] - then - value=$(($value + 32768)) - fi - - expect_pattern $(eval echo $index) $(printf '%04x' $value) - - $X52CLI offset $clock_id $offset $time_format - - verify_output - -} - -raw_time_test() -{ - local hh=$1 - local mm=$2 - local time_format=$3 - TEST_ID=$(printf "Test setting time to %02d:%02d, %s" $hh $mm $time_format) - - local value=$(($hh * 256 + $mm)) - if [[ $time_format == 24hr ]] - then - value=$((value + 32768)) - fi - - expect_pattern $X52_CLOCK_1_INDEX $(printf '%04x' $value) - - $X52CLI time $hh $mm $time_format - - verify_output -} - -raw_date_test() -{ - local dd=$1 - local mm=$2 - local yy=$3 - local date_format=$4 - - case "$date_format" in - ddmmyy) - dd1=$dd - mm1=$mm - yy1=$yy - ;; - mmddyy) - dd1=$mm - mm1=$dd - yy1=$yy - ;; - yymmdd) - dd1=$yy - mm1=$mm - yy1=$dd - ;; - esac - - TEST_ID=$(printf "Test setting date in %s format to %02d-%02d-%02d" $date_format $dd1 $mm1 $yy1) - - local date_value=$(printf '%04x' $(($mm1 * 256 + $dd1))) - local year_value=$(printf '%04x' $yy1) - - expect_pattern \ - $X52_CLOCK_DATE_INDEX $date_value \ - $X52_CLOCK_YEAR_INDEX $year_value - - $X52CLI date $dd $mm $yy $date_format - - verify_output -} - -# For all test cases, we want to assume that the local timezone -# is the same as UTC, as otherwise, it can cause havoc, depending -# on when and where the tests are run. -export TZ=UTC - -for timezone in 'local' gmt -do - for time_format in 12hr 24hr - do - for date_format in ddmmyy mmddyy yymmdd - do - clock_test_utc $timezone $time_format $date_format - done - done -done - -# For the offset test cases, x52cli reinitializes the internal data -# structure every time it is called, therefore, the timezone for clock -# 1 is automatically reset to UTC. -unset TZ - -for clock in 2 3 -do - for time_format in 12hr 24hr - do - # Run offset tests for every 30 minute offset from UTC - for offset in $(seq -1020 30 1020) - do - offset_test $clock $offset $time_format - done - done -done - -# The raw time test cases are a limited set of tests, it simply runs for -# every minute from 00:00 through 00:59, then it runs for every hour from -# 00:00 through 23:00. The tests are run in both 12 hour and 24 hour mode. -for mm in $(seq 0 59) -do - for time_format in 12hr 24hr - do - raw_time_test 0 $mm $time_format - done -done - -for hh in $(seq 0 23) -do - for time_format in 12hr 24hr - do - raw_time_test $hh 0 $time_format - done -done - -# The raw date tests simply verify that the date February 1, year 3 is -# displayed correctly in all 3 date formats -for date_format in ddmmyy mmddyy yymmdd -do - raw_date_test 1 2 3 $date_format -done - -verify_test_suite - diff --git a/tests/x52cli/test_indicator b/tests/x52cli/test_indicator deleted file mode 100755 index 8b4dcbb..0000000 --- a/tests/x52cli/test_indicator +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -# Indicator (blink & shift) tests -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh - -TEST_SUITE_ID="libx52 indicator tests (blink & shift)" - -indicator_test() -{ - local indicator=$(echo $1 | tr a-z A-Z) - local state=$(echo $2 | tr a-z A-Z) - local index="\$X52_${indicator}_INDICATOR_INDEX" - local value="\$X52_INDICATOR_STATE_${state}" - TEST_ID="Test setting $indicator $state" - - expect_pattern $(eval echo $index $value) - - $X52CLI $indicator $state - - verify_output -} - -for indicator in blink shift -do - for state in on off - do - indicator_test $indicator $state - done -done - -verify_test_suite - diff --git a/tests/x52cli/test_leds b/tests/x52cli/test_leds deleted file mode 100755 index 569410c..0000000 --- a/tests/x52cli/test_leds +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash -# LED tests -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh - -TEST_SUITE_ID="libx52 LED state tests" - -mono_led_test() -{ - local led_ident=$(echo $1 | tr a-z A-Z) - local led_state=$2 - local state=$(echo "\$X52_LED_${led_ident}_${led_state}" | tr a-z A-Z) - local TEST_ID="Test setting the $led_ident button $led_state" - - expect_pattern $X52_LED_COMMAND_INDEX $(eval echo $state) - - $X52CLI led $led_ident $led_state - - verify_output -} - -color_led_test() -{ - local led_ident=$(echo $1 | tr a-z A-Z) - local led_color=$(echo $2 | tr A-Z a-z) - local led_r_state=off - local led_g_state=off - local TEST_ID="Test setting the $led_ident button to $led_color" - - case $led_color in - 'red') - led_r_state=on - ;; - 'green') - led_g_state=on - ;; - 'amber') - led_r_state=on - led_g_state=on - ;; - 'off') - ;; - *) - echo "ERROR: Unknown ident" >&2 - exit $EXIT_HARD_ERROR - ;; - 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) - - expect_pattern \ - $X52_LED_COMMAND_INDEX $(eval echo $led_r_state) \ - $X52_LED_COMMAND_INDEX $(eval echo $led_g_state) - - $X52CLI led $led_ident $led_color - - verify_output -} - -# Run Mono-color LED tests -for led in fire throttle -do - for state in on off - do - mono_led_test $led $state - done -done - -# Run multi-color LED tests -for led in a b d e t1 t2 t3 pov clutch -do - for color in off red amber green - do - color_led_test $led $color - done -done - -verify_test_suite diff --git a/tests/x52cli/test_mfd b/tests/x52cli/test_mfd deleted file mode 100755 index 0784080..0000000 --- a/tests/x52cli/test_mfd +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env bash -# MFD tests -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh - -TEST_SUITE_ID="libx52 MFD text tests" - -# Take in input as a string, and convert them to list of MFD set format -format_text() -{ - local clear_index=$(eval echo $1) - local set_index=$(eval echo $2) - local input_string=$3 - local output_list="$clear_index 0" - local count=0 - - while [[ ${#input_string} -gt 1 ]] - do - char1=${input_string:0:1} - char2=${input_string:1:1} - input_string=${input_string:2} - output_list="$output_list $set_index $(printf '%02x%02x' \'$char2 \'$char1)" - ((count+=2)) - - # The library ignores strings longer than 16 characters - if [[ $count -eq 16 ]] - then - # Discard the rest of the input string - input_string= - fi - done - - if [[ ${#input_string} -eq 1 ]] - then - # Add the remaining character, but pad with a space - output_list="$output_list $set_index $(printf '20%02x' \'$input_string)" - fi - - echo $output_list - return 0 -} - -mfd_text_test() -{ - local line=$1 - local clear_index="\$X52_MFD_LINE_${line}_CLR_INDEX" - local set_index="\$X52_MFD_LINE_${line}_SET_INDEX" - local text="$2" - TEST_ID="Test setting MFD line $line to '$text'" - - pattern=$(format_text $clear_index $set_index "$text") - expect_pattern $pattern - - $X52CLI mfd $line "$text" - - verify_output -} - -for text in \ - a \ - ab \ - abc \ - abcd \ - abcde \ - abcdef \ - abcdefg \ - abcdefgh \ - abcdefghi \ - abcdefghij \ - abcdefghijk \ - abcdefghijkl \ - abcdefghijklm \ - abcdefghijklmn \ - abcdefghijklmno \ - abcdefghijklmnop \ - abcdefghijklmnopq \ - abcdefghijklmnopqr \ - ; -do - for line in 0 1 2 - do - mfd_text_test $line "$text" - done -done - -verify_test_suite - diff --git a/tests/x52cli/test_timezone b/tests/x52cli/test_timezone deleted file mode 100755 index 5c65453..0000000 --- a/tests/x52cli/test_timezone +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash -# Timezone tests -# -# Copyright (C) 2020 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -source $(dirname $0)/../common_infra.sh -require_programs faketime - -TEST_SUITE_ID="libx52 timezone tests" - -# Use the America/Los_Angeles timezone -# Standard time is UTC-08:00, Daylight time is UTC-07:00 -export TZ=America/Los_Angeles - -# All timezone tests use DD-MM-YY and 12hr format -timezone_test() -{ - local datetime="$1" - - TEST_ID="Test setting clock to '$(date --date="$datetime")'" - - local dd=$(date --date="$datetime" +%_d) - local mm=$(date --date="$datetime" +%_m) - local yy=$(date --date="$datetime" +%_y) - local hr=$(date --date="$datetime" +%_H) - local mn=$(date --date="$datetime" +%_M) - - local off - if [[ "$(date --date="$datetime" +%Z)" == 'PDT' ]] - then - # Pacific Daylight Time - # Default offset for clocks 2 & 3 should be +420 minutes - off=420 - else - # Pacific Standard time - # Default offset for clocks 2 & 3 should be +480 minutes - off=480 - fi - - local clock_value=$(($hr * 256 + $mn)) - local date_value=$(($mm * 256 + $dd)) - local year_value=$yy - - expect_pattern \ - $X52_CLOCK_DATE_INDEX $(printf '%04x' $date_value) \ - $X52_CLOCK_YEAR_INDEX $(printf '%04x' $year_value) \ - $X52_CLOCK_1_INDEX $(printf '%04x' $clock_value) \ - $X52_CLOCK_2_INDEX $(printf '%04x' $off) \ - $X52_CLOCK_3_INDEX $(printf '%04x' $off) \ - - faketime "$datetime" $X52CLI clock local 12hr ddmmyy - verify_output -} - -# Check timezone test for 14:15:16 on the 13th day of every month from -# January 2017 to December 2019 - -for year in $(seq 2017 2019) -do - for month in $(seq 1 12) - do - timezone_test "$(printf '%d-%02d-13 14:15:16' $year $month)" - done -done - -verify_test_suite diff --git a/tools/hidraw/hid-example.c b/tools/hidraw/hid-example.c deleted file mode 100644 index b01b3ab..0000000 --- a/tools/hidraw/hid-example.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Hidraw Userspace Example - * - * Copyright (c) 2010 Alan Ott - * Copyright (c) 2010 Signal 11 Software - * - * The code may be used by anyone for any purpose, - * and can serve as a starting point for developing - * applications using hidraw. - */ - -/* Linux */ -#include -#include -#include - -/* - * Ugly hack to work around failing compilation on systems that don't - * yet populate new version of hidraw.h to userspace. - * - * If you need this, please have your distro update the kernel headers. - */ -#ifndef HIDIOCSFEATURE -#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len) -#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len) -#endif - -/* Unix */ -#include -#include -#include -#include -#include - -/* C */ -#include -#include -#include -#include - -const char *bus_str(int bus); - -int main(int argc, char **argv) -{ - int fd; - int i, res, desc_size = 0; - char buf[256]; - struct hidraw_report_descriptor rpt_desc; - struct hidraw_devinfo info; - - /* Open the Device with non-blocking reads. In real life, - don't use a hard coded path; use libudev instead. */ - fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK); - - if (fd < 0) { - perror("Unable to open device"); - return 1; - } - - memset(&rpt_desc, 0x0, sizeof(rpt_desc)); - memset(&info, 0x0, sizeof(info)); - memset(buf, 0x0, sizeof(buf)); - - /* Get Report Descriptor Size */ - res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size); - if (res < 0) - perror("HIDIOCGRDESCSIZE"); - else - printf("Report Descriptor Size: %d\n", desc_size); - - /* Get Report Descriptor */ - rpt_desc.size = desc_size; - res = ioctl(fd, HIDIOCGRDESC, &rpt_desc); - if (res < 0) { - perror("HIDIOCGRDESC"); - } else { - printf("Report Descriptor:\n"); - for (i = 0; i < rpt_desc.size; i++) - printf("%hhx ", rpt_desc.value[i]); - puts("\n"); - } - - /* Get Raw Name */ - res = ioctl(fd, HIDIOCGRAWNAME(256), buf); - if (res < 0) - perror("HIDIOCGRAWNAME"); - else - printf("Raw Name: %s\n", buf); - - /* Get Physical Location */ - res = ioctl(fd, HIDIOCGRAWPHYS(256), buf); - if (res < 0) - perror("HIDIOCGRAWPHYS"); - else - printf("Raw Phys: %s\n", buf); - - /* Get Raw Info */ - res = ioctl(fd, HIDIOCGRAWINFO, &info); - if (res < 0) { - perror("HIDIOCGRAWINFO"); - } else { - printf("Raw Info:\n"); - printf("\tbustype: %d (%s)\n", - info.bustype, bus_str(info.bustype)); - printf("\tvendor: 0x%04hx\n", info.vendor); - printf("\tproduct: 0x%04hx\n", info.product); - } - - /* Set Feature */ - buf[0] = 0x9; /* Report Number */ - buf[1] = 0xff; - buf[2] = 0xff; - buf[3] = 0xff; - res = ioctl(fd, HIDIOCSFEATURE(4), buf); - if (res < 0) - perror("HIDIOCSFEATURE"); - else - printf("ioctl HIDIOCGFEATURE returned: %d\n", res); - - /* Get Feature */ - buf[0] = 0x9; /* Report Number */ - res = ioctl(fd, HIDIOCGFEATURE(256), buf); - if (res < 0) { - perror("HIDIOCGFEATURE"); - } else { - printf("ioctl HIDIOCGFEATURE returned: %d\n", res); - printf("Report data (not containing the report number):\n\t"); - for (i = 0; i < res; i++) - printf("%hhx ", buf[i]); - puts("\n"); - } - - /* Send a Report to the Device */ - buf[0] = 0x1; /* Report Number */ - buf[1] = 0x77; - res = 0; //write(fd, buf, 2); - if (res < 0) { - printf("Error: %d\n", errno); - perror("write"); - } else { - printf("write() wrote %d bytes\n", res); - } - - /* Get a report from the device */ - res = read(fd, buf, 16); - if (res < 0) { - perror("read"); - } else { - printf("read() read %d bytes:\n\t", res); - for (i = 0; i < res; i++) - printf("%hhx ", buf[i]); - puts("\n"); - } - close(fd); - return 0; -} - -const char * -bus_str(int bus) -{ - switch (bus) { - case BUS_USB: - return "USB"; - break; - case BUS_HIL: - return "HIL"; - break; - case BUS_BLUETOOTH: - return "Bluetooth"; - break; - case BUS_VIRTUAL: - return "Virtual"; - break; - default: - return "Other"; - break; - } -} diff --git a/tools/hidraw/hidraw.c b/tools/hidraw/hidraw.c deleted file mode 100644 index ac09ff7..0000000 --- a/tools/hidraw/hidraw.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Hidraw Userspace Example - * - * Copyright (c) 2010 Alan Ott - * Copyright (c) 2010 Signal 11 Software - * - * The code may be used by anyone for any purpose, - * and can serve as a starting point for developing - * applications using hidraw. - */ - -/* Linux */ -#include -#include -#include - -/* - * Ugly hack to work around failing compilation on systems that don't - * yet populate new version of hidraw.h to userspace. - * - * If you need this, please have your distro update the kernel headers. - */ -#ifndef HIDIOCSFEATURE -#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len) -#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len) -#endif - -/* Unix */ -#include -#include -#include -#include -#include - -/* C */ -#include -#include -#include -#include - -const char *bus_str(int bus); - -int main(int argc, char **argv) -{ - int fd; - int i, res, desc_size = 0; - unsigned char buf[256]; - struct hidraw_report_descriptor rpt_desc; - struct hidraw_devinfo info; - - if (argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); - return 1; - } - - /* Open the Device with non-blocking reads. In real life, - don't use a hard coded path; use libudev instead. */ - fd = open(argv[1], O_RDONLY); - - if (fd < 0) { - perror("Unable to open device"); - return 1; - } - - memset(&rpt_desc, 0x0, sizeof(rpt_desc)); - memset(&info, 0x0, sizeof(info)); - memset(buf, 0x0, sizeof(buf)); - -retry: - /* Get a report from the device */ - res = read(fd, buf, 16); - if (res < 0) { - perror("read"); - } else { - printf("read() read %d bytes:\n\t", res); - for (i = 0; i < res; i++) - printf("%02x ", buf[i]); - puts("\n"); - } - - goto retry; - close(fd); - return 0; -} - -const char * -bus_str(int bus) -{ - switch (bus) { - case BUS_USB: - return "USB"; - break; - case BUS_HIL: - return "HIL"; - break; - case BUS_BLUETOOTH: - return "Bluetooth"; - break; - case BUS_VIRTUAL: - return "Virtual"; - break; - default: - return "Other"; - break; - } -} diff --git a/tools/readjoy/Makefile b/tools/readjoy/Makefile deleted file mode 100644 index eabbba3..0000000 --- a/tools/readjoy/Makefile +++ /dev/null @@ -1,10 +0,0 @@ - -readjoy: readjoy.c - gcc -o $@ $< - -all: readjoy - -.PHONY: clean -clean: - rm -f readjoy - diff --git a/tools/readjoy/readjoy.c b/tools/readjoy/readjoy.c deleted file mode 100644 index 2540f84..0000000 --- a/tools/readjoy/readjoy.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - struct js_event joy_event; - int fd; - if (argc != 2) { - fprintf(stderr, "Usage: %s /dev/input/jsX\n", argv[0]); - return -1; - } - - fd = open(argv[1], O_RDONLY); - if (!fd) { - fprintf(stderr, "Error: Unable to open %s!\n", argv[1]); - return -2; - } - - for(;;) { - if (read(fd, &joy_event, sizeof(joy_event)) != sizeof(joy_event)) { - fprintf(stderr, "Error: Unable to read from joystick!\n"); - return -3; - } else { - if (joy_event.type & JS_EVENT_INIT) { - printf("*"); - } - - if (joy_event.type & JS_EVENT_BUTTON) { - printf("B"); - } else if (joy_event.type & JS_EVENT_AXIS) { - printf("A"); - } else { - printf("?"); - } - printf("%u: %d\n", joy_event.number, joy_event.value); - } - } - - return 0; -} diff --git a/udev/Makefile.am b/udev/Makefile.am index b2d9258..f2cf713 100644 --- a/udev/Makefile.am +++ b/udev/Makefile.am @@ -4,8 +4,7 @@ # # SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 -# Extra files that need to be in the distribution -EXTRA_DIST = 60-saitek-x52-x52pro.rules +EXTRA_DIST += udev/60-saitek-x52-x52pro.rules if HAVE_UDEV @@ -13,7 +12,7 @@ if HAVE_UDEV # writable by root, and if we're running make distcheck, we're most likely not # running as root. Therefore, disable this if we're running make distcheck if !IS_MAKE_DISTCHECK -udevrules_DATA = 60-saitek-x52-x52pro.rules +udevrules_DATA = udev/60-saitek-x52-x52pro.rules # Update udev only if being installed by root install-data-hook: diff --git a/utils/Makefile.am b/utils/Makefile.am deleted file mode 100644 index 964f28e..0000000 --- a/utils/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -# Top level Automake for utilities -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -SUBDIRS = cli test evtest - diff --git a/utils/cli/Makefile.am b/utils/cli/Makefile.am deleted file mode 100644 index 9a47c61..0000000 --- a/utils/cli/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -# Automake for x52cli -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -ACLOCAL_AMFLAGS = -I m4 - -bin_PROGRAMS = x52cli - -# Command line utility that front ends the core library -x52cli_SOURCES = x52_cli.c -x52cli_CFLAGS = @X52_INCLUDE@ $(WARN_CFLAGS) -x52cli_LDFLAGS = $(WARN_LDFLAGS) -x52cli_LDADD = ../../lib/libx52/libx52.la diff --git a/utils/test/Makefile.am b/utils/test/Makefile.am deleted file mode 100644 index a8c1e9c..0000000 --- a/utils/test/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -# Automake for x52test -# -# Copyright (C) 2012-2018 Nirenjan Krishnan (nirenjan@nirenjan.org) -# -# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 - -ACLOCAL_AMFLAGS = -I m4 - -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@ -I $(top_srcdir) -DLOCALEDIR=\"$(localedir)\" $(WARN_CFLAGS) -x52test_LDFLAGS = $(WARN_LDFLAGS) -x52test_LDADD = ../../lib/libx52/libx52.la - -# Extra files that need to be in the distribution -EXTRA_DIST = x52_test_common.h