DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py
@ 2019-09-06 12:19 Robin Jarry
  2019-09-10  7:11 ` [dpdk-dev] [PATCH v2] usertools: fix py3 support with pyelftools>=0.24 Robin Jarry
  0 siblings, 1 reply; 4+ messages 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] 4+ messages in thread

end of thread, other threads:[~2019-10-27 20:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 12:19 [dpdk-dev] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py Robin Jarry
2019-09-10  7:11 ` [dpdk-dev] [PATCH v2] usertools: fix py3 support with pyelftools>=0.24 Robin Jarry
2019-10-15 12:39   ` [dpdk-dev] [PATCH v3] " Robin Jarry
2019-10-27 20:32     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).