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

Cyril Hrubis chrubis@suse.cz
Tue May 9 13:59:01 CEST 2023


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:

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