From patchwork Tue Jul 24 19:53:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Cline X-Patchwork-Id: 10543161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89BE21805 for ; Tue, 24 Jul 2018 19:54:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78D62292E4 for ; Tue, 24 Jul 2018 19:54:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CBC3292F3; Tue, 24 Jul 2018 19:54:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 070B3292E4 for ; Tue, 24 Jul 2018 19:54:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388604AbeGXVCC (ORCPT ); Tue, 24 Jul 2018 17:02:02 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:45476 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388552AbeGXVCC (ORCPT ); Tue, 24 Jul 2018 17:02:02 -0400 Received: by mail-qt0-f194.google.com with SMTP id y5-v6so5385251qti.12 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=VD4hsYJPP7f2o9AamkWVPsELINeVu28xb4VCvjsXBozbPKgdZV1mRbzlvWK9IG9Ray zBci2PgWkqGabVI6ghX9bztH9f2mYTeDswJh5VXNzQNwvF1QHsJzZzYHOfHjjS6nx5TW 8JDqHauCJ/aCzaYBsy8C8jZv2khLWfgQQBj3b7Ei4QrP5X2ShfDi0J7rMZDC+QHwF8x5 +zrXTRS//25lCOd+E5l10vuI2C5EXmv3qHJl2tXhzl6NPUs0fYlz7kYedoqvjTX5A1rj 8/h32AUja20m6khhIs1Mavm9H7b9s5qXkx00rlhcOszXwnDu3DLaJiCkE8ffsUeb2ma+ mAWg== X-Gm-Message-State: AOUpUlHcX2tlW9E8yMQBEh1MNQI4xY/Ra+EuP3d6X56GmoKfmutsjhNa lPSce4kvHYt4PlihuBKN7wMmGw== X-Google-Smtp-Source: AAOMgpepz8WQcgqTx0P2U7oOMwt9sFBsV/JMSfup80T9jL6hRW55JplFmyJRJl9GUrX4I1Kj7g3kFQ== 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-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)