[v8,10/11] app/test: replace .sh scripts with .py scripts
Checks
Commit Message
- Add python script to check if system supports hugepages
- Remove corresponding .sh scripts
- Replace calling of .sh with corresponding .py in meson.build
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
---
app/test/has-hugepage.sh | 11 -----------
app/test/has_hugepage.py | 25 +++++++++++++++++++++++++
app/test/meson.build | 2 +-
3 files changed, 26 insertions(+), 12 deletions(-)
delete mode 100755 app/test/has-hugepage.sh
create mode 100644 app/test/has_hugepage.py
Comments
2021-10-25 19:46 (UTC-0700), Jie Zhou:
> - Add python script to check if system supports hugepages
> - Remove corresponding .sh scripts
> - Replace calling of .sh with corresponding .py in meson.build
>
> Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> ---
> app/test/has-hugepage.sh | 11 -----------
> app/test/has_hugepage.py | 25 +++++++++++++++++++++++++
> app/test/meson.build | 2 +-
> 3 files changed, 26 insertions(+), 12 deletions(-)
> delete mode 100755 app/test/has-hugepage.sh
> create mode 100644 app/test/has_hugepage.py
>
> 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..70107c61fd
> --- /dev/null
> +++ b/app/test/has_hugepage.py
> @@ -0,0 +1,25 @@
> +# SPDX-License-Identifier: BSD-3-Clause
> +# Copyright (c) 2021 Microsoft Corporation
> +"""This script checks if the system supports huge pages"""
> +
> +import platform
> +import ctypes
> +
> +osName = platform.system()
Please follow Python's preferred naming style, "os_name".
> +if osName == "Linux":
> + with open("/proc/sys/vm/nr_hugepages") as file_o:
> + content = file_o.read()
> + print(content)
Compared to shell version, lost is the logic to print 0 in case of a failure.
> +elif osName == "FreeBSD":
> + # Assume FreeBSD always has hugepages enabled
> + print("1")
> +elif osName == "Windows":
> + # On Windows, determine if large page is supported based on the
> + # value returned by GetLargePageMinimum. If the return value is zero,
> + # the processor does not support large pages.
I honestly don't see what this comment adds to the code below :)
> + if ctypes.windll.kernel32.GetLargePageMinimum() > 0:
> + print("1")
> + else:
> + print("0")
> +else:
> + print("0")
[...]
On Wed, Nov 24, 2021 at 01:15:33AM +0300, Dmitry Kozlyuk wrote:
> 2021-10-25 19:46 (UTC-0700), Jie Zhou:
> > - Add python script to check if system supports hugepages
> > - Remove corresponding .sh scripts
> > - Replace calling of .sh with corresponding .py in meson.build
> >
> > Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> > ---
> > app/test/has-hugepage.sh | 11 -----------
> > app/test/has_hugepage.py | 25 +++++++++++++++++++++++++
> > app/test/meson.build | 2 +-
> > 3 files changed, 26 insertions(+), 12 deletions(-)
> > delete mode 100755 app/test/has-hugepage.sh
> > create mode 100644 app/test/has_hugepage.py
> >
> > 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..70107c61fd
> > --- /dev/null
> > +++ b/app/test/has_hugepage.py
> > @@ -0,0 +1,25 @@
> > +# SPDX-License-Identifier: BSD-3-Clause
> > +# Copyright (c) 2021 Microsoft Corporation
> > +"""This script checks if the system supports huge pages"""
> > +
> > +import platform
> > +import ctypes
> > +
> > +osName = platform.system()
>
> Please follow Python's preferred naming style, "os_name".
>
> > +if osName == "Linux":
> > + with open("/proc/sys/vm/nr_hugepages") as file_o:
> > + content = file_o.read()
> > + print(content)
>
> Compared to shell version, lost is the logic to print 0 in case of a failure.
>
> > +elif osName == "FreeBSD":
> > + # Assume FreeBSD always has hugepages enabled
> > + print("1")
> > +elif osName == "Windows":
> > + # On Windows, determine if large page is supported based on the
> > + # value returned by GetLargePageMinimum. If the return value is zero,
> > + # the processor does not support large pages.
>
> I honestly don't see what this comment adds to the code below :)
>
> > + if ctypes.windll.kernel32.GetLargePageMinimum() > 0:
> > + print("1")
> > + else:
> > + print("0")
> > +else:
> > + print("0")
> [...]
Thanks Dmitry. Addressed all in V9.
deleted file mode 100755
@@ -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
new file mode 100644
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2021 Microsoft Corporation
+"""This script checks if the system supports huge pages"""
+
+import platform
+import ctypes
+
+osName = platform.system()
+if osName == "Linux":
+ with open("/proc/sys/vm/nr_hugepages") as file_o:
+ content = file_o.read()
+ print(content)
+elif osName == "FreeBSD":
+ # Assume FreeBSD always has hugepages enabled
+ print("1")
+elif osName == "Windows":
+ # On Windows, determine if large page is supported based on the
+ # value returned by GetLargePageMinimum. If the return value is zero,
+ # the processor does not support large pages.
+ if ctypes.windll.kernel32.GetLargePageMinimum() > 0:
+ print("1")
+ else:
+ print("0")
+else:
+ print("0")
@@ -463,7 +463,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