Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5033imm; Tue, 24 Jul 2018 12:55:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdI7lGTlbEegPx8qVCd2wr8OJCuTJlqW2GN6Vc0VeYD6ZaBT/2g0VrlwDFLohUK5tZmtAV6 X-Received: by 2002:a62:5ec3:: with SMTP id s186-v6mr19206217pfb.129.1532462141441; Tue, 24 Jul 2018 12:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532462141; cv=none; d=google.com; s=arc-20160816; b=Hy5qsTK07flte2Y46ZOmIjl5thIY2Se9VYsj4PdFKr2szKXvS/YDfR5e2vGUmeXPc1 oqD3eNltYUEFjntpo8k3aJqQ5fAoSTxoMOUzI5WYHWPYOPcsW5r4qJ4V2O4zcYO2XLik Qd9AHE8BoMdjhPfrxmeh3nOPZXVNZ6sjdP4zVr/5qdtrGqWF/c3gk1Qpx8OUDyppEyqA YIbX3JP8vf7gswg0PFXUn5wRNbSiWtEvPeEhzso6bgS1SIU2ZGGe0CuFEaz7BlOOvWoe pMCdI2HZYw9VEXHCvszD2yAkOsKBI8dqxEsZxf9lhmN6IphQCLC69KAzeLRPIYdRYjS8 P/Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=oNjFS0dcLSG7SsDaWI6O7p5t9gTOEPyQqyv9R3BGNds=; b=iavXRFcmo9EdzUssKY38Pblg85uISj+uZ0OLzGoG1LDtplpDfYD1quD5Lscf8kgha8 1KhRnJ+pHB7LgdDlT1jR9DQSVBycYHHn23BamkyBzLz4ydttW7IKgq6Dh4b/bhBWRFQJ qGtquSkmFJRU5oju0wti9EphnFub8ZPqfwkqKT2Ira9fJ//6ej015e0+2oEgc59ntmWR eNK98MxgN8e5NZOxN88Orpr2TVa9aBlU+zufUszi2EUIvo3DzMbAJ0ZN6dnmYXpEerEx ty0kJKsYZcOOOwhv2MWByXYBFvgR4g6qCYdu0kxKcrV8Pu/1/Rj8r3NrFb6fws1zhrId KvvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd3-v6si10820456plb.171.2018.07.24.12.55.26; Tue, 24 Jul 2018 12:55:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388736AbeGXVCC (ORCPT + 99 others); Tue, 24 Jul 2018 17:02:02 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44167 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388572AbeGXVCC (ORCPT ); Tue, 24 Jul 2018 17:02:02 -0400 Received: by mail-qt0-f193.google.com with SMTP id b15-v6so5387233qtp.11 for ; Tue, 24 Jul 2018 12:54:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oNjFS0dcLSG7SsDaWI6O7p5t9gTOEPyQqyv9R3BGNds=; b=KBZOr9qwPvNNebEtWUJOi9qNK+as01QOCfeapvP2LPQGsLenrFYQcGeRoaCeDa5phU WOUKVxbFyVOumgYHNNMfFKzqSU+QJMqOJA82zcuJjw2aKDp/ELcnfRokUzAZqXFIdjLA NpagfkI+E1HctBLLcrifyV2xaGusht8deKmdKnwlsC0O1avfCXMnwt6v1gpy+Av/pXtA frTekJVvuSiTRua3yC7s1AQeFSAK+4lO8eCiSfzNJvbqrOQBhpGzyLroqaGE27RNznpz aEb9+8udD+PZlNUU2pi+wImJ38Lh1+V1g8Cgt2ZZJJMUA8a50k31mEDs2/YxHBmlMnDJ 3bfQ== X-Gm-Message-State: AOUpUlHn2eoKAXFT3Tdd2vNOcYbwHXcShZqRSO7vzsQNk5aQThnBzbA8 iFTlc5EhodS3M3OzkbrFIPXN+A== X-Received: by 2002:ac8:21d2:: with SMTP id 18-v6mr18242818qtz.70.1532462039655; Tue, 24 Jul 2018 12:53:59 -0700 (PDT) Received: from laptop.jcline.org.com (nat-pool-rdu-t.redhat.com. [66.187.233.202]) by smtp.gmail.com with ESMTPSA id d12-v6sm8007755qtp.6.2018.07.24.12.53.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 12:53:58 -0700 (PDT) From: Jeremy Cline To: Alexei Starovoitov , Daniel Borkmann , Shuah Khan Cc: Lawrence Brakmo , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Jeremy Cline Subject: [PATCH v2] bpf: Add Python 3 support to selftests scripts for bpf Date: Tue, 24 Jul 2018 15:53:34 -0400 Message-Id: <20180724195334.13965-1-jcline@redhat.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes since v1: - Drop Python 2 support tools/testing/selftests/bpf/tcp_client.py | 12 ++++++------ tools/testing/selftests/bpf/tcp_server.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 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 @@ -#!/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 @@ -39,10 +39,10 @@ try: except socket.error as e: sys.exit(1) -buf = '' +buf = b'' n = 0 while n < 1000: - buf += '+' + buf += b'+' n += 1 sock.settimeout(1); 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) -- 2.17.1