Skip to content

Commit ff78c67

Browse files
Merge pull request #393 from Treece-Burgess/05-23-2025-lmsensors-read-test-unrestrict-events-chosen
lmsensors component: Remove restriction on the events chosen to be added to an eventset for `lmsensors_read.c`
2 parents bb01076 + acb6192 commit ff78c67

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/components/lmsensors/tests/lmsensors_read.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "papi.h"
2323
#include "papi_test.h"
2424

25-
/* number of events we want to add to the PAPI EventSet */
25+
/* maximum number of events we want to add to the PAPI EventSet */
2626
#define NUM_EVENTS 3
2727

2828
int main(int argc, char **argv)
@@ -64,29 +64,30 @@ int main(int argc, char **argv)
6464
test_fail(__FILE__, __LINE__, "PAPI_enum_cmp_event", retval);
6565
}
6666

67-
/* enumerate UNITL we find 3 Core and max temp events */
67+
/* enumerate through the available lmsensors events and add a maximum of three */
6868
modifier = PAPI_ENUM_EVENTS;
6969
do {
7070
retval = PAPI_event_code_to_name(EventCode, EventName);
7171
if (retval != PAPI_OK) {
7272
test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval);
7373
}
7474

75-
/* filter for only core and max temp events, max of three events to be added */
76-
if (strstr(EventName, "Core") && strstr(EventName, "max")) {
77-
retval = PAPI_add_named_event(EventSet, EventName);
78-
if (retval != PAPI_OK) {
79-
test_fail(__FILE__, __LINE__, "PAPI_add_named_event", retval);
80-
}
81-
82-
if (!TESTS_QUIET) {
83-
printf("Successfully added %s to the EventSet.\n", EventName);
84-
}
85-
86-
/* store current event name and increment count */
87-
strncpy(lm_events[event_cnt], EventName, PAPI_MAX_STR_LEN);
88-
event_cnt++;
75+
retval = PAPI_add_named_event(EventSet, EventName);
76+
if (retval != PAPI_OK) {
77+
test_fail(__FILE__, __LINE__, "PAPI_add_named_event", retval);
78+
}
79+
80+
if (!TESTS_QUIET) {
81+
printf("Successfully added %s to the EventSet.\n", EventName);
82+
}
83+
84+
/* store current event name and increment count */
85+
int strLen = snprintf(lm_events[event_cnt], PAPI_MAX_STR_LEN, "%s", EventName);
86+
if (strLen < 0 || strLen >= PAPI_MAX_STR_LEN) {
87+
fprintf(stderr, "Failed to fully write event name: %s into array.\n", EventName);
88+
return PAPI_EBUF;
8989
}
90+
event_cnt++;
9091
} while( ( PAPI_enum_cmp_event(&EventCode, modifier, cidx) == PAPI_OK ) && ( event_cnt < NUM_EVENTS ) );
9192

9293
/* start counting */
@@ -107,11 +108,11 @@ int main(int argc, char **argv)
107108
test_fail(__FILE__, __LINE__, "PAPI_stop", retval);
108109
}
109110

110-
/* print out temp values for each event */
111+
/* for each event successfully added print their counter values */
111112
if (!TESTS_QUIET) {
112-
printf("Max temp output for events:\n");
113-
for (i = 0; i < NUM_EVENTS; i++) {
114-
printf("%s: %d\n", lm_events[i], values[i]);
113+
printf("Read counters from the EventSet:\n");
114+
for (i = 0; i < event_cnt; i++) {
115+
printf("Event: %s, Counter Value: %lld\n", lm_events[i], values[i]);
115116
}
116117
}
117118

0 commit comments

Comments
 (0)