patches for DPDK stable branches
 help / color / Atom feed
* [dpdk-stable] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py
@ 2019-09-06 12:19 Robin Jarry
  0 siblings, 0 replies; only message in thread
From: Robin Jarry @ 2019-09-06 12:19 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev, John McNamara, stable, Olivier Matz

Running this script on ubuntu-18.04 with python 3 and pyelftools
installed produces no output but no error is reported neither:

  ~$ python3 usertools/dpdk-pmdinfo.py -r build/app/testpmd
  ~$ echo $?
  0

While with python 2, it works:

  ~# python2 usertools/dpdk-pmdinfo.py -r build/app/testpmd
  {"pci_ids": [], "name": "dpio"}
  {"pci_ids": [], "name": "dpbp"}
  {"pci_ids": [], "name": "dpaa2_qdma"}
  .....

Looking in the code of pyelftools, ELFFile.get_section_by_name performs
a lookup in a _section_name_map dictionary which contains a mapping of
section names to section numbers. Section names are strings, not bytes.
We must not encode the string before using it as argument to this
function. Otherwise the lookup fails and the script assumes there is no
ELF section in the file. Then it exits without any error.

Also, section tags are strings, not bytes, fix the following error on
python 3:

  Traceback (most recent call last):
    File "usertools/dpdk-pmdinfo.py", line 612, in <module>
      main()
    File "usertools/dpdk-pmdinfo.py", line 601, in main
      readelf.process_dt_needed_entries()
    File "usertools/dpdk-pmdinfo.py", line 442, in
    process_dt_needed_entries
      rc = tag.needed.find(b"librte_pmd")
  TypeError: must be str, not bytes

Fixes: c67c9a5c646a ("tools: query binaries for HW and other support information")
Cc: Neil Horman <nhorman@tuxdriver.com>
Fixes: 54ca545dce4b ("make python scripts python2/3 compliant")
Cc: John McNamara <john.mcnamara@intel.com>
Cc: stable@dpdk.org

Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
---
 usertools/dpdk-pmdinfo.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
index 03623d5b8b48..d2d4aa3c143f 100755
--- a/usertools/dpdk-pmdinfo.py
+++ b/usertools/dpdk-pmdinfo.py
@@ -14,7 +14,7 @@
 import string
 import sys
 from elftools.common.exceptions import ELFError
-from elftools.common.py3compat import (byte2int, bytes2str, str2bytes)
+from elftools.common.py3compat import (byte2int, bytes2str)
 from elftools.elf.elffile import ELFFile
 from optparse import OptionParser
 
@@ -267,7 +267,7 @@ def _section_from_spec(self, spec):
                 return None
         except ValueError:
             # Not a number. Must be a name then
-            return self.elffile.get_section_by_name(str2bytes(spec))
+            return self.elffile.get_section_by_name(spec)
 
     def pretty_print_pmdinfo(self, pmdinfo):
         global pcidb
@@ -439,7 +439,7 @@ def process_dt_needed_entries(self):
 
         for tag in dynsec.iter_tags():
             if tag.entry.d_tag == 'DT_NEEDED':
-                rc = tag.needed.find(b"librte_pmd")
+                rc = tag.needed.find("librte_pmd")
                 if (rc != -1):
                     library = search_file(tag.needed,
                                           runpath + ":" + ldlibpath +
-- 
2.23.0.rc1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 12:19 [dpdk-stable] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py Robin Jarry

patches for DPDK stable branches

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/ public-inbox