ACK: [PATCH 1/2] acpi: method: add a function to check number of sub-package elements
ivanhu
ivan.hu at canonical.com
Tue Jan 19 01:51:09 UTC 2021
On 1/13/21 3:28 PM, Alex Hung wrote:
> The function name is fwts_method_subpackage_count_equal
>
> Signed-off-by: Alex Hung <alex.hung at canonical.com>
> ---
> src/acpi/method/method.c | 86 ++++---------------------
> src/lib/include/fwts_acpi_object_eval.h | 1 +
> src/lib/src/fwts_acpi_object_eval.c | 26 ++++++++
> 3 files changed, 39 insertions(+), 74 deletions(-)
>
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 703e564e..07916c7f 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -693,12 +693,7 @@ static void method_test_DLM_return(
> for (i = 0; i < obj->Package.Count; i++) {
> ACPI_OBJECT *pkg = &obj->Package.Elements[i];
>
> - if (pkg->Package.Count != 2) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_DLMSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 2 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_DLM", pkg, i, 2) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -914,12 +909,7 @@ static void method_test_PRT_return(
> pkg = &obj->Package.Elements[i];
>
> /* check size of sub-packages */
> - if (pkg->Package.Count != 4) {
> - fwts_failed(fw, LOG_LEVEL_CRITICAL,
> - "Method_PRTSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to have 4"
> - "elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_PRT", pkg, i, 4) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -1394,14 +1384,8 @@ static void method_test_PRW_return(
> if (obj->Package.Elements[0].Type == ACPI_TYPE_PACKAGE) {
> ACPI_OBJECT *pkg;
> pkg = &obj->Package.Elements[0];
> - if (pkg->Package.Count != 2) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_PRWSubPackageElementCount",
> - "%s sub-package 0 was expected to have 2"
> - "elements, got %" PRIu32 " elements instead.",
> - name, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_PRW", pkg, 0, 2) != FWTS_OK)
> failed = true;
> - }
>
> if (pkg->Package.Elements[0].Type != ACPI_TYPE_LOCAL_REFERENCE) {
> fwts_failed(fw, LOG_LEVEL_MEDIUM,
> @@ -1909,12 +1893,7 @@ static void method_test_CSD_return(
> /*
> * Currently we expect a package of 6 integers.
> */
> - if (pkg->Package.Count != 6) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_CSDSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 5 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_CSD", pkg, i, 6) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -2063,12 +2042,7 @@ static void method_test_CST_return(
>
> pkg = &obj->Package.Elements[i];
>
> - if (pkg->Package.Count != 4) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_CSTElementPackageCountInvalid",
> - "%s package element %" PRIu32 " should have "
> - "4 elements, instead it had %" PRIu32 ".",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_CST", pkg, i, 4) != FWTS_OK) {
> cst_elements_ok[i] = false;
> failed = true;
> continue;
> @@ -2390,12 +2364,7 @@ static void method_test_PSD_return(
> bool elements_ok = true;
>
> pkg = &obj->Package.Elements[i];
> - if (pkg->Package.Count != 5) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_PSDSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 5 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_PSD", pkg, i, 5) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -2541,12 +2510,7 @@ static void method_test_TSD_return(
> /*
> * Currently we expect a package of 5 integers.
> */
> - if (pkg->Package.Count != 5) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_TSDSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 5 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "TSD", pkg, i, 5) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -2666,13 +2630,7 @@ static void method_test_TSS_return(
> /*
> * We expect a package of 5 integers.
> */
> - if (pkg->Package.Count != 5) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_TSSSubPackageElementCount",
> - "%s sub-package %" PRIu32
> - " was expected to have 5 elements, "
> - "got %" PRIu32" elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_TSS", pkg, i, 5) != FWTS_OK) {
> tss_elements_ok[i] = false;
> failed = true;
> continue; /* Skip processing sub-package */
> @@ -3034,12 +2992,7 @@ static void method_test_ALR_return(
> ACPI_OBJECT *pkg;
>
> pkg = &obj->Package.Elements[i];
> - if (pkg->Package.Count != 2) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_ALRBadSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 2 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_ALR", pkg, i, 2) != FWTS_OK) {
> failed = true;
> } else {
> /* elements should be listed in monotonically increasing order */
> @@ -4284,12 +4237,7 @@ static void method_test_FPS_return(
> }
>
> pkg = &obj->Package.Elements[i];
> - if (pkg->Package.Count != 5) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_FPSBadSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 5 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_FPS", pkg, i, 5) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -4493,12 +4441,7 @@ static void method_test_ART_return(
> }
>
> pkg = &obj->Package.Elements[i];
> - if (pkg->Package.Count != 13) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_ARTBadSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 13 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_ART", pkg, i, 13) != FWTS_OK) {
> failed = true;
> continue;
> }
> @@ -4575,12 +4518,7 @@ static void method_test_TRT_return(
> bool elements_ok = true;
>
> pkg = &obj->Package.Elements[i];
> - if (pkg->Package.Count != 8) {
> - fwts_failed(fw, LOG_LEVEL_MEDIUM,
> - "Method_TRTSubPackageElementCount",
> - "%s sub-package %" PRIu32 " was expected to "
> - "have 8 elements, got %" PRIu32 " elements instead.",
> - name, i, pkg->Package.Count);
> + if (fwts_method_subpackage_count_equal(fw, name, "_TRT", pkg, i, 8) != FWTS_OK) {
> failed = true;
> continue;
> }
> diff --git a/src/lib/include/fwts_acpi_object_eval.h b/src/lib/include/fwts_acpi_object_eval.h
> index 97d12fa0..3d611916 100644
> --- a/src/lib/include/fwts_acpi_object_eval.h
> +++ b/src/lib/include/fwts_acpi_object_eval.h
> @@ -118,6 +118,7 @@ bool fwts_method_type_matches(ACPI_OBJECT_TYPE t1, ACPI_OBJECT_TYPE t2);
> int fwts_method_buffer_size(fwts_framework *fw, const char *name, ACPI_OBJECT *obj, size_t buf_size);
> int fwts_method_package_count_min(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const uint32_t min);
> int fwts_method_package_count_equal(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const uint32_t count);
> +int fwts_method_subpackage_count_equal(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const uint32_t sub, const uint32_t count);
> int fwts_method_package_elements_all_type(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const ACPI_OBJECT_TYPE type);
> int fwts_method_package_elements_type(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const fwts_package_element *info, const uint32_t count);
> int fwts_method_test_revision(fwts_framework *fw, const char *name, const uint32_t cur_revision, const uint32_t spec_revision);
> diff --git a/src/lib/src/fwts_acpi_object_eval.c b/src/lib/src/fwts_acpi_object_eval.c
> index afad265d..e822a934 100644
> --- a/src/lib/src/fwts_acpi_object_eval.c
> +++ b/src/lib/src/fwts_acpi_object_eval.c
> @@ -645,6 +645,32 @@ int fwts_method_package_count_equal(
> return FWTS_OK;
> }
>
> +/*
> + * fwts_method_subpackage_count_equal()
> + * check that an ACPI subpackage has exactly 'count' elements
> + */
> +int fwts_method_subpackage_count_equal(
> + fwts_framework *fw,
> + const char *name,
> + const char *objname,
> + const ACPI_OBJECT *obj,
> + const uint32_t sub,
> + const uint32_t count)
> +{
> + if (obj->Package.Count != count) {
> + char tmp[128];
> +
> + snprintf(tmp, sizeof(tmp), "Method%sSubPackageElementCount", objname);
> + fwts_failed(fw, LOG_LEVEL_CRITICAL, tmp,
> + "%s sub-package %" PRIu32 " was expected to have "
> + "%" PRIu32 " element%s, got %" PRIu32 " element%s instead.",
> + name, sub, count, count == 1 ? "" : "s",
> + obj->Package.Count, obj->Package.Count == 1 ? "" : "s");
> + return FWTS_ERROR;
> + }
> + return FWTS_OK;
> +}
> +
> int fwts_method_package_elements_all_type(
> fwts_framework *fw,
> const char *name,
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>
More information about the fwts-devel
mailing list