diff options
author | Jeremy Cline <jcline@redhat.com> | 2018-07-24 15:53:34 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-25 01:46:48 -0400 |
commit | e66565f3bee141748d2c3b2ed0d4ecd455f634fa (patch) | |
tree | 1c93844b2b0a9d4d06bcd36f6ef7acb6e087ebb2 /tools/testing/selftests/bpf/tcp_client.py | |
parent | 2cc512c1fa1ee99879d55d1cb4e3fd0e6eab35b3 (diff) |
bpf: Add Python 3 support to selftests scripts for bpf
Adjust tcp_client.py and tcp_server.py to work with Python 3 by using
the print function, marking string literals as bytes, and using the
newer exception syntax. This should be functionally equivalent and
supports Python 3+.
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/testing/selftests/bpf/tcp_client.py')
-rwxr-xr-x | tools/testing/selftests/bpf/tcp_client.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/tools/testing/selftests/bpf/tcp_client.py b/tools/testing/selftests/bpf/tcp_client.py index 481dccdf140c..7f8200a8702b 100755 --- a/tools/testing/selftests/bpf/tcp_client.py +++ b/tools/testing/selftests/bpf/tcp_client.py | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python2 | 1 | #!/usr/bin/env python3 |
2 | # | 2 | # |
3 | # SPDX-License-Identifier: GPL-2.0 | 3 | # SPDX-License-Identifier: GPL-2.0 |
4 | # | 4 | # |
@@ -9,11 +9,11 @@ import subprocess | |||
9 | import select | 9 | import select |
10 | 10 | ||
11 | def read(sock, n): | 11 | def read(sock, n): |
12 | buf = '' | 12 | buf = b'' |
13 | while len(buf) < n: | 13 | while len(buf) < n: |
14 | rem = n - len(buf) | 14 | rem = n - len(buf) |
15 | try: s = sock.recv(rem) | 15 | try: s = sock.recv(rem) |
16 | except (socket.error), e: return '' | 16 | except (socket.error) as e: return b'' |
17 | buf += s | 17 | buf += s |
18 | return buf | 18 | return buf |
19 | 19 | ||
@@ -22,7 +22,7 @@ def send(sock, s): | |||
22 | count = 0 | 22 | count = 0 |
23 | while count < total: | 23 | while count < total: |
24 | try: n = sock.send(s) | 24 | try: n = sock.send(s) |
25 | except (socket.error), e: n = 0 | 25 | except (socket.error) as e: n = 0 |
26 | if n == 0: | 26 | if n == 0: |
27 | return count; | 27 | return count; |
28 | count += n | 28 | count += n |
@@ -39,10 +39,10 @@ try: | |||
39 | except socket.error as e: | 39 | except socket.error as e: |
40 | sys.exit(1) | 40 | sys.exit(1) |
41 | 41 | ||
42 | buf = '' | 42 | buf = b'' |
43 | n = 0 | 43 | n = 0 |
44 | while n < 1000: | 44 | while n < 1000: |
45 | buf += '+' | 45 | buf += b'+' |
46 | n += 1 | 46 | n += 1 |
47 | 47 | ||
48 | sock.settimeout(1); | 48 | sock.settimeout(1); |