Commit Graph

131 Commits (report-buttons-in-order)

Author SHA1 Message Date
nirenjan 3981b873e0 Add date format tests 2020-06-28 08:57:23 -07:00
nirenjan 87ad48a37f Cleanup generated test formatting 2020-06-28 08:57:01 -07:00
nirenjan 7b423f4ea0 Update libx52_set_led_state to use check_feature 2020-06-28 08:35:14 -07:00
nirenjan efd984ef63 Parse and add setup_hook and fields
This change allows updates to the dev structure for individual test
cases. This defines the "setup_hook" array, and "fields" map, at both
the test group level and at the individual test case level, with the
ones at the test case level overriding any parent level fields and/or
hooks.

The primary use case for this is to add new test definitions that would
not be setup correctly by the default infrastructure, such as testing
the LED function for the non-Pro X52, or setting up clock tests for
local timezone, etc.
2020-06-28 08:24:49 -07:00
nirenjan 681a8e8aa1 Change libx52 mock tests to use preprocessor overrides
Prior to this change, libx52 tests needed a linker that supported the
--wrap argument. This is not available on OSX, and therefore, we had to
disable the unit tests on non-Linux systems.

Since we needed to rebuild the libx52 library anyway for the test, it is
simpler to just define libusb_control_transfer to point to our mock
function. This allows us to verify libx52 on all supported platforms.
2020-06-27 22:04:56 -07:00
nirenjan c4696f6055 Add clock time tests 2020-06-17 18:52:07 -07:00
nirenjan e9167b4c20 Disable cmocka tests on non-Linux hosts 2020-06-17 16:00:25 -07:00
nirenjan 3afe999fe8 Ensure generated sources are not packaged in distribution 2020-06-17 15:12:01 -07:00
nirenjan 9f37cde784 Add generated tests to verify libx52 functionality
This change adds a suite of tests in JSON format using a Python script
to generate the cmocka based test program. Because we need to wrap some
of libusb functionality, we need to rebuild and relink the libx52
sources with the -Wl,--wrap option.
2020-06-17 15:06:19 -07:00
nirenjan bf9b1bdfbd Remove manual tests in favor of cmocka
Prior to this change, we needed to add a manual override function to
mock the vendor command. Given that cmocka has built-in support for
mocking functions, it's better to use that instead.

This change simply removes the manual override and any tests that rely
on it.
2020-06-16 17:33:15 -07:00
nirenjan c4acd0ce49 Update makefiles to use Python 3
Prior to this change, generation of the character lookup table could use
Python 2 or Python 3, depending on what the first instance of python in
the PATH pointed to.  On most systems, python is a symbolic link to
python2.7. However, given that Python 2 is EOL, it makes sense to switch
the code to use Python 3 now, rather than later.

This change updates the requirements to use Python 3.6 or later, and
updates the Makefile to invoke the script with the detected python
binary, rather than relying on the shebang to use the system Python.
2020-06-16 15:17:53 -07:00
nirenjan 3eaee7b8f4 Reduce duplicate code in libx52 test code 2020-06-14 00:07:40 -07:00
nirenjan e1915bc734 Update paths of scripts to allow building on BSD
Prior to this change, the assumption in all shell and Python scripts was
that the Bash interpreter would always be available at `/bin/bash`, and
Python would always be available at `/usr/bin/python`. However, on a VM
running FreeBSD, installing bash and python using the pkg command
installs them under /usr/local/bin.

This change updates the paths to use /usr/bin/env in the shebang. While
this is not a standard path either, it is more likely to be available at
this location.

This change also updates the find command in common_infra.sh to use
`-perm -+x` in lieu of `-executable`, which is not a condition defined
by POSIX. This allows running the tests on BSD.
2020-06-12 23:26:51 -07:00
nirenjan 16a7801e59 Update offset tests to use common test infrastructure.
Prior to the introduction of common test infrastructure, the offset test
was using an undocumented function in libx52 to validate the timezone
offset calculations.

