[LTP] [PATCH v2] thermal: add new test group

Petr Vorel pvorel@suse.cz
Thu Jan 22 15:27:01 CET 2026


Hi Piotr,
...
> > > +	bool interrupts_found = 0;
> > > +	char line[8192];
> > very nit: IMHO 1024 would be more than enough, but whatever.
> And I wasn't even sure 8192 would be enough. The reason is that, since
> it's a string, every digit is a single array element. With new 2S or 4S
> systems with hundreds of cores and each interrupt being up to 2^64,
> even 8192 might not be enough.

OK.

> > > +
> > > +	memset(interrupt_array, 0, nproc *
> > > sizeof(*interrupt_array));
> > > +	FILE *fp = SAFE_FOPEN("/proc/interrupts", "r");
> > > +
> > > +	while (fgets(line, sizeof(line), fp)) {
> > > +		if (strstr(line, "Thermal event interrupts")) {
> > Can't we use FILE_LINES_SCANF() or SAFE_FILE_LINES_SCANF() to instead
> > of whole
> > while() block to simplify?

> > See example code
> > https://github.com/linux-test-project/ltp/tree/master/lib/newlib_tests/tst_safe_fileops.c
> It's quite unclear to me. SAFE_FILE_LINES_SCANF() seems fine for
> reading a single interrupt number or even multiple, but only when well
> known how many cores we have. Here the number of elements in the array
> is equal to the number of logical cores the system has, in my case
> it's:
>  TRM:       7795       7795       7795       7795       7800       7800
> 7797       7797       7795       7795       7886       7886       7860
> 7860       7863       7863       7795       7795       7795       7795
> 7795       7795       7795       7795   Thermal event interrupts

> I tried:
> SAFE_FILE_LINES_SCANF("/proc/interrupts", " TRM:%sThermal event
> interrupts", line);

> to fit all the numbers in "line" string and then later parse them, but
> only the 1st number is read. Here we need to have all of them.

I'm sorry, I was wrong here. Yes, you right SAFE_FILE_LINES_SCANF() scans whole
file at once. With generic pattern it can cumulate the results (otherwise with
specific enough it finds only single place). Anyway, not suitable for you.

But you could process each line with SAFE_SSCANF(), that would help to avoid
strtok() (simplify code a lot).

Kind regards,
Petr


More information about the ltp mailing list