diff mbox series

[1/2] selftests: mm: ksm: Fix incorrect evaluation of parameter

Message ID 20230728060109.4403-1-ayush.jain3@amd.com (mailing list archive)
State New
Headers show
Series [1/2] selftests: mm: ksm: Fix incorrect evaluation of parameter | expand

Commit Message

Ayush Jain July 28, 2023, 6:01 a.m. UTC
A missing break in kms_tests leads to kselftest hang when the
parameter -s is used.
In current code flow because of missing break in -s, -t parses
args spilled from -s and as -t accepts only valid values as 0,1
so any arg in -s >1 or <0, gets in ksm_test failure

This went undetected since, before the addition of option -t,
the next case -M would immediately break out of the switch
statement but that is no longer the case

Add the missing break statement.

----Before----
./ksm_tests -H -s 100
Invalid merge type

----After----
./ksm_tests -H -s 100
Number of normal pages:    0
Number of huge pages:    50
Total size:    100 MiB
Total time:    0.401732682 s
Average speed:  248.922 MiB/s

Fixes: 9e7cb94ca218 ("selftests: vm: add KSM merging time test")

Signed-off-by: Ayush Jain <ayush.jain3@amd.com>
---
 tools/testing/selftests/mm/ksm_tests.c | 1 +
 1 file changed, 1 insertion(+)

Comments

David Hildenbrand July 28, 2023, 2:35 p.m. UTC | #1
On 28.07.23 08:01, Ayush Jain wrote:
> A missing break in kms_tests leads to kselftest hang when the
> parameter -s is used.
> In current code flow because of missing break in -s, -t parses
> args spilled from -s and as -t accepts only valid values as 0,1
> so any arg in -s >1 or <0, gets in ksm_test failure
> 
> This went undetected since, before the addition of option -t,
> the next case -M would immediately break out of the switch
> statement but that is no longer the case
> 
> Add the missing break statement.
> 
> ----Before----
> ./ksm_tests -H -s 100
> Invalid merge type
> 
> ----After----
> ./ksm_tests -H -s 100
> Number of normal pages:    0
> Number of huge pages:    50
> Total size:    100 MiB
> Total time:    0.401732682 s
> Average speed:  248.922 MiB/s
> 
> Fixes: 9e7cb94ca218 ("selftests: vm: add KSM merging time test")

I think this actually fixes 07115fcc15b4 ("selftests/mm: add new 
selftests for KSM") that added the "t" parsing.

Reviewed-by: David Hildenbrand <david@redhat.com>
Ayush Jain July 28, 2023, 4:15 p.m. UTC | #2
Hello David,

On 7/28/2023 8:05 PM, David Hildenbrand wrote:
> On 28.07.23 08:01, Ayush Jain wrote:
>> A missing break in kms_tests leads to kselftest hang when the
>> parameter -s is used.
>> In current code flow because of missing break in -s, -t parses
>> args spilled from -s and as -t accepts only valid values as 0,1
>> so any arg in -s >1 or <0, gets in ksm_test failure
>>
>> This went undetected since, before the addition of option -t,
>> the next case -M would immediately break out of the switch
>> statement but that is no longer the case
>>
>> Add the missing break statement.
>>
>> ----Before----
>> ./ksm_tests -H -s 100
>> Invalid merge type
>>
>> ----After----
>> ./ksm_tests -H -s 100
>> Number of normal pages:    0
>> Number of huge pages:    50
>> Total size:    100 MiB
>> Total time:    0.401732682 s
>> Average speed:  248.922 MiB/s
>>
>> Fixes: 9e7cb94ca218 ("selftests: vm: add KSM merging time test")
> 
> I think this actually fixes 07115fcc15b4 ("selftests/mm: add new selftests for KSM") that added the "t" parsing.
> 

Sure will update in v2.

> Reviewed-by: David Hildenbrand <david@redhat.com>
> 

Thanks,
Ayush Jain
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index 435acebdc325..380b691d3eb9 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -831,6 +831,7 @@  int main(int argc, char *argv[])
 				printf("Size must be greater than 0\n");
 				return KSFT_FAIL;
 			}
+			break;
 		case 't':
 			{
 				int tmp = atoi(optarg);