Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6053655imm; Mon, 23 Jul 2018 10:34:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdXB4ICj2Iy6bLTTXJDoq/k4XaHAGukBYnxP3JryQ8bera9xXSoCnZ9lQoG1vDJcfcsgjmT X-Received: by 2002:a17:902:aa4b:: with SMTP id c11-v6mr1706863plr.344.1532367258049; Mon, 23 Jul 2018 10:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532367258; cv=none; d=google.com; s=arc-20160816; b=xfgEAMChTseKxXK6Mjzx309MWoHN4j7pkX8L9ICaSAvbSHJffBIIDC5I2Aujh/i5tv 3jdHCxs2VVsr5+63sco+jZOU8C1SycQHSZwpDY2GxSvJ1sK/N3A1lFFXLMleo+9M+cRa mv6RTB30TyZ/zzvY9fYvXLIR1LpMiPET47iIpCTVfNNnjHrmtUzkKoJvYVWBdskgHHdh ygsesd58Mwgm/sPd7t9Ivw0KPEq+fZcp5txq3IGn2roJM90Q21MvLdW1P7tpJ+NX1one WIjLGP/c21b1Tm/6VZ2C5bgurl6mFzkjNlZyKfa2dehL0TJx02q/JETnejrrSwQcLU2h JU9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=EzDRXJ95/mKl0U1X6L7KLiCwN7QB1YpPa1jwi5eCWjQ=; b=t1ni4l7dly+adsuRjfrONftpBGz8URF9BO+4/L7NVO98r9OSvxskpZzRPuUUasWoxo yqsjKmj1lmIqkBxCetpc/Ln5S8FhkLfnfa+pvoji/A8xe0reuXyIqD1xtewMM6UMZmuU Ghomr5fr+pKgNtchxIxITztPweEUeJt9by1g6pV6Lb1YlPh9apc/nflu9T/lj22+zB9I HJT+6htCgmMEj0yC49iXEYU3Iy+RpXE6SwsPs0K/WK8gAn+FJyYg4pX1JrtKe3r7EgJn cotH5QuXgMY4B4IlAfpRbXMXkFXxZ5BMeReWrR0WGjZME3OabUsURr/IaLjxxKfy2lTS LIoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jZL08M6t; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21-v6si9548260pgb.131.2018.07.23.10.34.03; Mon, 23 Jul 2018 10:34:18 -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; dkim=pass header.i=@linaro.org header.s=google header.b=jZL08M6t; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388227AbeGWSfc (ORCPT + 99 others); Mon, 23 Jul 2018 14:35:32 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:44985 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388002AbeGWSfc (ORCPT ); Mon, 23 Jul 2018 14:35:32 -0400 Received: by mail-oi0-f66.google.com with SMTP id s198-v6so2562819oih.11 for ; Mon, 23 Jul 2018 10:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EzDRXJ95/mKl0U1X6L7KLiCwN7QB1YpPa1jwi5eCWjQ=; b=jZL08M6tFlDQSpQqmRRc7k2yazBd8701TsIdDcz9O5V0XbDmO3G6hKe1UQM0TqPybr Yn8nd+TvJZzOCaIfWsd3PzKPuYRdQtLIjElne3q0KIqNR/bUOWwPol1Jd8vniQM/k/mc UNigmIURTlF/b9QPtHuJaOqEhDyUghuMFuTqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EzDRXJ95/mKl0U1X6L7KLiCwN7QB1YpPa1jwi5eCWjQ=; b=FwSmeZwo0ESFzTSQhYoJ6fzS89L7MC9w2ImwW0ZvPW0nouO7ydmQBbrspr0CZZK0Ht 9q9y0qxM/x3K3U6zc79vs/rvBc4UWNgJePvg34sDjJ/8CYcu1b4+hJbIl8Dfu/Z1L2g6 iyN7x+69fH5Y/XYQFSTBGltuhvOnfxChiryUXb3W776t09z5GNLt+xY58d7Jw7JIzSSI 1EjpOPdPdl66EWEJyFZFBjW+cx8Qw+5/inXcQ8BN0HRczd+NlbX94fR7BXYBOy0IaICn jLhhdt3QJEP325fttA5Iq2J1c9DCO7/mDmNGvJl8qU1IYHjr12/mbaAqMh2p9DePaKay e/4w== X-Gm-Message-State: AOUpUlEEoBX3z6dsvQkqJyWUtCfXvNrE03fKBIh7EN+eHLsUHBx/O50E Rt4vKAgd4MQcoYqKTjtQy7N+cA== X-Received: by 2002:aca:da88:: with SMTP id r130-v6mr9645698oig.163.1532367195228; Mon, 23 Jul 2018 10:33:15 -0700 (PDT) Received: from localhost ([2600:3c00::f03c:91ff:fefc:c793]) by smtp.gmail.com with ESMTPSA id m62-v6sm25774933oik.30.2018.07.23.10.33.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 10:33:14 -0700 (PDT) Date: Mon, 23 Jul 2018 17:33:13 +0000 From: Dan Rue To: Jeremy Cline Cc: Daniel Borkmann , Alexei Starovoitov , Shuah Khan , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Lawrence Brakmo , jakub.kicinski@netronome.com Subject: Re: [PATCH] bpf: Add Python 3 support to selftests scripts for bpf Message-ID: <20180723173313.ri2uz7srtdtno2hl@linode.therub.org> References: <20180718213610.19618-1-jcline@redhat.com> <1aa3dc98-2ab1-7386-d5d9-afd3dbb3fde9@iogearbox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 23, 2018 at 10:08:57AM -0400, Jeremy Cline wrote: > Hi Daniel, > > On 07/20/2018 04:45 PM, Daniel Borkmann wrote: > > 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? > > I certainly don't object to Python 3 only and I'm happy to drop the > Python 2 compatibility from this patch if that's okay. This (well, along with introducing python in the first place, which took me by surprise), sounds like a policy decision that should be made clear in the kselftest documentation (Documentation/dev-tools/kselftest.rst). Currently, that file does not mention any python requirement. That said, I agree that python2 support is no longer necessary. My use-case (which may be unusual?): We try to run all of kselftest against a variety of kernels and architectures for every push to next, mainline, and stable/lts branches. It seems that this is not a common usecase, but shouldn't it be? Dan > > > > >> 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) > >> > > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html