summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/tcp_server.py
diff options
context:
space:
mode:
authorJeremy Cline <jcline@redhat.com>2018-07-24 15:53:34 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-25 07:46:48 +0200
commite66565f3bee141748d2c3b2ed0d4ecd455f634fa (patch)
tree1c93844b2b0a9d4d06bcd36f6ef7acb6e087ebb2 /tools/testing/selftests/bpf/tcp_server.py
parent2cc512c1fa1ee99879d55d1cb4e3fd0e6eab35b3 (diff)
downloadtalos-op-linux-e66565f3bee141748d2c3b2ed0d4ecd455f634fa.tar.gz
talos-op-linux-e66565f3bee141748d2c3b2ed0d4ecd455f634fa.zip
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_server.py')
-rwxr-xr-xtools/testing/selftests/bpf/tcp_server.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/tools/testing/selftests/bpf/tcp_server.py b/tools/testing/selftests/bpf/tcp_server.py
index bc454d7d0be2..b39903fca4c8 100755
--- a/tools/testing/selftests/bpf/tcp_server.py
+++ b/tools/testing/selftests/bpf/tcp_server.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
#
# SPDX-License-Identifier: GPL-2.0
#
@@ -9,11 +9,11 @@ import subprocess
import select
def read(sock, n):
- buf = ''
+ buf = b''
while len(buf) < n:
rem = n - len(buf)
try: s = sock.recv(rem)
- except (socket.error), e: return ''
+ except (socket.error) as e: return b''
buf += s
return buf
@@ -22,7 +22,7 @@ def send(sock, s):
count = 0
while count < total:
try: n = sock.send(s)
- except (socket.error), e: n = 0
+ except (socket.error) as e: n = 0
if n == 0:
return count;
count += n
@@ -43,7 +43,7 @@ host = socket.gethostname()
try: serverSocket.bind((host, 0))
except socket.error as msg:
- print 'bind fails: ', msg
+ print('bind fails: ' + str(msg))
sn = serverSocket.getsockname()
serverPort = sn[1]
@@ -51,10 +51,10 @@ serverPort = sn[1]
cmdStr = ("./tcp_client.py %d &") % (serverPort)
os.system(cmdStr)
-buf = ''
+buf = b''
n = 0
while n < 500:
- buf += '.'
+ buf += b'.'
n += 1
serverSocket.listen(MAX_PORTS)
@@ -79,5 +79,5 @@ while True:
serverSocket.close()
sys.exit(0)
else:
- print 'Select timeout!'
+ print('Select timeout!')
sys.exit(1)
OpenPOWER on IntegriCloud