Skip to contentSkip to conversation

runpwtests03: use expr to calculate total_cpus for runpwtests03

PATCH New Po-Hsu Lin 3 participants 6 messages Jun 25, 2019 – Jun 27, 2019

lore
Share & tools
lore

Po-Hsu Lin

author
#0 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
 testcases/kernel/power_management/runpwtests03.sh | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +3 -6
index 11197937f..3fb85d273 100755
@@ -25,8 +25,7 @@ export TST_TOTAL=4
 . pm_include.sh
 
 check_cpufreq_sysfs_files() {
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`
 	RC=0
 
 	for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
 change_govr() {
 	available_govr=$(get_supporting_govr)
 
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`
 	RC=0
 
 	for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
 	available_govr=$(get_supporting_govr)
 	RC=0
 
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`
 
 	if ( echo ${available_govr} | grep -i "userspace" \
 		>/dev/null 2>&1 ); then
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

Quoted 25 lines · Po-Hsu Lin

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
  testcases/kernel/power_management/runpwtests03.sh | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +0 -0
index 11197937f..3fb85d273 100755

testcases/kernel/power_management/runpwtests03.sh export TST_TOTAL=4 · line 28

Quoted 6 lines
testcases/kernel/power_management/runpwtests03.sh +1 -2
@@ -25,8 +25,7 @@ export TST_TOTAL=4
  . pm_include.sh
 
  check_cpufreq_sysfs_files() {
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`

Hi,

It's wrong for single variable to use $(), did you mean ${tst_ncpus}?

Best Regards,
Xiao Yang

Quoted 23 lines
testcases/kernel/power_management/runpwtests03.sh +2 -4
  	RC=0
 
  	for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
  change_govr() {
  	available_govr=$(get_supporting_govr)
 
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`
  	RC=0
 
  	for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
  	available_govr=$(get_supporting_govr)
  	RC=0
 
-	total_cpus=$(tst_ncpus)
-	(( total_cpus-=1 ))
+	total_cpus=`expr $(tst_ncpus) - 1`
 
  	if ( echo ${available_govr} | grep -i "userspace" \
  		>/dev/null 2>&1 ); then
author
#2 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

Hello!

The $() here is for the tst_ncpus executable, which will return the total cpu number.

Thanks
PHLin

Quoted 66 lines · Xiao Yang
Quoted 25 lines · Po-Hsu Lin

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
  testcases/kernel/power_management/runpwtests03.sh | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +0 -0
index 11197937f..3fb85d273 100755

testcases/kernel/power_management/runpwtests03.sh export TST_TOTAL=4 · line 28

Quoted 6 lines
testcases/kernel/power_management/runpwtests03.sh +1 -2
@@ -25,8 +25,7 @@ export TST_TOTAL=4
  . pm_include.sh
 
  check_cpufreq_sysfs_files() {
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`

Hi,

It's wrong for single variable to use $(), did you mean ${tst_ncpus}?

Best Regards,
Xiao Yang

Quoted 23 lines
testcases/kernel/power_management/runpwtests03.sh +2 -4
      RC=0
 
      for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
  change_govr() {
      available_govr=$(get_supporting_govr)
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
      RC=0
 
      for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
      available_govr=$(get_supporting_govr)
      RC=0
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
 
      if ( echo ${available_govr} | grep -i "userspace" \
              >/dev/null 2>&1 ); then
#3 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

Hi,

Sorry, I missed the fact that tst_ncpus is executable binary.

It's good to me.

BTW: if you don't want to depend expr command, we can fix it by using total_cpus=$((total_cpus - 1)) instead.

Best Regards,
Xiao Yang

Quoted 72 lines · Po-Hsu Lin

Hello!

The $() here is for the tst_ncpus executable, which will return the total cpu number.

Thanks
PHLin

Quoted 63 lines · Xiao Yang
Quoted 25 lines · Po-Hsu Lin

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
   testcases/kernel/power_management/runpwtests03.sh | 9 +++------
   1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +0 -0
index 11197937f..3fb85d273 100755

testcases/kernel/power_management/runpwtests03.sh export TST_TOTAL=4 · line 28

Quoted 6 lines
testcases/kernel/power_management/runpwtests03.sh +1 -2
@@ -25,8 +25,7 @@ export TST_TOTAL=4
   . pm_include.sh
 
   check_cpufreq_sysfs_files() {
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`

Hi,

It's wrong for single variable to use $(), did you mean ${tst_ncpus}?

Best Regards,
Xiao Yang

Quoted 23 lines
testcases/kernel/power_management/runpwtests03.sh +2 -4
       RC=0
 
       for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
   change_govr() {
       available_govr=$(get_supporting_govr)
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
       RC=0
 
       for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
       available_govr=$(get_supporting_govr)
       RC=0
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
 
       if ( echo ${available_govr} | grep -i "userspace" \
               >/dev/null 2>&1 ); then
author
#4 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

Thanks for the review,

They are both fine with me, if you want to see this to be changed into the double parentheses form, I can send a V2 for that.

Cheers
PHLin

Quoted 89 lines · Xiao Yang

Hi,

Sorry, I missed the fact that tst_ncpus is executable binary.

It's good to me.

BTW: if you don't want to depend expr command, we can fix it by using total_cpus=$((total_cpus - 1)) instead.

Best Regards,
Xiao Yang

Quoted 72 lines · Po-Hsu Lin

Hello!

The $() here is for the tst_ncpus executable, which will return the total cpu number.

Thanks
PHLin

Quoted 63 lines · Xiao Yang
Quoted 25 lines · Po-Hsu Lin

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
   testcases/kernel/power_management/runpwtests03.sh | 9 +++------
   1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +0 -0
index 11197937f..3fb85d273 100755

testcases/kernel/power_management/runpwtests03.sh export TST_TOTAL=4 · line 28

Quoted 6 lines
testcases/kernel/power_management/runpwtests03.sh +1 -2
@@ -25,8 +25,7 @@ export TST_TOTAL=4
   . pm_include.sh
 
   check_cpufreq_sysfs_files() {
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`

Hi,

It's wrong for single variable to use $(), did you mean ${tst_ncpus}?

Best Regards,
Xiao Yang

Quoted 23 lines
testcases/kernel/power_management/runpwtests03.sh +2 -4
       RC=0
 
       for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
   change_govr() {
       available_govr=$(get_supporting_govr)
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
       RC=0
 
       for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
       available_govr=$(get_supporting_govr)
       RC=0
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
 
       if ( echo ${available_govr} | grep -i "userspace" \
               >/dev/null 2>&1 ); then
#5 lore raw

PATCH 1/1 runpwtests03: use expr to calculate total_cpus for runpwtests03

Hi,

Don't need.? It's fine to me as well.

Pushed, thanks for your patch.

Best Reagrds,

Xiao Yang

Quoted 95 lines · Po-Hsu Lin

Thanks for the review,

They are both fine with me, if you want to see this to be changed into the double parentheses form, I can send a V2 for that.

Cheers
PHLin

Quoted 86 lines · Xiao Yang

Hi,

Sorry, I missed the fact that tst_ncpus is executable binary.

It's good to me.

BTW: if you don't want to depend expr command, we can fix it by using total_cpus=$((total_cpus - 1)) instead.

Best Regards,
Xiao Yang

Quoted 71 lines · Po-Hsu Lin

Hello!

The $() here is for the tst_ncpus executable, which will return the total cpu number.

Thanks
PHLin

Quoted 62 lines · Xiao Yang
Quoted 25 lines · Po-Hsu Lin

The arithmetic operation (( total_cpus-=1 )) does not work for dash, which was symbolic linked to /bin/sh on some OS like Ubuntu.

In such case, people will see error like:
runpwtests03.sh: total_cpus-=1: not found

And this further leads to access for a non-existing file and cause false-positive result in the end:
runpwtests03.sh: cannot create /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor: Directory nonexistent runpwtests03.sh: FAIL: Unable to set governor -- powersave for cpu8 Power_Management03 2 TFAIL: Changing governors

Use expr instead for fix this issue.

---
    testcases/kernel/power_management/runpwtests03.sh | 9 +++------
    1 file changed, 3 insertions(+), 6 deletions(-)
testcases/kernel/power_management/runpwtests03.sh +0 -0
index 11197937f..3fb85d273 100755

testcases/kernel/power_management/runpwtests03.sh export TST_TOTAL=4 · line 28

Quoted 6 lines
testcases/kernel/power_management/runpwtests03.sh +1 -2
@@ -25,8 +25,7 @@ export TST_TOTAL=4
    . pm_include.sh
 
    check_cpufreq_sysfs_files() {
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`

Hi,

It's wrong for single variable to use $(), did you mean ${tst_ncpus}?

Best Regards,
Xiao Yang

Quoted 23 lines
testcases/kernel/power_management/runpwtests03.sh +2 -4
        RC=0
 
        for cpu in $(seq 0 "${total_cpus}" )
@@ -51,8 +50,7 @@ check_cpufreq_sysfs_files() {
    change_govr() {
        available_govr=$(get_supporting_govr)
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
        RC=0
 
        for cpu in $(seq 0 "${total_cpus}" )
@@ -79,8 +77,7 @@ change_freq() {
        available_govr=$(get_supporting_govr)
        RC=0
 
-     total_cpus=$(tst_ncpus)
-     (( total_cpus-=1 ))
+     total_cpus=`expr $(tst_ncpus) - 1`
 
        if ( echo ${available_govr} | grep -i "userspace" \
                >/dev/null 2>&1 ); then