From 8fd16d544a18553b1b292d5a0a7b6c1f839ad9fd Mon Sep 17 00:00:00 2001 From: nirenjan Date: Mon, 11 Oct 2021 07:14:00 -0700 Subject: [PATCH] Add bugreport utility This change adds a utility that generates some output that can be used to figure out what the user system is, specifically, the versions of the following: * libusb * hidapi (if available) * kernel * device info These parameters can be used to determine if the user is running some non-standard environment, and make it easier to track down bugs. --- ChangeLog.md | 4 ++ Makefile.am | 1 + bugreport/Makefile.am | 22 ++++++++++ bugreport/bugreport.c | 98 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 bugreport/Makefile.am create mode 100644 bugreport/bugreport.c diff --git a/ChangeLog.md b/ChangeLog.md index b35082d..0bc22fa 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based upon [Keep a Changelog]. ## [Unreleased] +### Added +- Bug report utility to make it easier to gather system and build information + when reporting issues. + ### Changed - Renamed project from `x52pro-linux` to `libx52` diff --git a/Makefile.am b/Makefile.am index 570f466..532cfca 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,6 +41,7 @@ include evtest/Makefile.am include daemon/Makefile.am include udev/Makefile.am +include bugreport/Makefile.am include docs/Makefile.am ####################################################################### diff --git a/bugreport/Makefile.am b/bugreport/Makefile.am new file mode 100644 index 0000000..41fa965 --- /dev/null +++ b/bugreport/Makefile.am @@ -0,0 +1,22 @@ +# Automake for libx52-bugreport +# +# Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) +# +# SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + +bin_PROGRAMS += x52bugreport + +# Bug report program that reports the build and linked library versions +x52bugreport_SOURCES = bugreport/bugreport.c +x52bugreport_CFLAGS = \ + -I$(top_srcdir)/libx52io \ + @LIBUSB_CFLAGS@ \ + @HIDAPI_CFLAGS@ \ + $(WARN_CFLAGS) + +x52bugreport_LDFLAGS = \ + @LIBUSB_LIBS@ \ + @HIDAPI_LIBS@ \ + $(WARN_LDFLAGS) + +x52bugreport_LDADD = libx52io.la diff --git a/bugreport/bugreport.c b/bugreport/bugreport.c new file mode 100644 index 0000000..d2c72dc --- /dev/null +++ b/bugreport/bugreport.c @@ -0,0 +1,98 @@ +/* + * libx52 bugreport utility + * + * 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 "libusb.h" +#include "hidapi.h" +#include "libx52io.h" + +static void print_sysinfo(void) +{ + struct utsname uts; + + puts(""); + puts("System info:"); + puts("============"); + if (uname(&uts) < 0) { + printf("Unable to get system info: %s\n", strerror(errno)); + } else { + printf("%s %s %s (%s)\n", uts.sysname, uts.release, uts.machine, uts.version); + } +} + +static void print_devinfo(void) +{ + libx52io_context *ctx; + int rc; + + puts(""); + puts("Device info:"); + puts("============"); + #define CHECK_RC() do { \ + if (rc != LIBX52IO_SUCCESS) { \ + puts(libx52io_strerror(rc)); \ + return; \ + } \ + } while (0) + + rc = libx52io_init(&ctx); + CHECK_RC(); + + rc = libx52io_open(ctx); + CHECK_RC(); + + printf("Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n", + libx52io_get_vendor_id(ctx), + libx52io_get_product_id(ctx), + libx52io_get_device_version(ctx)); + printf("Device name: '%s' '%s'\n", + libx52io_get_manufacturer_string(ctx), + libx52io_get_product_string(ctx)); + printf("Serial number: '%s'\n", + libx52io_get_serial_number_string(ctx)); +} + +int main(int argc, char **argv) +{ + const struct libusb_version *libusb; + + puts("libx52 bugreport"); + puts("================"); + printf("Package version: %s\n", VERSION); + printf("Build version: %s\n", BUILD_VERSION); + + puts(""); + puts("Built against:"); + puts("=============="); + + printf("libusb API version: 0x%08x\n", LIBUSB_API_VERSION); +#if defined HID_API_VERSION_STR + printf("hidapi version: %s\n", HID_API_VERSION_STR); +#endif + + libusb = libusb_get_version(); + puts(""); + puts("System versions:"); + puts("================"); + printf("libusb: %d.%d.%d.%d%s (%s)\n", + libusb->major, libusb->minor, libusb->micro, libusb->nano, + libusb->rc, libusb->describe); +#if defined HID_API_VERSION_STR + printf("hidapi: %s\n", hid_version_str()); +#endif + + print_sysinfo(); + print_devinfo(); + + return 0; +}