Skip to content

Commit a40b702

Browse files
Joelgranadosmcgrof
authored andcommitted
test_sysctl: Fix test metadata getters
The functions get_test_{count,enabled,target} use awk to get the N'th field in the ALL_TESTS variable. A variable with leading zeros (e.g. 0009) is misinterpreted as an entire line instead of the N'th field. Remove the leading zeros so this does not happen. We can now use the helper in tests 6, 7 and 8. Signed-off-by: Joel Granados <j.granados@samsung.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent 37e9981 commit a40b702

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

tools/testing/selftests/sysctl/sysctl.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,15 @@ sysctl_test_0005()
730730

731731
sysctl_test_0006()
732732
{
733-
TARGET="${SYSCTL}/bitmap_0001"
733+
TARGET="${SYSCTL}/$(get_test_target 0006)"
734734
reset_vals
735735
ORIG=""
736736
run_bitmaptest
737737
}
738738

739739
sysctl_test_0007()
740740
{
741-
TARGET="${SYSCTL}/boot_int"
741+
TARGET="${SYSCTL}/$(get_test_target 0007)"
742742
if [ ! -f $TARGET ]; then
743743
echo "Skipping test for $TARGET as it is not present ..."
744744
return $ksft_skip
@@ -778,7 +778,7 @@ sysctl_test_0007()
778778

779779
sysctl_test_0008()
780780
{
781-
TARGET="${SYSCTL}/match_int"
781+
TARGET="${SYSCTL}/$(get_test_target 0008)"
782782
if [ ! -f $TARGET ]; then
783783
echo "Skipping test for $TARGET as it is not present ..."
784784
return $ksft_skip
@@ -857,25 +857,32 @@ function test_num()
857857
usage
858858
fi
859859
}
860+
function remove_leading_zeros()
861+
{
862+
echo $1 | sed 's/^0*//'
863+
}
860864

861865
function get_test_count()
862866
{
863867
test_num $1
864-
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
868+
awk_field=$(remove_leading_zeros $1)
869+
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$awk_field'}')
865870
echo ${TEST_DATA} | awk -F":" '{print $2}'
866871
}
867872

868873
function get_test_enabled()
869874
{
870875
test_num $1
871-
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
876+
awk_field=$(remove_leading_zeros $1)
877+
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$awk_field'}')
872878
echo ${TEST_DATA} | awk -F":" '{print $3}'
873879
}
874880

875881
function get_test_target()
876882
{
877883
test_num $1
878-
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
884+
awk_field=$(remove_leading_zeros $1)
885+
TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$awk_field'}')
879886
echo ${TEST_DATA} | awk -F":" '{print $4}'
880887
}
881888

0 commit comments

Comments
 (0)