Re: [PATCH i-g-t] tests/intel/intel_hwmon: Warn on zero-valued numeric attributes
"Purkait, Soham" <[email protected]>
| Newsgroups | org.freedesktop.lists.igt-dev |
|---|---|
| Message-ID | <[email protected]> |
Hi Karthik, On 05-08-2026 19:28, Karthik Poosa wrote: > Add a check for numeric hwmon attribute values and emit a warning when a > valid numeric attribute reports 0. > This acts as a sanity check for valid telemetry data reported via hwmon. > > Exclude *_label attributes from this validation to avoid false warnings on > non-numeric label entries. > > Also include the necessary headers required for numeric parsing helpers. > > Signed-off-by: Karthik Poosa <[email protected]> > Assisted-by: GitHub-Copilot:GPT-5.3-Codex > --- > tests/intel/intel_hwmon.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > > diff --git a/tests/intel/intel_hwmon.c b/tests/intel/intel_hwmon.c > index f185c1ca3..6fe57a334 100644 > --- a/tests/intel/intel_hwmon.c > +++ b/tests/intel/intel_hwmon.c > @@ -4,6 +4,8 @@ > */ > > #include <dirent.h> > +#include <errno.h> > +#include <stdlib.h> > #include <sys/stat.h> > #include "igt.h" > #include "igt_hwmon.h" > @@ -26,6 +28,31 @@ > > IGT_TEST_DESCRIPTION("Tests for intel hwmon"); > > +static bool value_is_numeric_zero(const char *val) > +{ > + char *end; > + long long num; > + > + errno = 0; > + num = strtoll(val, &end, 10); > + if (errno || *val == '\0' || *end != '\0') > + return false; > + > + return num == 0; > +} > + > +static bool is_hmwon_label(const char *name) > +{ > + const char *suffix = "_label"; > + size_t name_len = strlen(name); > + size_t suffix_len = strlen(suffix); > + > + if (name_len < suffix_len) > + return false; > + > + return !strcmp(name + name_len - suffix_len, suffix); > +} > + > static void check_if_temp_valid(int hwm, char *sysfs_name) > { > int32_t cur_temp = 0, limit = 0; > @@ -64,9 +91,11 @@ static void hwmon_read(int hwm) > igt_assert(igt_sysfs_scanf(hwm, de->d_name, "%127s", val) == 1); > igt_debug("'%s': %s\n", de->d_name, val); > > + if (!is_hmwon_label(de->d_name) && value_is_numeric_zero(val)) Typo : is_hmwon_label -> is_hwmon_label ? Thanks, Soham > + igt_warn("hwmon sysfs entry '%s' has zero value\n", de->d_name); > + > if (!strncmp(de->d_name, "temp", 4)) > check_if_temp_valid(hwm, de->d_name); > - > } > closedir(dir); > }