]> git.droids-corp.org - dpdk.git/commitdiff
test: replace shell script with Python
authorJie Zhou <jizh@linux.microsoft.com>
Wed, 26 Jan 2022 05:10:43 +0000 (21:10 -0800)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 8 Feb 2022 13:19:40 +0000 (14:19 +0100)
- 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>
MAINTAINERS
app/test/has-hugepage.sh [deleted file]
app/test/has_hugepage.py [new file with mode: 0644]
app/test/meson.build

index c65b753c6b69724575d32cab68329a1c56403ea6..0f5fc6b1e766c4cd298a362ae1950d5c43d7e6db 100644 (file)
@@ -1638,7 +1638,7 @@ Test Applications
 
 Unit tests framework
 F: app/test/commands.c
-F: app/test/has-hugepage.sh
+F: app/test/has_hugepage.py
 F: app/test/packet_burst_generator.c
 F: app/test/packet_burst_generator.h
 F: app/test/process.h
diff --git a/app/test/has-hugepage.sh b/app/test/has-hugepage.sh
deleted file mode 100755 (executable)
index d600fad..0000000
+++ /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 (file)
index 0000000..c0dd005
--- /dev/null
@@ -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")
index 5476c180ee54acf36023ab73d4ea792a9dbbe5b8..c3bc6c4d97f0be549e4f862260cf0b68a6351cd1 100644 (file)
@@ -457,7 +457,7 @@ dpdk_test = executable('dpdk-test',
              driver_install_path),
         install: true)
 
-has_hugepage = run_command('has-hugepage.sh', check: true).stdout().strip() != '0'
+has_hugepage = run_command(py3, 'has_hugepage.py', check: true).stdout().strip() != '0'
 message('hugepage availability: @0@'.format(has_hugepage))
 
 # some perf tests (eg: memcpy perf autotest)take very long