[dpdk-dev] [PATCH] devtools: add script to verify map files

Pavan Nikhilesh pbhagavatula at caviumnetworks.com
Mon Feb 12 17:13:12 CET 2018


This script checks for the symbols specified in the map files against
the symbols present in the map file directory.
Currently, the script checks for map files in drivers and lib directory.

Example:
./devtools/check-map.py

The following symbols are unused :

Map file : /home/pavan/Work/clean/dpdk/drivers/mempool/dpaa/...
['rte_dpaa_pool_table']

Map file : /home/pavan/Work/clean/dpdk/drivers/bus/fslmc/...
['qbman_get_version', 'qbman_swp_send_multiple']

...

Signed-off-by: Pavan Nikhilesh <pbhagavatula at caviumnetworks.com>
---
 devtools/check-map.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 devtools/check-map.py

diff --git a/devtools/check-map.py b/devtools/check-map.py
new file mode 100755
index 000000000..a508469d6
--- /dev/null
+++ b/devtools/check-map.py
@@ -0,0 +1,56 @@
+#! /usr/bin/env python
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017 Cavium, Inc
+#
+
+import subprocess
+import re
+import os
+from glob import glob
+
+paths = ['drivers', 'lib']
+map_files = []
+
+for path in paths:
+    map_files = map_files + [y
+                             for x in os.walk(os.environ['PWD'] + '/' + path)
+                             for y in glob(os.path.join(x[0],
+                                                        '*.map'))]
+
+print("\nThe following symbols are unused : \n")
+for map_file in map_files:
+    path = os.path.dirname(os.path.abspath(map_file))
+    with open(map_file) as f:
+        map_content = [line.strip() for line in f]
+    # Filter empty lines.
+    map_content = list(filter(None, map_content))
+    regex = re.compile(
+            r"""
+            \bDPDK.*\b |
+            \bglobal.*\b |
+            \blocal.*\b | \}.* |
+            \bEXPERIMENTAL\b |
+            \bper_lcore.*\b""",
+            flags=re.I | re.X | re.VERBOSE)
+    filtered_map = filter(lambda i: not regex.search(i), map_content)
+    filtered_map = [i for i in map_content if not regex.search(i)]
+    filtered_map = [s.replace(';', '') for s in filtered_map]
+    # Filter out known lines.
+    if not filtered_map:
+        continue
+    not_found = []
+    # Gerp in the map file directory for each symbol
+    for map_symbol in filtered_map:
+        try:
+            op = subprocess.check_output(['grep', '-nr', '--exclude',
+                                          os.path.basename(map_file),
+                                          map_symbol,
+                                          path])
+        except subprocess.CalledProcessError as ex:
+            not_found.append(map_symbol)
+            rc = ex.returncode
+            if rc != 1:
+                raise
+    if not_found:
+        print("Map file : %s" % map_file)
+        print("%s\n" % not_found)
-- 
2.16.1



More information about the dev mailing list