This change allows us to hide that undocumented function and not have to
expose internal functionality in order to perform testing.
2020-06-12 17:18:04 -07:00
nirenjan 02165a8712 Fix comparision issue in test_common.c
Prior to this change, the comparision loop ran until it found a zero
value in either the index or the value field, rather than looping until
both were zero.

This change fixes that bug, and also adds additional debug functions to
print the expected and observed values.
2020-06-12 17:09:09 -07:00
nirenjan dbacc27164 libusbx52: Clean up compiler warnings 2020-06-11 23:39:28 -07:00
nirenjan 1e2dd5699f libx52util: Clean up compiler warnings 2020-06-11 23:39:28 -07:00
nirenjan 3b8b98e74c libx52: Clean up compiler warnings 2020-06-11 23:39:28 -07:00
nirenjan 37162510ac Enable additional compiler warnings
This change adds additional compiler warnings as detected by the
autoconf archive. Because the code is susceptible to these additional
warnings, disable treating warnings as errors for now, until we can fix
the warnings.
2020-06-11 23:38:44 -07:00
nirenjan fffb0bb69e Add test cases for blink and shift functionality 2020-06-11 22:29:59 -07:00
nirenjan 49d162fa07 Return result from _x52_vendor_command 2020-06-11 16:44:41 -07:00
nirenjan 1efcaf8970 Remove unnecessary pass statement 2020-06-11 16:04:12 -07:00
nirenjan c96ba7fec4 Add test cases for LEDs
This change adds tests for setting the X52Pro LEDs using the new x52
test infrastructure. This should be used in addition to the x52cli based
test suite.
2020-06-11 15:07:27 -07:00
nirenjan 92b0eb584f Allow overriding the vendor command functionality
This change allows for a test framework to override the functionality of
libx52_vendor_command. By doing so, it can build tests that change the
libx52_device structure, and therefore, not need to rely on libusbx52 to
get the commands written.

This allows for tests that can be built and run on other OSes as well,
since the libusbx52 based tests cannot run on OSX and have not been
tested on BSD systems.
2020-06-10 17:04:24 -07:00
nirenjan 2cb3474861 Add test case for offset calculation 2020-06-09 15:29:26 -07:00
nirenjan 4d93df1d58 Break offset calculation out into a separate function
This change will allow for a test program to verify that the offset
computation is valid.
2020-06-09 14:43:59 -07:00
nirenjan c9ffb415c8 Move opening from environment into separate function 2020-06-09 14:31:20 -07:00
nirenjan 23a980e250 Cleanup spurious whitespace 2020-06-08 23:52:27 -07:00
nirenjan 5715b19326 Reduce libx52_update function complexity
With the introduction of automatic code review tools, libx52_update was
found to be "too complex". This change simply breaks out the switch
cases into a set of functions indexed through a lookup table.
2020-06-08 22:59:41 -07:00
nirenjan e70a1b74e9 libx52: create separate group for connection functions 2020-06-08 17:31:32 -07:00
nirenjan 2d46b395a1 Add libx52_is_connected function 2020-06-08 17:22:33 -07:00
nirenjan 0cf977b751 Automatically close open handle when no device detected
Prior to this change, libx52_vendor_command would leave the device
handle untouched, even if the joystick was disconnected.

This change will force applications to reconnect to the joystick after
they encounter such a failure.
2020-06-08 16:23:11 -07:00
nirenjan 88d57958f9 Remove daylight savings offset bug from documentation 2020-06-07 02:26:32 -07:00
nirenjan 85d2fc3522 Update libx52 version to reflect fix 2020-06-06 18:34:32 -07:00
nirenjan af49ce6500 Fix daylight savings offset calculation bug
This commit changes the local timezone calculation to use tm.tm_gmtoff,
and falling back to calculating it manually from the output of strftime
when tm_gmtoff is not a member of struct tm.

