Bug 2199 - Python 3 error on test.py and valgrind
Python 3 error on test.py and valgrind
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: test framework
pre-release
PC Linux
: P5 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-10-27 05:37 UTC by natale.patriciello
Modified: 2015-10-27 15:53 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description natale.patriciello 2015-10-27 05:37:07 UTC
When using python3, and test.py with valgrind, the following may appear:

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 923, in _bootstrap_inner
    self.run()
  File "./test.py", line 971, in run
    job.cwd, options.valgrind, job.is_pyexample, job.build_path)
  File "./test.py", line 780, in run_job_synchronously
    if valgrind and retval == 0 and "== LEAK SUMMARY:" in stderr_results:
TypeError: a bytes-like object is required, not 'str'

This is because stderr_results, obtained with

  stdout_results, stderr_results = proc.communicate()

has changed type. Before, it was a string (Captured stderr from the child process. A bytes sequence, or a string if run() was called with universal_newlines=True. None if stderr was not captured, from [1]). So, a quick fix is to decode the bytes into a string:


  stdout_results, stderr_results = proc.communicate()
  elapsed_time = time.time() - start_time

  retval = proc.returncode
  stdout_results = stdout_results.decode("utf-8")
  stderr_results = stderr_results.decode("utf-8")

  ...

And then enjoy test.py -g without errors.
Have a nice day!


[1] https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module
Comment 1 Tom Henderson 2015-10-27 15:53:01 UTC
fixed in changeset 11731:7890c40df838