Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5852154imm; Mon, 23 Jul 2018 07:11:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdtwsMQuckBz7hzx/42GV6ddpPso0XgCTIAqTgj70rc1f/EugoFeU0jxBhIp+SDklhqgCX7 X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr13459250pfc.243.1532355083456; Mon, 23 Jul 2018 07:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532355083; cv=none; d=google.com; s=arc-20160816; b=SgJo8JxvLvLBQv+X2wAMvol7+3tvr/i6BFy1yrIHzUVVVCuVnL74+DzBN330Crp4kU Fg3k0U9pQSAOKdIGFYxrfdSoY3YQUECMpNuim9fBrguy2HEulC4wpx375d36G5XWRaSs 6uNPNOPBgGUSignBBpsZ/4gNQAQvxADn5EHXN/9cBETMrI9lignOLT2V1aM4nZrrGts8 PZaZxI7GPriXqP2fs0TnGvz+5/DIm+cldcUz8dDc4mLKtyrjqiHj0NqYP9oF5DG8VsV1 SvO4x8AW8ZwHnhBfXepi4m95qPzTxBGV0ZFeLN6WUqlNMO7NPJxv4C1Y94X13bwXnDxS a9Sg== 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:autocrypt:openpgp:references:cc:to:subject:from :arc-authentication-results; bh=jyv3pRG0wLPCfur1zW4AZCWIV2KY6pbU6E3QDzgVkXQ=; b=ibz9KCOaFFo1hl58M5jbPF1zwdMPnJI6P4W2VqNA15C5mo9Lr1XHjbjGm7l1IrT3FH lrc4c6Ks9idwSDr5YmUcWiPMQVk87q1wDo/uMQTsbBZNBkb3zA9qDaaP7A9Wk+rNg7DN q7XBFkj+NZoRcDb4tDf+xvzQcy0WOdptmVc5xyc5qHG44X2RAc389SsZ7Hm4ddB+SCbG BNWYrIEJ/VKpCqhVWNQBKXI2UL4zupyy1tqAKg6EZciYe1mE+GuVHnvHt51BkfjoQjLG g26Fc/y0KTvI7BmBv35rZA7uxklKjxFGBesFQUH3K31W9z131J254NCaSCwelCQxOjXZ RPNQ== 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 l26-v6si8749762pfj.188.2018.07.23.07.11.08; Mon, 23 Jul 2018 07:11:23 -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 S2388280AbeGWPKZ (ORCPT + 99 others); Mon, 23 Jul 2018 11:10:25 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:40287 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388172AbeGWPKZ (ORCPT ); Mon, 23 Jul 2018 11:10:25 -0400 Received: by mail-qk0-f195.google.com with SMTP id c126-v6so467645qkd.7 for ; Mon, 23 Jul 2018 07:08:59 -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:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=jyv3pRG0wLPCfur1zW4AZCWIV2KY6pbU6E3QDzgVkXQ=; b=G84X3bufFPXoU1crXYWwjVqBJHN5ttLeen53khNbLxyE3dxa2OvBfKeJc7X45zD22h 3mchCnHNAoYwRerZgEvi+LAOfbSr4MXM7KwLd/Qy5vG1Cw+8+B253C2M3KgXw9AjwVvM ydiSjYt8q93q/LO5nDomOAbFY9Nmb/wYddneCtDF9BxsrMut/7fFBbmgo13Ds/rRpISx jrQgW/7yJNQSA/SoNh+4eiuimKT3v8Xcv0vks6xG5TNdRC3E1lv3z9103nVofnNZ2Y6Q 0CCVRTBPFoDxWx86Uf/gJpDccIl47Jo7Aw06klJfqoWdKXK96VgEuQQ+8WKiHnMb4ZBO T8tQ== X-Gm-Message-State: AOUpUlGEmAYm6KpmqmnEm8eJdkeWDde/7Bcf2JML15v+5b+4/BNJTqQl 88+4veOq2NTWPfMqLoXbC8OMkA== X-Received: by 2002:a37:254a:: with SMTP id x71-v6mr11756696qkg.350.1532354939271; Mon, 23 Jul 2018 07:08:59 -0700 (PDT) Received: from laptop.jcline.org (nat-pool-rdu-t.redhat.com. [66.187.233.202]) by smtp.gmail.com with ESMTPSA id d202-v6sm5580151qkb.38.2018.07.23.07.08.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 07:08:58 -0700 (PDT) From: Jeremy Cline Subject: [PATCH] bpf: Add Python 3 support to selftests scripts for bpf To: Daniel Borkmann , 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> <1aa3dc98-2ab1-7386-d5d9-afd3dbb3fde9@iogearbox.net> Openpgp: preference=signencrypt Autocrypt: addr=jcline@redhat.com; keydata= xsFNBFThCPYBEACx9hl05pMfpVKVjm8Yrmd2I3sm9Jw7EIGfn1tmncSnzfveN7UcIjYI23Gw DE11Hf70tMZKXhNmQqDqoftEDwLbTuzBdgJXFZmfEwrcQHGiR5CZ4IQ3U7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pjwVDHi2i2kFSsl88+DThQlJrCGmIwYB6KqvHHNoCotd8Dvb fA8AEQEAAcLBXwQYAQIACQUCVOEI9gIbDAAKCRDGyJ0h8ZTGQi1bD/wMbSCnreanQFYTTgzC 6i/dtsWrd3DvJzaxKdUrSjioP1tK6YLpS7SSc5khYUjVp7xdsu9vCazsLspzBYbQOV02xtI5 CTLwMzh4hYE1/66K899++0v2dP9m9DEKu/R4vqW4axTfWIbR/ygd1bh2a/7NpAT6qiJg8vha Qkf/fVKZ9xM7EDHmfFJscqC6JyYNdYvz8wJ0aa9Z6zvnNUzjAntj62kJV8b8m5diUQDUI8dp r9crk+XxOTNpYid6p8mlNTcX54LTy1eEL7BYG1S3ezcLZC9/78MTdTJbxQMz7/zQXOABfMDy +otLuhEBxi5hl+COIsiRotTOBNPNr1UmV4fQjXz2K6cfgaO/9NilQaEU6zpsMcAOi5lLxlzD GRyPO2a0QQFZ7FmH9dRWw/6mmspQMBNRr5CrQdIBiWDcJGNPl8iX9TqwP62dZgwANT6+FR7K If4axm/gJQMSUCon3eLJhi8b5qZp4vZn7Xj4hCswrO9eExmT9IjpRVcHLYti36m99WRvItDy dVvrvIQi5qah3PrQjtwSJ61ExSZTOpBQGC60yQf+GG0TISIeeXX8CK2e1PIDt7/l+d0onCmU /98IQsNgR/9sifmdPeh3nKsxe2vsa3HNeElQU2ko6ZHMrE0gSyel5vaqRLQQwekBx1mr/7Ll X/87hZ4pdW/aOXUAgQ== Message-ID: Date: Mon, 23 Jul 2018 10:08:57 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1aa3dc98-2ab1-7386-d5d9-afd3dbb3fde9@iogearbox.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > >> 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) >> >