Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3290942imm; Fri, 20 Jul 2018 13:46:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdcuKmKU4HlAk8n791EJR2X+rtEb2ZnWOtb2B+9QjdcXs4lHSg44CR5Ri8FM+6zE8MY7dEN X-Received: by 2002:a63:e318:: with SMTP id f24-v6mr3289836pgh.175.1532119595131; Fri, 20 Jul 2018 13:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532119595; cv=none; d=google.com; s=arc-20160816; b=MvLX37htVQJddCGcmWpUlrCHU+L2A+4W/EZ9De2akbQd4CLltv+ArrCkZSG60tTFM5 8BJoesUOfByJdoHY1s9xtRBweAjfK9RZ4iRB4rlRuK65bWyiEIC3ZYHifmfab0JDB+us vuaRZTaLuGCig07uOPY+I6KMRrsxeaN3LXtUV3sTWsLP670nAXvCHTGzGQBJl9NfeMpY XrUNCH4yYM+FvJHSSyFZuLUk5CCe2ySUXFReemHTtq6VHFIX3J/bxctW4cvOjvA9fVrE 90b+9teqQpprw9F8J819rnW9T4PruBGI6+6GXc4usxJlxjq+Ge5T4Av7lBai6WRqwZgd Zleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=7Horm3gZRfHxxxVMAPrYQpykh5TP3YNqkuevOsGYzq0=; b=HscbbLClTviUl4Zw8FD1E1mVf9+DFZz+fOPn7ulMfNojEadTiXSTNN31ICt3XIgj+/ 8lRK96ecmO5T+uxAfkkcb7Nsiw+phHoCq2sfHDUALyAMu9qtSkBjTUPjqWSCQgrU/NpU Hyg+RHNe2rtD3F2mBWfWMXmEItabMiy37XlsNtLtgGGyjJ6dxhemPe3dqdeG5So2y5nm MnUl4u9/TX7GjCmKx3OdewSiws19RNmzNoxkBviDUjqt9tKxnUZy8+gL5KmK0Y0TPkO5 nCKg0sn0QUujf0PmH6YCE3Ndm+h65FQO/0iCjyr8ITYCGb14X+8EK8qaug2BblfJBQGS pWbA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28-v6si2602341pgk.111.2018.07.20.13.46.20; Fri, 20 Jul 2018 13:46:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729313AbeGTVfj (ORCPT + 99 others); Fri, 20 Jul 2018 17:35:39 -0400 Received: from www62.your-server.de ([213.133.104.62]:57850 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728088AbeGTVfj (ORCPT ); Fri, 20 Jul 2018 17:35:39 -0400 Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1fgcHP-00032b-ER; Fri, 20 Jul 2018 22:45:35 +0200 Received: from [62.203.87.61] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1fgcHP-0004pa-7e; Fri, 20 Jul 2018 22:45:35 +0200 Subject: Re: [PATCH] bpf: Add Python 3 support to selftests scripts for bpf To: Jeremy Cline , Alexei Starovoitov , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Lawrence Brakmo , jakub.kicinski@netronome.com References: <20180718213610.19618-1-jcline@redhat.com> From: Daniel Borkmann Message-ID: <1aa3dc98-2ab1-7386-d5d9-afd3dbb3fde9@iogearbox.net> Date: Fri, 20 Jul 2018 22:45:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20180718213610.19618-1-jcline@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.0/24767/Fri Jul 20 18:41:48 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/18/2018 11:36 PM, Jeremy Cline wrote: > 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 > support Python 2.6 through Python 3.7. > > Signed-off-by: Jeremy Cline Thanks for the patch, Jeremy! Given we also have test_offload.py in BPF kselftests and it is written for python 3 only, it would probably make sense to adapt the tcp_{client,server}.py towards python 3 as well, so we wouldn't need to keep extra compat for 2 and have a consistent version dependency. Lawrence / Jeremy, any objections? > tools/testing/selftests/bpf/tcp_client.py | 12 ++++++------ > tools/testing/selftests/bpf/tcp_server.py | 17 +++++++++-------- > 2 files changed, 15 insertions(+), 14 deletions(-) > > diff --git a/tools/testing/selftests/bpf/tcp_client.py b/tools/testing/selftests/bpf/tcp_client.py > index 481dccdf140c..9fe5f1b5c020 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 python > # > # 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..1d4a40a6584b 100755 > --- a/tools/testing/selftests/bpf/tcp_server.py > +++ b/tools/testing/selftests/bpf/tcp_server.py > @@ -1,7 +1,8 @@ > -#!/usr/bin/env python2 > +#!/usr/bin/env python > # > # SPDX-License-Identifier: GPL-2.0 > # > +from __future__ import print_function > > import sys, os, os.path, getopt > import socket, time > @@ -9,11 +10,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 +23,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 +44,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 +52,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 +80,5 @@ while True: > serverSocket.close() > sys.exit(0) > else: > - print 'Select timeout!' > + print('Select timeout!') > sys.exit(1) >