[LTP] [PATCH v1 1/1] libs: libltpnuma: Fix one fake failure when CXL(Compute eXpress Link) node memory is not used

Pengfei Xu pengfei.xu@intel.com
Tue May 9 16:05:21 CEST 2023


Hi Cyril,

On 2023-05-09 at 13:59:01 +0200, Cyril Hrubis wrote:
> Hi!
> >  
> > -	if (!mem_total || !mem_used) {
> > -		tst_res(TWARN, "Failed to parse '%s'", path);
> > +	tst_res(TINFO,"Node%i: mem_total:%ld kB, mem_used:%ld kB", node,
> > +	        mem_total, mem_used);
> > +
> > +	if (!mem_total) {
> > +		tst_res(TWARN, "Failed to parse '%s', MemTotal is 0", path);
> >  		return 0;
> 
> Why don't we use the return value from the sscanf instead?
> 
> What about:
  I tried as follow:
# ./get_mempolicy01
tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s
tst_numa.c:208: TINFO: Found 3 NUMA memory nodes
tst_numa.c:162: TWARN: Faield to parse '/sys/devices/system/node/node0/meminfo' MemUsed:65220292
tst_numa.c:162: TWARN: Faield to parse '/sys/devices/system/node/node1/meminfo' MemUsed:65167784
tst_numa.c:162: TWARN: Faield to parse '/sys/devices/system/node/node2/meminfo' MemUsed:4194304
get_mempolicy01.c:149: TCONF: test requires at least one NUMA memory node
Node 0 and 1 could not be tested with follow patch installed, seems when
node2/meminfo "MemUsed: 0",sscanf("...%li", &val) will return 0 if only 0 value
will be scaned, and the while loop will scan the char one by one and impact all
other node meminfo scan result, it's strange.

If used my patch, I didn't meet this issue.

Thanks!
BR.

> 
> diff --git a/libs/libltpnuma/tst_numa.c b/libs/libltpnuma/tst_numa.c
> index ef4c8e879..7e7504cac 100644
> --- a/libs/libltpnuma/tst_numa.c
> +++ b/libs/libltpnuma/tst_numa.c
> @@ -149,11 +149,19 @@ static int node_has_enough_memory(int node, size_t min_kb)
>         while (fgets(buf, sizeof(buf), fp)) {
>                 long val;
> 
> -               if (sscanf(buf, "%*s %*i MemTotal: %li", &val) == 1)
> +               if (sscanf(buf, "%*s %*i MemTotal: %li", &val) == 1) {
>                         mem_total = val;
> +               } else {
> +                       tst_res(TWARN, "Faield to parse '%s' MemTotal", path);
> +                       return 0;
> +               }
> 
> -               if (sscanf(buf, "%*s %*i MemUsed: %li", &val) == 1)
> +               if (sscanf(buf, "%*s %*i MemUsed: %li", &val) == 1) {
>                         mem_used = val;
> +               } else {
> +                       tst_res(TWARN, "Faield to parse '%s' MemUsed", path);
> +                       return 0;
> +               }
> 
>                 if (sscanf(buf, "%*s %*i FilePages: %li", &val) == 1)
>                         file_pages = val;
> @@ -161,10 +169,6 @@ static int node_has_enough_memory(int node, size_t min_kb)
> 
>         fclose(fp);
> 
> -       if (!mem_total || !mem_used) {
> -               tst_res(TWARN, "Failed to parse '%s'", path);
> -               return 0;
> -       }
> 
>         mem_avail = mem_total - mem_used + (9 * file_pages)/10;
> 
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz


More information about the ltp mailing list