DPDK patches and discussions
 help / color / mirror / Atom feed
From: Robin Jarry <robin.jarry@6wind.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: dev@dpdk.org, John McNamara <john.mcnamara@intel.com>,
	stable@dpdk.org, Olivier Matz <olivier.matz@6wind.com>
Subject: [dpdk-dev] [PATCH] usertools: fix python 3 support of dpdk-pmdinfo.py
Date: Fri,  6 Sep 2019 14:19:55 +0200	[thread overview]
Message-ID: <20190906121955.24046-1-robin.jarry@6wind.com> (raw)

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


             reply	other threads:[~2019-09-06 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 12:19 Robin Jarry [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190906121955.24046-1-robin.jarry@6wind.com \
    --to=robin.jarry@6wind.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=nhorman@tuxdriver.com \
    --cc=olivier.matz@6wind.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).