[LTP] [PATCH v2] cpuset/cpuset_memory_pressure_test: Fix free memory calculate

Hao Ge gehao@kylinos.cn
Fri Mar 3 10:24:29 CET 2023


Currently, free has two output formats,as follows

free -m
        total        used        free      shared  buff/cache   available
Mem:   128135        3857      120633         158        3644      123219
Swap:    8191          82        8109

free -m
        total       used       free     shared    buffers     cached
Mem:   419694       9464     410230        234        435       6005
-/+ buffers/cache:       3022     416671
Swap:    2053          0       2053

We need to avoid the error of adding the available item so that py_mem is
wrong.

Signed-off-by: Hao Ge <gehao@kylinos.cn>
---
 .../cpuset_memory_pressure_testset.sh                  | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
index eddd7f6c5..88db03fd9 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
@@ -32,8 +32,16 @@ check
 
 exit_status=0
 
+#read free cmd print layout is buff/cache or buff cache
+bc_string=$(free -m | awk '{if(NR==1) print $5}')
+
 # usable physical memory
-py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
+if [ "$bc_string" == "buff/cache" ]
+then
+        py_mem=$(free -m | awk '{if(NR==2) print $4 + $6}')
+else
+        py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
+fi
 
 # free swap space
 sw_mem=$(free -m | awk '{if(NR==4) print $4}')
-- 
2.25.1



More information about the ltp mailing list