Message ID | 1506990215-9584-1-git-send-email-alex.hung@canonical.com |
---|---|
State | Accepted |
Headers | show |
Series | acpi: devices: add a new test for smart battery device | expand |
On 03/10/17 01:23, Alex Hung wrote: > Signed-off-by: Alex Hung <alex.hung@canonical.com> > --- > src/Makefile.am | 1 + > src/acpi/devices/battery/smart_battery.c | 145 +++++++++++++++++++++++++++++++ > 2 files changed, 146 insertions(+) > create mode 100644 src/acpi/devices/battery/smart_battery.c > > diff --git a/src/Makefile.am b/src/Makefile.am > index c1dccf6..cda0a49 100644 > --- a/src/Makefile.am > +++ b/src/Makefile.am > @@ -47,6 +47,7 @@ fwts_SOURCES = main.c \ > acpi/ac_adapter/ac_adapter.c \ > acpi/devices/ac_adapter/ac.c \ > acpi/devices/battery/battery.c \ > + acpi/devices/battery/smart_battery.c \ > acpi/acpidump/acpidump.c \ > acpi/acpiinfo/acpiinfo.c \ > acpi/acpitables/acpitables.c \ > diff --git a/src/acpi/devices/battery/smart_battery.c b/src/acpi/devices/battery/smart_battery.c > new file mode 100644 > index 0000000..81ecd52 > --- /dev/null > +++ b/src/acpi/devices/battery/smart_battery.c > @@ -0,0 +1,145 @@ > +/* > + * Copyright (C) 2017 Canonical > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version 2 > + * of the License, or (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. > + * > + */ > +#include "fwts.h" > + > +#if defined(FWTS_HAS_ACPI) > + > +#include "fwts_acpi_object_eval.h" > +#include <stdlib.h> > +#include <stdio.h> > +#include <unistd.h> > +#include <inttypes.h> > +#include <string.h> > + > +#define FWTS_SMART_BATTERY_HID "ACPI0002" > + > +static ACPI_HANDLE device; > + > +static ACPI_STATUS get_device_handle(ACPI_HANDLE handle, uint32_t level, > + void *context, void **ret_val) > +{ > + FWTS_UNUSED(level); > + FWTS_UNUSED(context); > + FWTS_UNUSED(ret_val); > + > + device = handle; > + return AE_CTRL_TERMINATE; > +} > + > +static int smart_battery_init(fwts_framework *fw) > +{ > + ACPI_STATUS status; > + > + if (fwts_acpica_init(fw) != FWTS_OK) > + return FWTS_ERROR; > + > + status = AcpiGetDevices(FWTS_SMART_BATTERY_HID, get_device_handle, NULL, NULL); > + if (ACPI_FAILURE(status)) { > + fwts_log_error(fw, "Cannot find the ACPI device"); > + return FWTS_ERROR; > + } > + > + if (!device) { > + fwts_log_error(fw, "Smart Battery device does not exist, skipping test"); > + return FWTS_SKIP; > + } else { > + ACPI_BUFFER buffer; > + char full_name[128]; > + > + buffer.Length = sizeof(full_name); > + buffer.Pointer = full_name; > + > + status = AcpiGetName(device, ACPI_FULL_PATHNAME, &buffer); > + if (ACPI_SUCCESS(status)) { > + fwts_log_info_verbatim(fw, "Smart Battery Device: %s", full_name); > + fwts_log_nl(fw); > + } > + } > + > + return FWTS_OK; > +} > + > +static void method_test_SBS_return( > + fwts_framework *fw, > + char *name, > + ACPI_BUFFER *buf, > + ACPI_OBJECT *obj, > + void *private) > +{ > + static const char *sbs_info[] = { > + "Maximum 1 Smart Battery, system manager/selector not present", > + "Maximum 1 Smart Battery, system manager/selector present", > + "Maximum 2 Smart Batteries, system manager/selector present", > + "Maximum 3 Smart Batteries, system manager/selector present", > + "Maximum 4 Smart Batteries, system manager/selector present" > + }; > + > + FWTS_UNUSED(private); > + > + if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_INTEGER) != FWTS_OK) > + return; > + > + switch (obj->Integer.Value) { > + case 0 ... 4: > + fwts_passed(fw, "%s correctly returned value %" PRIu64 " %s", > + name, (uint64_t)obj->Integer.Value, > + sbs_info[obj->Integer.Value]); > + break; > + default: > + fwts_failed(fw, LOG_LEVEL_MEDIUM, "Method_SBSReturn", > + "%s returned %" PRIu64 ", should be between 0 and 4.", > + name, (uint64_t)obj->Integer.Value); > + fwts_advice(fw, > + "Smart Battery %s is incorrectly informing " > + "the OS about the smart battery " > + "configuration. This is a bug and needs to be " > + "fixed.", name); > + break; > + } > +} > + > +static int method_test_SBS(fwts_framework *fw) > +{ > + return fwts_evaluate_method(fw, METHOD_MANDATORY, &device, > + "_SBS", NULL, 0, method_test_SBS_return, NULL); > +} > + > +static fwts_framework_minor_test smart_battery_tests[] = { > + { method_test_SBS, "Test _SBS (Smart Battery Subsystem)." }, > + { NULL, NULL } > +}; > + > +static int smart_battery_deinit(fwts_framework *fw) > +{ > + FWTS_UNUSED(fw); > + fwts_acpica_deinit(); > + > + return FWTS_OK; > +} > + > +static fwts_framework_ops smart_battery_ops = { > + .description = "ACPI smart battery device test", > + .init = smart_battery_init, > + .deinit = smart_battery_deinit, > + .minor_tests = smart_battery_tests > +}; > + > +FWTS_REGISTER("smart_battery", &smart_battery_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI) > + > +#endif > Acked-by: Colin Ian King <colin.king@canonical.com>
On 10/03/2017 08:23 AM, Alex Hung wrote: > Signed-off-by: Alex Hung <alex.hung@canonical.com> > --- > src/Makefile.am | 1 + > src/acpi/devices/battery/smart_battery.c | 145 +++++++++++++++++++++++++++++++ > 2 files changed, 146 insertions(+) > create mode 100644 src/acpi/devices/battery/smart_battery.c > > diff --git a/src/Makefile.am b/src/Makefile.am > index c1dccf6..cda0a49 100644 > --- a/src/Makefile.am > +++ b/src/Makefile.am > @@ -47,6 +47,7 @@ fwts_SOURCES = main.c \ > acpi/ac_adapter/ac_adapter.c \ > acpi/devices/ac_adapter/ac.c \ > acpi/devices/battery/battery.c \ > + acpi/devices/battery/smart_battery.c \ > acpi/acpidump/acpidump.c \ > acpi/acpiinfo/acpiinfo.c \ > acpi/acpitables/acpitables.c \ > diff --git a/src/acpi/devices/battery/smart_battery.c b/src/acpi/devices/battery/smart_battery.c > new file mode 100644 > index 0000000..81ecd52 > --- /dev/null > +++ b/src/acpi/devices/battery/smart_battery.c > @@ -0,0 +1,145 @@ > +/* > + * Copyright (C) 2017 Canonical > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation; either version 2 > + * of the License, or (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. > + * > + */ > +#include "fwts.h" > + > +#if defined(FWTS_HAS_ACPI) > + > +#include "fwts_acpi_object_eval.h" > +#include <stdlib.h> > +#include <stdio.h> > +#include <unistd.h> > +#include <inttypes.h> > +#include <string.h> > + > +#define FWTS_SMART_BATTERY_HID "ACPI0002" > + > +static ACPI_HANDLE device; > + > +static ACPI_STATUS get_device_handle(ACPI_HANDLE handle, uint32_t level, > + void *context, void **ret_val) > +{ > + FWTS_UNUSED(level); > + FWTS_UNUSED(context); > + FWTS_UNUSED(ret_val); > + > + device = handle; > + return AE_CTRL_TERMINATE; > +} > + > +static int smart_battery_init(fwts_framework *fw) > +{ > + ACPI_STATUS status; > + > + if (fwts_acpica_init(fw) != FWTS_OK) > + return FWTS_ERROR; > + > + status = AcpiGetDevices(FWTS_SMART_BATTERY_HID, get_device_handle, NULL, NULL); > + if (ACPI_FAILURE(status)) { > + fwts_log_error(fw, "Cannot find the ACPI device"); > + return FWTS_ERROR; > + } > + > + if (!device) { > + fwts_log_error(fw, "Smart Battery device does not exist, skipping test"); > + return FWTS_SKIP; > + } else { > + ACPI_BUFFER buffer; > + char full_name[128]; > + > + buffer.Length = sizeof(full_name); > + buffer.Pointer = full_name; > + > + status = AcpiGetName(device, ACPI_FULL_PATHNAME, &buffer); > + if (ACPI_SUCCESS(status)) { > + fwts_log_info_verbatim(fw, "Smart Battery Device: %s", full_name); > + fwts_log_nl(fw); > + } > + } > + > + return FWTS_OK; > +} > + > +static void method_test_SBS_return( > + fwts_framework *fw, > + char *name, > + ACPI_BUFFER *buf, > + ACPI_OBJECT *obj, > + void *private) > +{ > + static const char *sbs_info[] = { > + "Maximum 1 Smart Battery, system manager/selector not present", > + "Maximum 1 Smart Battery, system manager/selector present", > + "Maximum 2 Smart Batteries, system manager/selector present", > + "Maximum 3 Smart Batteries, system manager/selector present", > + "Maximum 4 Smart Batteries, system manager/selector present" > + }; > + > + FWTS_UNUSED(private); > + > + if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_INTEGER) != FWTS_OK) > + return; > + > + switch (obj->Integer.Value) { > + case 0 ... 4: > + fwts_passed(fw, "%s correctly returned value %" PRIu64 " %s", > + name, (uint64_t)obj->Integer.Value, > + sbs_info[obj->Integer.Value]); > + break; > + default: > + fwts_failed(fw, LOG_LEVEL_MEDIUM, "Method_SBSReturn", > + "%s returned %" PRIu64 ", should be between 0 and 4.", > + name, (uint64_t)obj->Integer.Value); > + fwts_advice(fw, > + "Smart Battery %s is incorrectly informing " > + "the OS about the smart battery " > + "configuration. This is a bug and needs to be " > + "fixed.", name); > + break; > + } > +} > + > +static int method_test_SBS(fwts_framework *fw) > +{ > + return fwts_evaluate_method(fw, METHOD_MANDATORY, &device, > + "_SBS", NULL, 0, method_test_SBS_return, NULL); > +} > + > +static fwts_framework_minor_test smart_battery_tests[] = { > + { method_test_SBS, "Test _SBS (Smart Battery Subsystem)." }, > + { NULL, NULL } > +}; > + > +static int smart_battery_deinit(fwts_framework *fw) > +{ > + FWTS_UNUSED(fw); > + fwts_acpica_deinit(); > + > + return FWTS_OK; > +} > + > +static fwts_framework_ops smart_battery_ops = { > + .description = "ACPI smart battery device test", > + .init = smart_battery_init, > + .deinit = smart_battery_deinit, > + .minor_tests = smart_battery_tests > +}; > + > +FWTS_REGISTER("smart_battery", &smart_battery_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI) > + > +#endif > Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff --git a/src/Makefile.am b/src/Makefile.am index c1dccf6..cda0a49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ fwts_SOURCES = main.c \ acpi/ac_adapter/ac_adapter.c \ acpi/devices/ac_adapter/ac.c \ acpi/devices/battery/battery.c \ + acpi/devices/battery/smart_battery.c \ acpi/acpidump/acpidump.c \ acpi/acpiinfo/acpiinfo.c \ acpi/acpitables/acpitables.c \ diff --git a/src/acpi/devices/battery/smart_battery.c b/src/acpi/devices/battery/smart_battery.c new file mode 100644 index 0000000..81ecd52 --- /dev/null +++ b/src/acpi/devices/battery/smart_battery.c @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2017 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "fwts.h" + +#if defined(FWTS_HAS_ACPI) + +#include "fwts_acpi_object_eval.h" +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <inttypes.h> +#include <string.h> + +#define FWTS_SMART_BATTERY_HID "ACPI0002" + +static ACPI_HANDLE device; + +static ACPI_STATUS get_device_handle(ACPI_HANDLE handle, uint32_t level, + void *context, void **ret_val) +{ + FWTS_UNUSED(level); + FWTS_UNUSED(context); + FWTS_UNUSED(ret_val); + + device = handle; + return AE_CTRL_TERMINATE; +} + +static int smart_battery_init(fwts_framework *fw) +{ + ACPI_STATUS status; + + if (fwts_acpica_init(fw) != FWTS_OK) + return FWTS_ERROR; + + status = AcpiGetDevices(FWTS_SMART_BATTERY_HID, get_device_handle, NULL, NULL); + if (ACPI_FAILURE(status)) { + fwts_log_error(fw, "Cannot find the ACPI device"); + return FWTS_ERROR; + } + + if (!device) { + fwts_log_error(fw, "Smart Battery device does not exist, skipping test"); + return FWTS_SKIP; + } else { + ACPI_BUFFER buffer; + char full_name[128]; + + buffer.Length = sizeof(full_name); + buffer.Pointer = full_name; + + status = AcpiGetName(device, ACPI_FULL_PATHNAME, &buffer); + if (ACPI_SUCCESS(status)) { + fwts_log_info_verbatim(fw, "Smart Battery Device: %s", full_name); + fwts_log_nl(fw); + } + } + + return FWTS_OK; +} + +static void method_test_SBS_return( + fwts_framework *fw, + char *name, + ACPI_BUFFER *buf, + ACPI_OBJECT *obj, + void *private) +{ + static const char *sbs_info[] = { + "Maximum 1 Smart Battery, system manager/selector not present", + "Maximum 1 Smart Battery, system manager/selector present", + "Maximum 2 Smart Batteries, system manager/selector present", + "Maximum 3 Smart Batteries, system manager/selector present", + "Maximum 4 Smart Batteries, system manager/selector present" + }; + + FWTS_UNUSED(private); + + if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_INTEGER) != FWTS_OK) + return; + + switch (obj->Integer.Value) { + case 0 ... 4: + fwts_passed(fw, "%s correctly returned value %" PRIu64 " %s", + name, (uint64_t)obj->Integer.Value, + sbs_info[obj->Integer.Value]); + break; + default: + fwts_failed(fw, LOG_LEVEL_MEDIUM, "Method_SBSReturn", + "%s returned %" PRIu64 ", should be between 0 and 4.", + name, (uint64_t)obj->Integer.Value); + fwts_advice(fw, + "Smart Battery %s is incorrectly informing " + "the OS about the smart battery " + "configuration. This is a bug and needs to be " + "fixed.", name); + break; + } +} + +static int method_test_SBS(fwts_framework *fw) +{ + return fwts_evaluate_method(fw, METHOD_MANDATORY, &device, + "_SBS", NULL, 0, method_test_SBS_return, NULL); +} + +static fwts_framework_minor_test smart_battery_tests[] = { + { method_test_SBS, "Test _SBS (Smart Battery Subsystem)." }, + { NULL, NULL } +}; + +static int smart_battery_deinit(fwts_framework *fw) +{ + FWTS_UNUSED(fw); + fwts_acpica_deinit(); + + return FWTS_OK; +} + +static fwts_framework_ops smart_battery_ops = { + .description = "ACPI smart battery device test", + .init = smart_battery_init, + .deinit = smart_battery_deinit, + .minor_tests = smart_battery_tests +}; + +FWTS_REGISTER("smart_battery", &smart_battery_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI) + +#endif
Signed-off-by: Alex Hung <alex.hung@canonical.com> --- src/Makefile.am | 1 + src/acpi/devices/battery/smart_battery.c | 145 +++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 src/acpi/devices/battery/smart_battery.c