This also fixes the tests so that they are no longer expected to fail.

Fixes #20.
2020-06-06 17:48:17 -07:00
nirenjan f5145de36b Force _GNU_SOURCE in libusbx52 2020-06-06 17:26:43 -07:00
nirenjan 4f22983739 Revert "Enable compiling libx52 with weak symbol binding"
The hope was that I could compile some tests that would override
libx52_vendor_command, and run those on OSX to bypass the skipped tests
that used x52cli. However, a Travis-CI run indicated that the compiler
on OSX doesn't support weak symbols, which renders the point moot.
2020-06-06 17:05:17 -07:00
nirenjan 780d9b4da4 Reduce variable scope as suggested by code inspector 2020-06-06 16:35:24 -07:00
nirenjan 95bc71859b Enable compiling libx52 with weak symbol binding
This change allows exporting libx52_vendor_command as a weak symbol,
thereby allowing it to be overridden by a test runner to validate that
the library is indeed behaving as per the spec.

Because this is something that may not be necessarily desirable on a
production environment, add a configure time flag to disable building
with weak symbols. This will also disable any tests that may rely on
libx52_vendor_command being a weak function.
2020-06-06 16:24:31 -07:00
nirenjan bac20b410d Hide libx52 internal symbols
Prior to this change, all symbols were being exported in the generated
library. This change adds libtool directives to only export the public
symbols in libx52.
2020-06-06 07:41:13 -07:00
nirenjan 88f02bc5da Add _GNU_SOURCE to all files
If configured with CFLAGS=-std=c99, then quite a few warnings are
raised, as well as a couple of errors. By forcing the system to use
_GNU_SOURCE, we can allow the compilation to succeed even if using a
user defined C standard.
2020-06-05 16:37:20 -07:00
nirenjan 543aec85b1 Add config header to all C files 2020-06-05 15:19:56 -07:00
nirenjan 011bb737af Update libusbx52 to address code-inspector violations
This change addresses the code inspector violations reported in
https://frontend.code-inspector.com/analysis/result/8899/550515
2020-06-04 17:03:02 -07:00
nirenjan b6ebdef7ef Handle time out of range in libx52_set_clock
Prior to this change, the assumption was that localtime/gmtime would
never fail, regardless of the time value provided to it. However,
testing on an Ubuntu 20.04 machine revealed that the representable
range of time_t was about 56 bits, values that exceed a 56 bit
representation would cause localtime/gmtime to return a NULL pointer.

This change replaces the use of localtime/gmtime with their
corresponding thread-safe variants, and checks the return value against
NULL. If it matches a NULL value, then it will return an error and not
update the clocks.
2020-06-04 15:34:03 -07:00
nirenjan 7ae5cad0cc Clear warning when linking x52test_log_actions
Prior to this change, we were linking the log_actions program against
the stub library, since we needed to use the logging capabilities in the
stub library to save the expected values to a file for the test harness
to use. However, doing so gives us the following warning:

*** Warning: Linking the executable x52test_log_actions against the loadable module
*** libusbx52.so is not portable!

