diff mbox series

[v5,3/3] max_map_count: replace ifdefs by tst_arch

Message ID 20211117070708.2174932-3-liwang@redhat.com
State Changes Requested
Headers show
Series [v5,1/3] lib: adding .supported_archs field in tst_test structure | expand

Commit Message

Li Wang Nov. 17, 2021, 7:07 a.m. UTC
Signed-off-by: Li Wang <liwang@redhat.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/mem/tunable/max_map_count.c | 46 ++++++++++----------
 1 file changed, 24 insertions(+), 22 deletions(-)

Comments

Richard Palethorpe Nov. 17, 2021, 10:33 a.m. UTC | #1
Hello Li,

Li Wang <liwang@redhat.com> writes:

> Signed-off-by: Li Wang <liwang@redhat.com>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/mem/tunable/max_map_count.c | 46 ++++++++++----------
>  1 file changed, 24 insertions(+), 22 deletions(-)
>
> diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
> index 4f0ad0037..a4c3dbf8e 100644
> --- a/testcases/kernel/mem/tunable/max_map_count.c
> +++ b/testcases/kernel/mem/tunable/max_map_count.c
> @@ -55,7 +55,6 @@
>  
>  static long old_max_map_count = -1;
>  static long old_overcommit = -1;
> -static struct utsname un;
>  
>  static void setup(void)
>  {
> @@ -66,9 +65,6 @@ static void setup(void)
>  	old_max_map_count = get_sys_tune("max_map_count");
>  	old_overcommit = get_sys_tune("overcommit_memory");
>  	set_sys_tune("overcommit_memory", 0, 1);
> -
> -	if (uname(&un) != 0)
> -		tst_brk(TBROK | TERRNO, "uname error");
>  }
>  
>  static void cleanup(void)
> @@ -91,24 +87,30 @@ static bool filter_map(const char *line)
>  	if (ret != 1)
>  		return false;
>  
> -#if defined(__x86_64__) || defined(__x86__)
> -	/* On x86, there's an old compat vsyscall page */
> -	if (!strcmp(buf, "[vsyscall]"))
> -		return true;
> -#elif defined(__ia64__)
> -	/* On ia64, the vdso is not a proper mapping */
> -	if (!strcmp(buf, "[vdso]"))
> -		return true;
> -#elif defined(__arm__)
> -	/* Skip it when run it in aarch64 */
> -	if ((!strcmp(un.machine, "aarch64"))
> -	|| (!strcmp(un.machine, "aarch64_be")))
> -		return false;
> -
> -	/* Older arm kernels didn't label their vdso maps */
> -	if (!strncmp(line, "ffff0000-ffff1000", 17))
> -		return true;
> -#endif
> +	switch (tst_arch.type) {
> +	case TST_X86:
> +	case TST_X86_64:
> +		/* On x86, there's an old compat vsyscall page */
> +		if (!strcmp(buf, "[vsyscall]"))
> +			return true;
> +		break;
> +	case TST_IA64:
> +		/* On ia64, the vdso is not a proper mapping */
> +		if (!strcmp(buf, "[vdso]"))
> +			return true;
> +		break;
> +	case TST_ARM:
> +		/* Skip it when run it in aarch64 */

This should not be possible. If TST_ARM is set then how can we be on
aarch64? We also have TST_AARCH64.

> +		if (tst_kernel_bits() == 64)
> +			return false;
> +
> +		/* Older arm kernels didn't label their vdso maps */
> +		if (!strncmp(line, "ffff0000-ffff1000", 17))
> +			return true;
> +		break;
> +	default:
> +		break;
> +	};
>  
>  	return false;
>  }
> -- 
> 2.31.1
Li Wang Nov. 17, 2021, 1:28 p.m. UTC | #2
Hi Richard,



> > +     case TST_IA64:
> > +             /* On ia64, the vdso is not a proper mapping */
> > +             if (!strcmp(buf, "[vdso]"))
> > +                     return true;
> > +             break;
> > +     case TST_ARM:
> > +             /* Skip it when run it in aarch64 */
>
> This should not be possible. If TST_ARM is set then how can we be on
> aarch64? We also have TST_AARCH64.
>

Not exactly, I was thinking like this before, but as Cyril point that there
is
a possible 32bit ARM binary runs on 64bit aarch64 kernel.

https://lists.linux.it/pipermail/ltp/2021-November/025925.html
Richard Palethorpe Nov. 17, 2021, 1:58 p.m. UTC | #3
Hello Li,

Li Wang <liwang@redhat.com> writes:

> Hi Richard,
>
>  
>  > +     case TST_IA64:
>  > +             /* On ia64, the vdso is not a proper mapping */
>  > +             if (!strcmp(buf, "[vdso]"))
>  > +                     return true;
>  > +             break;
>  > +     case TST_ARM:
>  > +             /* Skip it when run it in aarch64 */
>
>  This should not be possible. If TST_ARM is set then how can we be on
>  aarch64? We also have TST_AARCH64.
>
> Not exactly, I was thinking like this before, but as Cyril point that there is
> a possible 32bit ARM binary runs on 64bit aarch64 kernel.
>
> https://lists.linux.it/pipermail/ltp/2021-November/025925.html

Thanks

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
diff mbox series

Patch

diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
index 4f0ad0037..a4c3dbf8e 100644
--- a/testcases/kernel/mem/tunable/max_map_count.c
+++ b/testcases/kernel/mem/tunable/max_map_count.c
@@ -55,7 +55,6 @@ 
 
 static long old_max_map_count = -1;
 static long old_overcommit = -1;
-static struct utsname un;
 
 static void setup(void)
 {
@@ -66,9 +65,6 @@  static void setup(void)
 	old_max_map_count = get_sys_tune("max_map_count");
 	old_overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 0, 1);
-
-	if (uname(&un) != 0)
-		tst_brk(TBROK | TERRNO, "uname error");
 }
 
 static void cleanup(void)
@@ -91,24 +87,30 @@  static bool filter_map(const char *line)
 	if (ret != 1)
 		return false;
 
-#if defined(__x86_64__) || defined(__x86__)
-	/* On x86, there's an old compat vsyscall page */
-	if (!strcmp(buf, "[vsyscall]"))
-		return true;
-#elif defined(__ia64__)
-	/* On ia64, the vdso is not a proper mapping */
-	if (!strcmp(buf, "[vdso]"))
-		return true;
-#elif defined(__arm__)
-	/* Skip it when run it in aarch64 */
-	if ((!strcmp(un.machine, "aarch64"))
-	|| (!strcmp(un.machine, "aarch64_be")))
-		return false;
-
-	/* Older arm kernels didn't label their vdso maps */
-	if (!strncmp(line, "ffff0000-ffff1000", 17))
-		return true;
-#endif
+	switch (tst_arch.type) {
+	case TST_X86:
+	case TST_X86_64:
+		/* On x86, there's an old compat vsyscall page */
+		if (!strcmp(buf, "[vsyscall]"))
+			return true;
+		break;
+	case TST_IA64:
+		/* On ia64, the vdso is not a proper mapping */
+		if (!strcmp(buf, "[vdso]"))
+			return true;
+		break;
+	case TST_ARM:
+		/* Skip it when run it in aarch64 */
+		if (tst_kernel_bits() == 64)
+			return false;
+
+		/* Older arm kernels didn't label their vdso maps */
+		if (!strncmp(line, "ffff0000-ffff1000", 17))
+			return true;
+		break;
+	default:
+		break;
+	};
 
 	return false;
 }