lkml.org 
[lkml]   [2022]   [Aug]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.19 0915/1157] selftests/powerpc: Skip energy_scale_info test on older firmware
    Date
    From: Michael Ellerman <mpe@ellerman.id.au>

    [ Upstream commit 4228a996b072d36f3baafb4afdc2d2d66d2cbadf ]

    Older machines don't have the firmware feature that enables the code
    this test is testing. Skip the test if the sysfs directory doesn't
    exist. Also use the FAIL_IF() macro to provide more verbose error
    reporting if an error is encountered.

    Fixes: 57201d657eb7 ("selftest/powerpc: Add PAPR sysfs attributes sniff test")
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20220619233103.2666171-1-mpe@ellerman.id.au
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    .../powerpc/papr_attributes/attr_test.c | 30 +++++++++++--------
    1 file changed, 18 insertions(+), 12 deletions(-)

    diff --git a/tools/testing/selftests/powerpc/papr_attributes/attr_test.c b/tools/testing/selftests/powerpc/papr_attributes/attr_test.c
    index bab0dc06e90b..9b655be641c9 100644
    --- a/tools/testing/selftests/powerpc/papr_attributes/attr_test.c
    +++ b/tools/testing/selftests/powerpc/papr_attributes/attr_test.c
    @@ -7,6 +7,7 @@
    * Copyright 2022, Pratik Rajesh Sampat, IBM Corp.
    */

    +#include <errno.h>
    #include <stdio.h>
    #include <string.h>
    #include <dirent.h>
    @@ -32,7 +33,7 @@ enum type {
    NUM_VAL
    };

    -int value_type(int id)
    +static int value_type(int id)
    {
    int val_type;

    @@ -54,15 +55,21 @@ int value_type(int id)
    return val_type;
    }

    -int verify_energy_info(void)
    +static int verify_energy_info(void)
    {
    const char *path = "/sys/firmware/papr/energy_scale_info";
    struct dirent *entry;
    struct stat s;
    DIR *dirp;

    - if (stat(path, &s) || !S_ISDIR(s.st_mode))
    - return -1;
    + errno = 0;
    + if (stat(path, &s)) {
    + SKIP_IF(errno == ENOENT);
    + FAIL_IF(errno);
    + }
    +
    + FAIL_IF(!S_ISDIR(s.st_mode));
    +
    dirp = opendir(path);

    while ((entry = readdir(dirp)) != NULL) {
    @@ -76,25 +83,24 @@ int verify_energy_info(void)

    id = atoi(entry->d_name);
    attr_type = value_type(id);
    - if (attr_type == INVALID)
    - return -1;
    + FAIL_IF(attr_type == INVALID);

    /* Check if the files exist and have data in them */
    sprintf(file_name, "%s/%d/desc", path, id);
    f = fopen(file_name, "r");
    - if (!f || fgetc(f) == EOF)
    - return -1;
    + FAIL_IF(!f);
    + FAIL_IF(fgetc(f) == EOF);

    sprintf(file_name, "%s/%d/value", path, id);
    f = fopen(file_name, "r");
    - if (!f || fgetc(f) == EOF)
    - return -1;
    + FAIL_IF(!f);
    + FAIL_IF(fgetc(f) == EOF);

    if (attr_type == STR_VAL) {
    sprintf(file_name, "%s/%d/value_desc", path, id);
    f = fopen(file_name, "r");
    - if (!f || fgetc(f) == EOF)
    - return -1;
    + FAIL_IF(!f);
    + FAIL_IF(fgetc(f) == EOF);
    }
    }

    --
    2.35.1


    \
     
     \ /
      Last update: 2022-08-16 02:42    [W:4.068 / U:1.592 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site