Since we don't really need to have dynamic linking in this case, simply
including the stub library source into the log_actions program sources
list is sufficient, and bypasses this warning.
2020-06-02 07:50:51 -07:00
nirenjan a43cbc83a5 Add libx52_set_clock bug (#20) to documentation 2020-06-01 17:45:33 -07:00
nirenjan 127ab10995 Update Doxygen documentation
This change cleans up the documentation and adds examples for some
functions.
2020-05-31 08:45:34 -07:00
nirenjan a711f0a882 Remove consolidated API documentation page
This change ensures that there is a separate link to all libx52.h
documentation. As a result, there is no longer a need to manually
maintain a list of functions, structs, enums, etc. This also updates
the main page to link directly to the documented files, rather than
to the API page.
2020-05-28 16:27:44 -07:00
nirenjan d9ae8d4b79 Add connect/disconnect methods to libx52
Prior to this change, libx52_init needed a supported joystick to be
plugged in, otherwise it would fail with LIBX52_ERROR_NO_DEVICE. This
change modifies the behavior so that libx52_init would still succeed,
but the application should call libx52_connect to make sure that the
device handle is valid. libx52_init still tries to connect to the
joystick, but absence is no longer treated as a failure.

This change also modifies x52cli to check that the joystick is actually
connected before calling the individual handlers. Because libx52_init no
longer fails if the joystick is absent, we need to rely on the return
code from libx52_connect.
2020-05-23 02:18:40 -07:00
nirenjan dfdf6468bc Update Doxygen documentation
This updates the Doxygen documentation so that the generated
documentation is more readable and accessible to users of libx52
2020-05-22 18:05:07 -07:00
nirenjan fd6afde59c Update libx52 soname to 2.2.0 2020-05-22 16:02:59 -07:00
nirenjan 482943e7a3 Add feature check method to libx52
This change allows applications to query if the connected device
supports the requested feature. This is so that applications like
x52test can skip test routines that aren't supported, instead of bailing
out of the loop.
2020-05-22 10:39:47 -07:00
nirenjan 0b6bc8f074 Clear the structure memory on exiting libx52 2020-05-22 10:33:33 -07:00
nirenjan cc8d6e9344 Revert hotplug support in libx52
This removes the earlier work done in libx52 to support USB hotplug.
This wasn't adequately tested, and the reason to have hotplug support
was to address perceived deficiencies in the standard API.

However, on recent reflection and experimentation, it seems to be easier
to support adding methods to connect to an X52/X52Pro joystick
dynamically after initializing the library. This approach also lends
itself to adding checks when sending control packets to close the device
handle when it detects device disconnection. Also, one could add a
disconnect method to disconnect from any connected joysticks.

Finally, this commit reverts a series of commits that chronicled my
journey into implementing hotplug support and simulating it in
libusbx52. By coalescing the revert into a single commit, it makes it
easier to revert the revert in the future, if necessary.
2020-05-22 00:42:01 -07:00
nirenjan ec9443dcdd Add gettext support to libx52
This change adds gettext support to libx52 using the Autotools
framework. This should allow translators to translate the error messages
provided by libx52_strerror into their corresponding localized versions.
2020-05-19 08:07:10 -07:00
nirenjan 74b828a790 Update Doxygen comments
This disables the include file list and dependency graph in the file
view. In addition, the groups are updated to include `libx52` in their
names, to avoid any potential conflict.

[skip ci]
2020-04-18 02:21:12 -07:00
nirenjan 34dc1b8a32 Declare hotplug functions in libx52.h
This change exposes the libx52_hotplug_* functions in libx52.h to allow
other programs to link against them.

This commit also adds Doxygen comments, and groups the declarations by
their function, for later use in Doxygen integration.
2020-04-18 01:30:53 -07:00
nirenjan cb050f2c30 Allow NULL cb_handle in libx52_hotplug_register_callback
This allows the caller to register a callback and forget about it. This
is useful in cases where a particular callback needs to be run
everytime, and there is no point in deregistering it until the
application terminates, at which point `libx52_hotplug_exit` will take
care of the cleanup.
2020-04-18 01:28:12 -07:00
nirenjan 79b1f930b8 Change return type of libx52_hotplug_exit
There is really no need for a return code, if the service pointer is
NULL, or any of the parameters are NULL, then simply return.
2020-04-18 01:23:41 -07:00
nirenjan 116f7b3a57 Install libx52.pc during make install 2020-04-17 00:04:09 -07:00
nirenjan 848d70fcf2 Generate pkg-config file for libx52 2020-04-16 22:10:48 -07:00
nirenjan e49261c8d6 Move pthread build logic to configure.ac
Prior to this change, the libusbx52 Makefile was manually specifying the
pthread flags to indicate that the linker needed to link against the
pthread libraries.

This change moves the pthread detection logic out to configure.ac, and
updates the flags in libusbx52 Makefile to use the pthread compiler.
2020-04-15 17:31:46 -07:00
nirenjan aa259bf343 Add hotplug support to libusbx52 2020-04-14 18:36:44 -07:00
nirenjan 946916f456 Add hotplug support to libx52
Prior to this change, libx52 would require that the X52/Pro be plugged
in before initialization. This change allows the application to
initialize libx52 even before the device is plugged in.
2020-04-14 18:36:44 -07:00
nirenjan a7caba19df Set debug output to be line buffered
The stub libusb library used for testing writes the control request to a
dump file. By default, this file is block-buffered, and on a typical
Linux system, it waits until it receives about a page worth of data
before flushing it to disk. This results in a delay in monitoring
packets when running a debug program.

This change makes the file line-buffered instead, which results in the
debug output for every single packet getting flushed to disk without
having to wait for a full page of data.
2020-04-12 16:29:22 -07:00
nirenjan 40c14fed24 Update calls to libusb_set_debug
With the release of libusb 1.0.22, `libusb_set_debug` has been
deprecated and replaced by `libusb_set_option`. This function is a new
generic API to add additional functionality in the future without having
to introduce new functions.

This change checks for `LIBUSB_API_VERSION` of at least `0x01000106`,
which is the version corresponding to 1.0.22, and if it matches, it
replaces the calls to `libusb_set_debug` with equivalent calls to
`libusb_set_option`.
2019-02-01 21:31:57 -08:00
nirenjan 9e581bf051 Let libx52_init also translate libusb error codes 2018-07-17 16:00:19 -07:00
nirenjan 7dcd3049ec Add SPDX license identifiers in all files 2018-04-18 12:19:29 -07:00
nirenjan 0913212ecc Always return translated error code
LIBUSB_SUCCESS is also handled by libx52_translate_libusb_error.
2017-10-27 14:20:19 -07:00
nirenjan 02c24cc964 Fix timezone offset calculations for large negative offsets 2017-10-27 14:19:38 -07:00
nirenjan 86642e5b16 Use pkg-config for libusb 2017-09-10 17:13:38 -07:00
nirenjan 3845c81229 Add libx52_strerror API 2017-08-28 22:54:46 -07:00
nirenjan 6f3f8d7c46 Add more error codes and translation from libusb
These new error codes correspond to similar ones returned by libusb, but
abstract away the usage of libusb underneath libx52. This lets the
application rely solely on libx52 error codes to perform error handling.
2017-08-28 19:10:41 -07:00
nirenjan d4afbd6de2 Build libusbx52 only for tests 2017-08-25 06:39:04 -07:00
nirenjan e5ea621899 Fix libtool version info for libx52
Also update package version to indicate it is in pre-release stage.
2017-08-25 06:04:36 -07:00
nirenjan f3270def9d API change for libx52
- libx52_init returns the libx52_device in an output parameter and
  returns a libx52_error_code
- Make all functions return libx52_error_code
- Update package version to indicate incompatible API change
2017-08-23 19:30:35 -07:00
nirenjan 52abd335ab Add raw time and date APIs to libx52
The raw time and date APIs bypass the timezone calculation and update
the internal data structures with the requested time in hh:mm and date
in dd/mm/yy formats.

This is unlikely to be used often, but it is useful during testing.
2017-08-18 07:23:49 -07:00
nirenjan 6b89a9d7f9 Clarify Doxygen comments for libx52 2017-08-16 23:38:19 -07:00
nirenjan 780447122c Reduce number of included headers for libx52util.h 2017-08-16 00:04:10 -07:00
nirenjan f6bf25d66f Add environment file to enable parallel tests 2017-08-01 21:45:02 -07:00
nirenjan f0a0a7dcaf Reorganize source layout 2017-07-27 17:56:51 -07:00