diff mbox series

[v15,10/11] app/test: replace .sh script with .py script

Message ID 1643173844-27341-11-git-send-email-jizh@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series app/test: enable subset of tests on Windows | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Zhou Jan. 26, 2022, 5:10 a.m. UTC
- Add python script to check if system supports hugepages
- Remove corresponding .sh script
- Replace calling of .sh with corresponding .py in meson.build

Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 app/test/has-hugepage.sh | 11 -----------
 app/test/has_hugepage.py | 26 ++++++++++++++++++++++++++
 app/test/meson.build     |  2 +-
 3 files changed, 27 insertions(+), 12 deletions(-)
 delete mode 100755 app/test/has-hugepage.sh
 create mode 100644 app/test/has_hugepage.py

Comments

Thomas Monjalon Feb. 3, 2022, 11:15 a.m. UTC | #1
26/01/2022 06:10, Jie Zhou:
> - Add python script to check if system supports hugepages
> - Remove corresponding .sh script
> - Replace calling of .sh with corresponding .py in meson.build
> 
> Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  app/test/has-hugepage.sh | 11 -----------
>  app/test/has_hugepage.py | 26 ++++++++++++++++++++++++++

The file MAINTAINERS should be updated with the new file name.
I will do it before merging if the rest is OK.
Jie Zhou Feb. 3, 2022, 6:54 p.m. UTC | #2
O Thu, Feb 03, 2022 at 12:15:19PM +0100, Thomas Monjalon wrote:
> 26/01/2022 06:10, Jie Zhou:
> > - Add python script to check if system supports hugepages
> > - Remove corresponding .sh script
> > - Replace calling of .sh with corresponding .py in meson.build
> > 
> > Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> > Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > ---
> >  app/test/has-hugepage.sh | 11 -----------
> >  app/test/has_hugepage.py | 26 ++++++++++++++++++++++++++
> 
> The file MAINTAINERS should be updated with the new file name.
> I will do it before merging if the rest is OK.
> 

Thanks Thomas. If you prefer me to submit a follow up patch to update the maintainers file, just please let me know.
Thomas Monjalon Feb. 8, 2022, 12:03 p.m. UTC | #3
26/01/2022 06:10, Jie Zhou:
> +    try:
> +        with open("/proc/sys/vm/nr_hugepages") as file_o:
> +            content = file_o.read()
> +            print(content)
> +    except:
> +            print("0")

flake8 says this line is over-indented, I will fix.

There is another warning that I won't fix:
app/test/has_hugepage.py:14:5: E722 do not use bare 'except'
diff mbox series

Patch

diff --git a/app/test/has-hugepage.sh b/app/test/has-hugepage.sh
deleted file mode 100755
index d600fad319..0000000000
--- a/app/test/has-hugepage.sh
+++ /dev/null
@@ -1,11 +0,0 @@ 
-#! /bin/sh
-# SPDX-License-Identifier: BSD-3-Clause
-# Copyright 2020 Mellanox Technologies, Ltd
-
-if [ "$(uname)" = "Linux" ] ; then
-	cat /proc/sys/vm/nr_hugepages || echo 0
-elif [ "$(uname)" = "FreeBSD" ] ; then
-	echo 1 # assume FreeBSD always has hugepages
-else
-	echo 0
-fi
diff --git a/app/test/has_hugepage.py b/app/test/has_hugepage.py
new file mode 100644
index 0000000000..f8e7087d1c
--- /dev/null
+++ b/app/test/has_hugepage.py
@@ -0,0 +1,26 @@ 
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2021 Microsoft Corporation
+"""This script checks if the system supports huge pages"""
+
+import platform
+import ctypes
+
+os_name = platform.system()
+if os_name == "Linux":
+    try:
+        with open("/proc/sys/vm/nr_hugepages") as file_o:
+            content = file_o.read()
+            print(content)
+    except:
+            print("0")
+
+elif os_name == "FreeBSD":
+    # Assume FreeBSD always has hugepages enabled
+    print("1")
+elif os_name == "Windows":
+    if ctypes.windll.kernel32.GetLargePageMinimum() > 0:
+        print("1")
+    else:
+        print("0")
+else:
+    print("0")
diff --git a/app/test/meson.build b/app/test/meson.build
index 725a218f4a..4de0dcd7a7 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -457,7 +457,7 @@  dpdk_test = executable('dpdk-test',
              driver_install_path),
         install: true)
 
-has_hugepage = run_command('has-hugepage.sh').stdout().strip() != '0'
+has_hugepage = run_command(py3, 'has_hugepage.py').stdout().strip() != '0'
 message('hugepage availability: @0@'.format(has_hugepage))
 
 # some perf tests (eg: memcpy perf autotest)take very long