ACK: [PATCH] lib: fwts_firmware: make enums into a defined type
Alex Hung
alex.hung at canonical.com
Thu Sep 7 01:45:27 UTC 2017
On 2017-09-06 02:08 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Rather than passing around firmware enums as integers, make the enums into
> a defined type and use that type.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/include/fwts_firmware.h | 14 +++++++-------
> src/lib/include/fwts_framework.h | 9 ++++++---
> src/lib/src/fwts_firmware.c | 8 ++++----
> src/lib/src/fwts_framework.c | 2 +-
> 4 files changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/src/lib/include/fwts_firmware.h b/src/lib/include/fwts_firmware.h
> index d6608680..e1c12f09 100644
> --- a/src/lib/include/fwts_firmware.h
> +++ b/src/lib/include/fwts_firmware.h
> @@ -21,28 +21,28 @@
>
> #include <stdbool.h>
>
> -enum firmware_type {
> +typedef enum {
> FWTS_FIRMWARE_UNKNOWN = 0,
> FWTS_FIRMWARE_BIOS = 1,
> FWTS_FIRMWARE_UEFI = 2,
> FWTS_FIRMWARE_OPAL = 3,
> FWTS_FIRMWARE_OTHER = 100
> -};
> +} fwts_firmware_type;
>
> -enum firmware_feature {
> +typedef enum {
> FWTS_FW_FEATURE_ACPI = 0x1,
> FWTS_FW_FEATURE_DEVICETREE = 0x2,
> FWTS_FW_FEATURE_IPMI = 0x4,
> FWTS_FW_FEATURE_ALL = FWTS_FW_FEATURE_ACPI |
> FWTS_FW_FEATURE_DEVICETREE |
> FWTS_FW_FEATURE_IPMI
> -};
> +} fwts_firmware_feature;
>
> -int fwts_firmware_detect(void);
> +fwts_firmware_type fwts_firmware_detect(void);
> int fwts_firmware_features(void);
> -const char *fwts_firmware_feature_string(const int features);
> +const char *fwts_firmware_feature_string(const fwts_firmware_feature features);
>
> -static inline bool fwts_firmware_has_features(const int features)
> +static inline bool fwts_firmware_has_features(const fwts_firmware_feature features)
> {
> return (fwts_firmware_features() & features) == features;
> }
> diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h
> index bef903c8..3f15312b 100644
> --- a/src/lib/include/fwts_framework.h
> +++ b/src/lib/include/fwts_framework.h
> @@ -32,6 +32,7 @@ typedef struct fwts_framework fwts_framework;
> #include "fwts_list.h"
> #include "fwts_acpica_mode.h"
> #include "fwts_types.h"
> +#include "fwts_firmware.h"
>
> #define FWTS_FRAMEWORK_MAGIC 0x2af61aec
>
> @@ -143,7 +144,7 @@ struct fwts_framework {
> fwts_log_level failed_level; /* Bit mask of failed levels in test run */
> fwts_log_level filter_level; /* --log-level option filter */
>
> - int firmware_type; /* Type of firmware */
> + fwts_firmware_type firmware_type; /* Type of firmware */
> bool show_progress; /* Show progress while running current test */
>
> fwts_log_type log_type; /* Output log type, default is plain text ASCII */
> @@ -190,14 +191,16 @@ typedef struct fwts_framework_test {
> fwts_framework_ops *ops;
> fwts_priority priority;
> fwts_framework_flags flags;
> - int fw_features;
> + fwts_firmware_feature fw_features;
> fwts_results results; /* Per test results */
> bool was_run;
>
> } fwts_framework_test;
>
> int fwts_framework_args(const int argc, char **argv);
> -void fwts_framework_test_add(const char *name, fwts_framework_ops *ops, const fwts_priority priority, const fwts_framework_flags flags, int fw_features);
> +void fwts_framework_test_add(const char *name, fwts_framework_ops *ops,
> + const fwts_priority priority, const fwts_framework_flags flags,
> + const fwts_firmware_feature fw_features);
> int fwts_framework_compare_test_name(void *, void *);
> void fwts_framework_show_version(FILE *fp, const char *name);
>
> diff --git a/src/lib/src/fwts_firmware.c b/src/lib/src/fwts_firmware.c
> index 5befa616..611ce8f8 100644
> --- a/src/lib/src/fwts_firmware.c
> +++ b/src/lib/src/fwts_firmware.c
> @@ -23,11 +23,11 @@
>
> #include "fwts.h"
>
> -static enum firmware_type firmware_type;
> +static fwts_firmware_type firmware_type;
> static bool firmware_type_valid;
>
> static const struct {
> - enum firmware_feature feature;
> + fwts_firmware_feature feature;
> const char name[16];
> } feature_names[] = {
> { FWTS_FW_FEATURE_ACPI, "ACPI" },
> @@ -39,7 +39,7 @@ static const struct {
> * fwts_memory_map_entry_compare()
> * callback used to sort memory_map entries on start address
> */
> -int fwts_firmware_detect(void)
> +fwts_firmware_type fwts_firmware_detect(void)
> {
> struct stat statbuf;
>
> @@ -86,7 +86,7 @@ int fwts_firmware_features(void)
> return features;
> }
>
> -const char *fwts_firmware_feature_string(const int features)
> +const char *fwts_firmware_feature_string(const fwts_firmware_feature features)
> {
> const int n = FWTS_ARRAY_LEN(feature_names);
> const char sep[] = ", ";
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 02e1cde6..c0d71521 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -171,7 +171,7 @@ void fwts_framework_test_add(
> fwts_framework_ops *ops,
> const fwts_priority priority,
> const fwts_framework_flags flags,
> - int fw_features)
> + const fwts_firmware_feature fw_features)
> {
> fwts_framework_test *new_test;
>
>
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list