diff mbox series

ac_adapter: skip tests when no power supply exists

Message ID 20180816070330.6160-1-alex.hung@canonical.com
State Accepted
Headers show
Series ac_adapter: skip tests when no power supply exists | expand

Commit Message

Alex Hung Aug. 16, 2018, 7:03 a.m. UTC
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/acpi/ac_adapter/ac_adapter.c |  6 ++----
 src/lib/src/fwts_ac_adapter.c    | 12 ++++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Colin Ian King Aug. 16, 2018, 7:06 a.m. UTC | #1
On 16/08/18 08:03, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/ac_adapter/ac_adapter.c |  6 ++----
>  src/lib/src/fwts_ac_adapter.c    | 12 ++++++++++++
>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/src/acpi/ac_adapter/ac_adapter.c b/src/acpi/ac_adapter/ac_adapter.c
> index 1b21b4e..e7d2082 100644
> --- a/src/acpi/ac_adapter/ac_adapter.c
> +++ b/src/acpi/ac_adapter/ac_adapter.c
> @@ -31,10 +31,8 @@ static int ac_adapter_init(fwts_framework *fw)
>  	int not_matching = 0;
> 
>  	if (fwts_ac_adapter_get_state(FWTS_AC_ADAPTER_ANY, &matching, &not_matching) != FWTS_OK) {
> -		fwts_failed(fw, LOG_LEVEL_LOW, "NoACAdapterEntry",
> -			"No %s or %s directory available: cannot test.",
> -			FWTS_SYS_CLASS_POWER_SUPPLY, FWTS_PROC_ACPI_AC_ADAPTER);
> -		return FWTS_ERROR;
> +		fwts_log_error(fw, "Power Supply does not exist, skipping test");
> +		return FWTS_SKIP;
>  	}
>  	return FWTS_OK;
>  }
> diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
> index 42e2025..9dd828f 100644
> --- a/src/lib/src/fwts_ac_adapter.c
> +++ b/src/lib/src/fwts_ac_adapter.c
> @@ -78,6 +78,18 @@ int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)
> 
>  	/* Try to user newer /sys interface first */
>  	if ((ac_power_dir = opendir(FWTS_SYS_CLASS_POWER_SUPPLY))) {
> +		struct dirent *ac_entry;
> +		int count = 0;
> +
> +		while ((ac_entry = readdir(ac_power_dir)) != NULL)
> +			count++;
> +
> +		/* no power supply dir exists */
> +		if (count == 2) {
> +			(void)closedir(ac_power_dir);
> +			return FWTS_ERROR;
> +		}
> +
>  		ac_interface = &fwts_ac_interfaces[SYS_INTERFACE];
>  	/* then try older /proc interface  */
>  	} else if ((ac_power_dir = opendir(FWTS_PROC_ACPI_AC_ADAPTER))) {
> 

Makes sense. Good idea.

Acked-by: Colin Ian King <colin.king@canonical.com>
Ivan Hu Aug. 16, 2018, 9:22 a.m. UTC | #2
On 08/16/2018 03:03 PM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/ac_adapter/ac_adapter.c |  6 ++----
>  src/lib/src/fwts_ac_adapter.c    | 12 ++++++++++++
>  2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/src/acpi/ac_adapter/ac_adapter.c b/src/acpi/ac_adapter/ac_adapter.c
> index 1b21b4e..e7d2082 100644
> --- a/src/acpi/ac_adapter/ac_adapter.c
> +++ b/src/acpi/ac_adapter/ac_adapter.c
> @@ -31,10 +31,8 @@ static int ac_adapter_init(fwts_framework *fw)
>  	int not_matching = 0;
>
>  	if (fwts_ac_adapter_get_state(FWTS_AC_ADAPTER_ANY, &matching, &not_matching) != FWTS_OK) {
> -		fwts_failed(fw, LOG_LEVEL_LOW, "NoACAdapterEntry",
> -			"No %s or %s directory available: cannot test.",
> -			FWTS_SYS_CLASS_POWER_SUPPLY, FWTS_PROC_ACPI_AC_ADAPTER);
> -		return FWTS_ERROR;
> +		fwts_log_error(fw, "Power Supply does not exist, skipping test");
> +		return FWTS_SKIP;
>  	}
>  	return FWTS_OK;
>  }
> diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
> index 42e2025..9dd828f 100644
> --- a/src/lib/src/fwts_ac_adapter.c
> +++ b/src/lib/src/fwts_ac_adapter.c
> @@ -78,6 +78,18 @@ int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)
>
>  	/* Try to user newer /sys interface first */
>  	if ((ac_power_dir = opendir(FWTS_SYS_CLASS_POWER_SUPPLY))) {
> +		struct dirent *ac_entry;
> +		int count = 0;
> +
> +		while ((ac_entry = readdir(ac_power_dir)) != NULL)
> +			count++;
> +
> +		/* no power supply dir exists */
> +		if (count == 2) {
> +			(void)closedir(ac_power_dir);
> +			return FWTS_ERROR;
> +		}
> +
>  		ac_interface = &fwts_ac_interfaces[SYS_INTERFACE];
>  	/* then try older /proc interface  */
>  	} else if ((ac_power_dir = opendir(FWTS_PROC_ACPI_AC_ADAPTER))) {

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/acpi/ac_adapter/ac_adapter.c b/src/acpi/ac_adapter/ac_adapter.c
index 1b21b4e..e7d2082 100644
--- a/src/acpi/ac_adapter/ac_adapter.c
+++ b/src/acpi/ac_adapter/ac_adapter.c
@@ -31,10 +31,8 @@  static int ac_adapter_init(fwts_framework *fw)
 	int not_matching = 0;

 	if (fwts_ac_adapter_get_state(FWTS_AC_ADAPTER_ANY, &matching, &not_matching) != FWTS_OK) {
-		fwts_failed(fw, LOG_LEVEL_LOW, "NoACAdapterEntry",
-			"No %s or %s directory available: cannot test.",
-			FWTS_SYS_CLASS_POWER_SUPPLY, FWTS_PROC_ACPI_AC_ADAPTER);
-		return FWTS_ERROR;
+		fwts_log_error(fw, "Power Supply does not exist, skipping test");
+		return FWTS_SKIP;
 	}
 	return FWTS_OK;
 }
diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
index 42e2025..9dd828f 100644
--- a/src/lib/src/fwts_ac_adapter.c
+++ b/src/lib/src/fwts_ac_adapter.c
@@ -78,6 +78,18 @@  int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)

 	/* Try to user newer /sys interface first */
 	if ((ac_power_dir = opendir(FWTS_SYS_CLASS_POWER_SUPPLY))) {
+		struct dirent *ac_entry;
+		int count = 0;
+
+		while ((ac_entry = readdir(ac_power_dir)) != NULL)
+			count++;
+
+		/* no power supply dir exists */
+		if (count == 2) {
+			(void)closedir(ac_power_dir);
+			return FWTS_ERROR;
+		}
+
 		ac_interface = &fwts_ac_interfaces[SYS_INTERFACE];
 	/* then try older /proc interface  */
 	} else if ((ac_power_dir = opendir(FWTS_PROC_ACPI_AC_ADAPTER))) {