Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Skip energy_scale_info test on older firmware

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

+18 -12
+18 -12
tools/testing/selftests/powerpc/papr_attributes/attr_test.c
··· 7 7 * Copyright 2022, Pratik Rajesh Sampat, IBM Corp. 8 8 */ 9 9 10 + #include <errno.h> 10 11 #include <stdio.h> 11 12 #include <string.h> 12 13 #include <dirent.h> ··· 33 32 NUM_VAL 34 33 }; 35 34 36 - int value_type(int id) 35 + static int value_type(int id) 37 36 { 38 37 int val_type; 39 38 ··· 55 54 return val_type; 56 55 } 57 56 58 - int verify_energy_info(void) 57 + static int verify_energy_info(void) 59 58 { 60 59 const char *path = "/sys/firmware/papr/energy_scale_info"; 61 60 struct dirent *entry; 62 61 struct stat s; 63 62 DIR *dirp; 64 63 65 - if (stat(path, &s) || !S_ISDIR(s.st_mode)) 66 - return -1; 64 + errno = 0; 65 + if (stat(path, &s)) { 66 + SKIP_IF(errno == ENOENT); 67 + FAIL_IF(errno); 68 + } 69 + 70 + FAIL_IF(!S_ISDIR(s.st_mode)); 71 + 67 72 dirp = opendir(path); 68 73 69 74 while ((entry = readdir(dirp)) != NULL) { ··· 83 76 84 77 id = atoi(entry->d_name); 85 78 attr_type = value_type(id); 86 - if (attr_type == INVALID) 87 - return -1; 79 + FAIL_IF(attr_type == INVALID); 88 80 89 81 /* Check if the files exist and have data in them */ 90 82 sprintf(file_name, "%s/%d/desc", path, id); 91 83 f = fopen(file_name, "r"); 92 - if (!f || fgetc(f) == EOF) 93 - return -1; 84 + FAIL_IF(!f); 85 + FAIL_IF(fgetc(f) == EOF); 94 86 95 87 sprintf(file_name, "%s/%d/value", path, id); 96 88 f = fopen(file_name, "r"); 97 - if (!f || fgetc(f) == EOF) 98 - return -1; 89 + FAIL_IF(!f); 90 + FAIL_IF(fgetc(f) == EOF); 99 91 100 92 if (attr_type == STR_VAL) { 101 93 sprintf(file_name, "%s/%d/value_desc", path, id); 102 94 f = fopen(file_name, "r"); 103 - if (!f || fgetc(f) == EOF) 104 - return -1; 95 + FAIL_IF(!f); 96 + FAIL_IF(fgetc(f) == EOF); 105 97 } 106 98 } 107 99