From nobody Wed Oct 8 04:06:44 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AE6326656D; Wed, 2 Jul 2025 11:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455273; cv=none; b=si6Zq76ONo4K07DA+qc1kPSqCGb9m5D3jPyMnvBhsO8Mu5U6/u5sRk7gxpzvikW0eW5XXT5vY+Wd70K5F+tTsI6KXP2gESd69KZ8oZfOYdEtHkDcF7Hd92p4zaqa1LyfEXAU6F5Aepl2nvBQvwEjGfLCrZsN+EID2ecckGW6jn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455273; c=relaxed/simple; bh=kmhreOsqeuqBCdj6XPPUE3ZSy4x+7B5KtJ0GKNZmy+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S99t5vHupaQSFcPoWvDVsmHrAHTW0LY0+ljAe90gxip3CE9Y4NSXebe0bPwZPC47fSTb8o6QgFULMrTs9c9pRncpcMeZE2hCssT7B4ugbxHPCKd5T4LxGfKHC7oCxq53DUgP6rBW6YH3QG6mQJdL/jcq0YrIxRa9b2tRvilpVSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-60c01f70092so11102875a12.3; Wed, 02 Jul 2025 04:21:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751455269; x=1752060069; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=snLCftmRv45xZk+dYhFYTETXXx2kQ2Ytw2HV/igRrFU=; b=gmKDxtx232WL07A2xSu4AXrJf+PeYpcVT5h7wGOf8wTSgCJrdj61CsuS+ysdhJGuO2 vZMoQ1xFQSMZASDu2SondAEPn4TCDH3p1S7fKcTq1BNre/hAv90O3L/fy3pyb2DjoQ6w T6j+Q157AnfR4RCsgrgko+FVyqZmbfB77SQvWre6Qey0MlCHNY6oHv7b7qpL9/a8n3bd 7twAvUHtsUw1xAORiFyTJfm2jcZHNxL0YDJjo8TbuDoAKgh7n11WOWkreS4ln/bK9V/5 4ID0zAlT2SMk+LoWbOPlUcmhCAzTDk5YIxJmqq8xVTR9wheUid6mCvAx+X4y/pHcVexb k2xw== X-Forwarded-Encrypted: i=1; AJvYcCV5w4y+ElkdJ4KhPqViqG2ExrQEbBMLHpYmy09B/lB9gyf87takuoZ/uwJgEgp15fW6XU5Glyg21SRIHtuDtEh3@vger.kernel.org, AJvYcCVxlm5Ur0ADr6OYAvCYxh7dHl+BssHSOVYVmExInfFUzi6PSqLNeIt9Y3NE1eX6QPiZnbz6UQGc@vger.kernel.org, AJvYcCWDiw4knyQ2sxqTLPSDpKP6rOvGP4G9YZwu9rqn3yhEdWc6vWmXyYezu2fUaeAKFFYxsKw=@vger.kernel.org X-Gm-Message-State: AOJu0YwdD4Tg7Mq29cfXQu1MfIK0AQ6RkUFX6Ry/gdLAqpz28RturSX3 xQVe57jp+gbyeqBTWmlDYkowcO4LHoNHJML/0h9njO0yqqOUN1058Ccu X-Gm-Gg: ASbGncto1kQEytjq2R648dMgiYDwKV9gqUhUm/yRg7o0/78xX3rbcB7+vsPitmLl30c fJWE6vT9ZvlL2L70faoMKC88lzVMm5icaCvITDQ0V1uoFe6aiMf6aVWLy+Gr7Df4eus34uGbwsl MhcD/YCKKqqLtckAKg0gwyNm+wzZXmYxDLh6rxU7uwU7F+mM1EQC6Z9M4mHeNJcx6DTaVbmmlnl gqrMyxdW/zlC+mIfB8q2lPN4l2SP+Hh2cU3WFm0LlK9cIDz9ZkRSaNlw1AmapSdXjlGJXkbnUau qMv9R1U/nQ51mp5RwFI8zwhttlBk63aR60RsvI1kKtaHTbDzM1SDhA== X-Google-Smtp-Source: AGHT+IHSXVJ+zv8OK3ZIb6xoLC+yCdDOg+t6pGtX89QkSDHD9cmdKEk7CjPhmivk4Ehy2d+SJpCUaw== X-Received: by 2002:a05:6402:2755:b0:606:c48c:fb8e with SMTP id 4fb4d7f45d1cf-60e52cd2cf9mr2278833a12.11.1751455269238; Wed, 02 Jul 2025 04:21:09 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:73::]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60c831ad416sm8825448a12.39.2025.07.02.04.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 04:21:08 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 04:21:00 -0700 Subject: [PATCH net-next v4 1/3] selftests: drv-net: add helper/wrapper for bpftrace Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_test-v4-1-cec227e85639@debian.org> References: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> In-Reply-To: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Willem de Bruijn , bpf@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=3156; i=leitao@debian.org; h=from:subject:message-id; bh=WGfCbot+9pyl//CXCduVntkS6/EWBvdoFOZZ//nP+P8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZRYiV8zzTzkaKwX1zLm2LU8xus3S4e/Plrqpp VW1o9oHcH6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUWIgAKCRA1o5Of/Hh3 bbSYD/4oo99IbSaIg8X8K7EkchnmepT5VL9YdQKqL6vHq3TWkkPLW9Ber2TH659Oj9Sj44kGWxa GAYlE5U7Pe+lEaDbo5Iw1uYFpCYv03dzPQ+fB6oR3bpbyv1hau3+mNNBrrP2jknOxfnxbI5odwu czHJV83HLOnz2iRUPt4Y9gk4pOYxo34QxV7uPc07aVyXQmTf3KbTUlfjaFyPlecpVrxDvSVHBoO Mx8Ier9eNxyCOQ6ZGVsRHO0t2fwRUXjdvh3XmEy28jRa1hN7GqFJmDzimBcfIFl6JVj5Jb+rC/B nO4lJbdX6KtXCZIGIIAxXnRCwPk0aDFCrFr/3vVLT96Pf8mwFTbDf+g1mLhcoJKxua3HOV2RJp5 L7iq+uc+O0L0o5NWdlNGTq9jvdUREBH7jDGtswOBiY+XcjHVbNyWvicAEHCQKzd1C6AxtiD5wdD pDhq+mZhIJhWbutVOB7T3nbP8Qhq7y6pfWhy8e4TI9NdcB3O0ZVuV58mVJcAwDufMgIKA1K5JDP Tgf3hS9pmlZNfrF3atfEh/j3vqHasKgSI03tYIe1DFkK+tjaACW36sf9P7cxNxk85oF675x4YRx fTK7Qj26nlPdFciZR4Z5Lhyavds6w8i2cElOq8+YhHTC6OSB2gk849slvnFTtaWC0T3BRA1cNAF XxcuvSfeaDzkIZA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D From: Jakub Kicinski bpftrace is very useful for low level driver testing. perf or trace-cmd would also do for collecting data from tracepoints, but they require much more post-processing. Add a wrapper for running bpftrace and sanitizing its output. bpftrace has JSON output, which is great, but it prints loose objects and in a slightly inconvenient format. We have to read the objects line by line, and while at it return them indexed by the map name. Signed-off-by: Jakub Kicinski Reviewed-by: Breno Leitao Signed-off-by: Breno Leitao --- .../selftests/drivers/net/lib/py/__init__.py | 3 +- tools/testing/selftests/net/lib/py/utils.py | 33 ++++++++++++++++++= ++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools= /testing/selftests/drivers/net/lib/py/__init__.py index 9ed1d8f70524a..98829a0f7a02c 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -14,7 +14,8 @@ try: from net.lib.py import EthtoolFamily, NetdevFamily, NetshaperFamily, \ NlError, RtnlFamily from net.lib.py import CmdExitFailure - from net.lib.py import bkg, cmd, defer, ethtool, fd_read_timeout, ip, \ + from net.lib.py import bkg, cmd, bpftrace, defer, ethtool, \ + fd_read_timeout, ip, \ rand_port, tool, wait_port_listen from net.lib.py import fd_read_timeout from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/se= lftests/net/lib/py/utils.py index 34470d65d871a..760ccf6fccccc 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -185,6 +185,39 @@ def ethtool(args, json=3DNone, ns=3DNone, host=3DNone): return tool('ethtool', args, json=3Djson, ns=3Dns, host=3Dhost) =20 =20 +def bpftrace(expr, json=3DNone, ns=3DNone, host=3DNone, timeout=3DNone): + """ + Run bpftrace and return map data (if json=3DTrue). + The output of bpftrace is inconvenient, so the helper converts + to a dict indexed by map name, e.g.: + { + "@": { ... }, + "@map2": { ... }, + } + """ + cmd_arr =3D ['bpftrace'] + # Throw in --quiet if json, otherwise the output has two objects + if json: + cmd_arr +=3D ['-f', 'json', '-q'] + if timeout: + expr +=3D ' interval:s:' + str(timeout) + ' { exit(); }' + cmd_arr +=3D ['-e', expr] + cmd_obj =3D cmd(cmd_arr, ns=3Dns, host=3Dhost, shell=3DFalse) + if json: + # bpftrace prints objects as lines + ret =3D {} + for l in cmd_obj.stdout.split('\n'): + if not l.strip(): + continue + one =3D _json.loads(l) + if one.get('type') !=3D 'map': + continue + for k, v in one["data"].items(): + ret[k] =3D v + return ret + return cmd_obj + + def rand_port(type=3Dsocket.SOCK_STREAM): """ Get a random unprivileged port. --=20 2.47.1 From nobody Wed Oct 8 04:06:44 2025 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4E79267AEC; Wed, 2 Jul 2025 11:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455274; cv=none; b=REv61tdYF296TMrvtWEl/n6uLEhMh4Mj7+D3vFg6NQbqG7rYytKdnv0nwkWQ5RQDII+HvUAI3IFwSBvwID1z3bfUp5HuXEJNeuZgPKpMUR6D4MTzD49gpmlxGQkkk+Vg9Cn4+F6q/mznNwHdTYtvMNk8vbR2v/u7ETmdOj3lsm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455274; c=relaxed/simple; bh=5e7Gu2hSYoF78NHOOQ4u3fblm9IpAmXxrCi48b0pb34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JYv5mWLoGIIktjJpnyHvrhlTc2h0Ia+PepTkrez5fIEfjbviaq2LjoFpR3OyK2mP5KqN//oTn5KCWSbOP+xWrdpMTOoVKwNX7cALcTuSRSQTZaU++nRZ8v8xEBa3OpoRkLP3hScC/X1yF0ApnhlqycU4KuZxYAJZIzUayWtWdWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ae3cd8fdd77so24061866b.1; Wed, 02 Jul 2025 04:21:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751455271; x=1752060071; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gaqp+BTPfvuWnqLQlzPe4IbE5DQFSHBJTK+OlPf0tvE=; b=mFTDY+YdXk8zopoBSkOqY+Icgzsa2cwq2l9HwH5ZD6q547tTgmhN8OyP22mMKQr+cZ JJiJ5lnMKu3ILlHR35CguBw4JqMGHHobT/pfFa/RQs9r6VOCLkYxv6JEkxNjmYFKnbaN RM1eIzCCGWn30qXmkYH94/ZeRS0IJOB1Hi3fcG9oO+H48SrIqOLDJfjhkw9VBERWha9s CovvbT/ga+Q69zWJi2CA6Wgglz5uE6fIBVSzvGijIQ/oQnUx1OGuG5alvYDIeJtcKnK8 HITzpaGQjuasGmW3uHMejGTsfD7Rrey/hEjQqOZx0FEtM4ct9pJ4xR5Fbwvcds0tb5j4 MDbA== X-Forwarded-Encrypted: i=1; AJvYcCV2XOwJGKUQ5Asc/9qaKivRf5fqM6+G30xJY6S8jBdgxWF+ne+pc+4UForZ49gALvyT4hM=@vger.kernel.org, AJvYcCVtDl2rT9m1Ota7P6j4BVWrJwfIfqO8ETdPMBXgf5N9Arkwt9VUAYftWxvgZcMPF0+CXdnsVgnPC/pzrjwCMDY0@vger.kernel.org, AJvYcCX0grO8AekaqTZzdR608aB4Zwo7s3hNlqDzP8lYHWBUdR3d0VkcYGnrO7rSBv5kgnybidaoUN/D@vger.kernel.org X-Gm-Message-State: AOJu0Yyhm8ZANK3ue+LEwG/x8zkNPTyCc7295H/jIY8lbx22FK408enl cR1sPbOmy62RGSg10efBH3C8kJGOwo/NNYeSpdE25Ovpiuzga1ODkbxX X-Gm-Gg: ASbGncvJ+70C11+pR9jFIlEikxnATUidv15zwQJCXetndxdcZyi/SpVG3k398e73/zg spsiZmBpPutr7rzpD1h/CDvL+qSW682Kb0LXV4279EQCD7aNLIjdvfXeTxVkhzjVKkfsoPEgQMI 7mo3wQgiljzU6rTh9LGDxy4CGRP5QbHGxtmcjNui+xQVv+1GcEsBxRaLQNjDex+US2vVCNuleVZ H4lAAL5OvL4yoV8NlDTRTEgjzNESYCQeiV39wY0RGSjPyx/dn2XkNsIcm8W0bsCiaDmNHqa+gXK 50nRHdXJGFX3B6t9qtOu3Dj/UrjpaVKeG2t1PiiGlJ3j1etWBhPK X-Google-Smtp-Source: AGHT+IEDMdTX1CxQMkgRGRYE/ObcPbJRaUJjkn8KHQ8Bisj1r7G4rCh2u1YanIqxelOJpwlxdpeE6A== X-Received: by 2002:a17:907:3e8b:b0:ade:32fa:739e with SMTP id a640c23a62f3a-ae3c2a904e4mr238897866b.2.1751455270920; Wed, 02 Jul 2025 04:21:10 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:2::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae353ca1cb3sm1057800466b.157.2025.07.02.04.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 04:21:10 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 04:21:01 -0700 Subject: [PATCH net-next v4 2/3] selftests: drv-net: Strip '@' prefix from bpftrace map keys Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_test-v4-2-cec227e85639@debian.org> References: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> In-Reply-To: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Willem de Bruijn , bpf@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=1053; i=leitao@debian.org; h=from:subject:message-id; bh=5e7Gu2hSYoF78NHOOQ4u3fblm9IpAmXxrCi48b0pb34=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZRYiYTBEtC3JkZ9ocdPcMBXa6dXyLxUCB2y0K sLcAsA6DzOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUWIgAKCRA1o5Of/Hh3 beTND/90rxGg4w5ITQE4iXr8TojvxUfs73oXVK7rzP9kn+KibVoOikS2sqsB8Q4JcZK48UyFL8N 3dgfhbp3wAUloZHuOlF1zHQJRA+QJmOvpG+rk440yQZFbnag/g1xgH/lzAlnM4YAtF45vy5NWx3 xWktQrcZTtYm42H6n7LfJa+gw8sLJy+fLHVMXKsAcd3bx2GsftIKoKHXszdgNwuNDuomtXR6ZLA vD+Du4nefPtSvWZ6w/ohZ6rFYvfCA4RsKvr1zAinrx7nFmJpoLP1hy4mV2+2fVPG38Z+fwImuy/ Pw8T4uGKDXYEb+Ny6hgqKh9b1amGKsz9MkleaC7K85SqGzbkGkGW3zPUJJ+BecqubOitPv4GDaL 4msu2xoMEbITgeMyDYq221+ZJiqYU8k0oDLsTUTF85J9gKdxRs3iiHbUQRsyOObWeTXm4BStnw5 e7bck4YCQwh0U6kMx5tB1LCMX9mDII+nrWA0qC53RKAgBfPh2zdnhXbduXGX244bBkqe8qelVXp ndqTQPxHGbIOdayJxcFbXg+4G0fpuRUatn35zk/ZVCnPGh3ntEgIRHHOZcPslxRnq2H6F0yhWtB rIIJvllAUpwKWb2TtU7jyTTFNdmNqtzMg+vGWeBenBepgXJtQmqkjoG61ewlPObkDqzS/8Unr29 VhzhsGPYkamhpAg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D The '@' prefix in bpftrace map keys is specific to bpftrace and can be safely removed when processing results. This patch modifies the bpftrace utility to strip the '@' from map keys before storing them in the result dictionary, making the keys more consistent with Python conventions. Signed-off-by: Breno Leitao --- tools/testing/selftests/net/lib/py/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/se= lftests/net/lib/py/utils.py index 760ccf6fccccc..33c23a928ed1d 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -213,6 +213,8 @@ def bpftrace(expr, json=3DNone, ns=3DNone, host=3DNone,= timeout=3DNone): if one.get('type') !=3D 'map': continue for k, v in one["data"].items(): + if k.startswith('@'): + k =3D k.lstrip('@') ret[k] =3D v return ret return cmd_obj --=20 2.47.1 From nobody Wed Oct 8 04:06:44 2025 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D6F926C396; Wed, 2 Jul 2025 11:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455276; cv=none; b=CudInG7Ypbn78CrtQGVl7evpiLeC9DBxtIJfekDmgW2Zdk4QwILuFHh/o6afnOif6dbosWdSKfUFd7v2JMr89RbPOWjk3OzKTs7ASeSdubwIbwabfSggUrN7z+X2/27b48qA2KyHGWB7N1qQKvGsR2xMncCS4V+xvn3oTS6cUfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751455276; c=relaxed/simple; bh=FRTEkYEmygM5jZbsnSMtXO9a4WVPx+t+RymFB6zRxWc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YGHKjnCDZwCipzS1SEfZOjcb3DxBnTfiGxWuEH4F1hXDjBdmIotNhf0hSSD8i3ubB14v7VJNRURNzEj04/YUjJcexWBEy4Ozbu4eO4CD+Dh8Z/ITYX9Jsf26aSuIREOE5yGW8pE9cgeYHCPZNbcXwXV/H7qyQlWaXO/P0hxHiwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-acb5ec407b1so767773866b.1; Wed, 02 Jul 2025 04:21:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751455273; x=1752060073; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VyZYpgP+dO8O+GOplLj6ow/h6NOrDNtT4jFXzdZVmts=; b=Cc5GiMUexxfVL1Df+y0wXstyt5JYyLRpIi2vtpbnxqbryz6QvuWyeCN2rbgkLKBOSC bSemqs7Fl5qzzV3rKBygO0aSu2AWggYxg2mp1D/Zk99B51PEA8VHdXQ72XMIPVpYatUd e0x2vF7EB6wBCvOSpiReyCVQGgBF5vZzOS5cxS/gd4S680JRaSfD/NRCYrLQViXIaLPW Xb3MerIhbm4t7txhMnWSXVA4p0qM4PNXQFYKEtIGE08qX1gL2LaFglyyMdupb9SnGTmY ziinhQlLhjLc/4IgC56lOl+RkwdzSwRpA6l/haeZtPCCNzvLCwYnt/eJ3tk+9ufYVaKj xrjw== X-Forwarded-Encrypted: i=1; AJvYcCX2MmAz6Ar8qwpoUIiwYIZfsVqpFYKbaZ4aMFdeqSQ7DinNac7ZA89HwLMuDwow6DBB1sQ=@vger.kernel.org, AJvYcCX43ZZ/jwtpBEIomBkgqUBfHvsguqtHCguKCds6J08mInQImT9A7vjMxzR1J2l7oE/P83/dulor@vger.kernel.org, AJvYcCXtX4gb90QM/YMXo9NoucawNWSFO/YnOyi5WId/6JSPL4Mrku8MZlSe8mb3vcBmqF4WVd4QWVeqD+yioYJzj7oX@vger.kernel.org X-Gm-Message-State: AOJu0Yyjc3YU2y8a4QTwC9juOo+spFAlTT/XN+/Hm1cs/iUzriCZGM5N ltaxG2Gir3ZvNmS2aTdhqXWev6waKEmEm6QGXmn2HIBk5H0noioxvDB3 X-Gm-Gg: ASbGncu/jFlS2IQew6AK9VDI2/z95ZtUhcuBx/GMW9X3Qfexoxz2sHzdmiIqfOCEIk+ FtKB9L9ioj3HJDJKPbb+OFoMEeIvJXLg4g3oTZIm68f33fA5qN93moeP3jcenfm/gcB5hZxWV24 cmSqz0j7N5Pzy0pCYZs6Zc1usymo7NYmyqn5k8Qzq5FPWue9QdAr/u+gefw+nREdcDKC7dSAHYK dtNfYXL+Rj7ldoP0+lxxTZpOsuP2IEwG5jQGi7utL/V+ZmvILMUeG2Qzj4BK9BzhtWOUM7zcsyP csCHaGXOYZ6HHavuighAjEi8oVb0+DpzIzk+ECmqstshlNuEQGWn77j6gOndvEU= X-Google-Smtp-Source: AGHT+IFVvMNvJ8NxcQl3N5hgFKNwn6xPsKXcKewZRlcd1UR+aCHfmYDiRExaYuMfu6cxQzfO3Ba/5A== X-Received: by 2002:a17:906:6a09:b0:ae3:53b3:b67d with SMTP id a640c23a62f3a-ae3c2b51dfdmr250631966b.1.1751455272438; Wed, 02 Jul 2025 04:21:12 -0700 (PDT) Received: from localhost ([2a03:2880:30ff:3::]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35365a000sm1041355466b.41.2025.07.02.04.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 04:21:11 -0700 (PDT) From: Breno Leitao Date: Wed, 02 Jul 2025 04:21:02 -0700 Subject: [PATCH net-next v4 3/3] selftests: net: add netpoll basic functionality test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250702-netpoll_test-v4-3-cec227e85639@debian.org> References: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> In-Reply-To: <20250702-netpoll_test-v4-0-cec227e85639@debian.org> To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Willem de Bruijn , bpf@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.15-dev-dd21f X-Developer-Signature: v=1; a=openpgp-sha256; l=14972; i=leitao@debian.org; h=from:subject:message-id; bh=FRTEkYEmygM5jZbsnSMtXO9a4WVPx+t+RymFB6zRxWc=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBoZRYi5yE6XDvitg6SSSuZRpPcJs3MOHJgBySDd L81Xku8jguJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaGUWIgAKCRA1o5Of/Hh3 bZZeEACiyHoCTzJ+VoaUKTe11sAl+VFkeSo3vFFsJmHY22Tm8IGuAmrBTuNEoAJW5Te47MictmS K9xwkFwlrBd0auHUrrwdD5doHAoB++flRTJdkGCECJ+f3qffJTmA/wq7GJKVSnLSwrZhpvWrkZw 2Ke9xTZyABIKtl8NIupp5djhEBdW9NtITwFvXA7hTbH9ZfVkElXQgzDV2JNHR2AtLUTuIIep7tY XrwY+fD+9ZIjmMBKIpPVnJukxvrtoMX2kvtMw/z9MLpspF3vMLpgrSRFoN2lu0wDruJaVBM+GSK qpV0JBp7I6KIb4lSEv+MF5JLFowXIAJTd92s8R+pbDfy5GV2vX1XvgFHkxlxcmizTnUfrF51iHE 8s1l+MGc6gaXjhWmE2cP3Pd7HHLaZHxuqUeKNTmgBfV7bLDIOUoxvsC9hYvQERvNRsimjKy66SJ KaZFOk9AmJj47UVjE8WJl0MeBi5LbaPx0MnSozE0OmZDOcwbkTHwrsWdkuSK3MABhIUK/ljrJG6 piGYi+oh9W4ZdQfpPsgdHA75tLLJcKKm9fZDFXcgy404+IKb7b7vnF4/vBl/xEA2BrbygT2sOQD 3s2I8k7cvWXR7EATI9/EOnNcv17EjPtbkrh1LvlBcm4uvP3sscamiGwlhEIpsjmnIxQmNwqRrLc iO4wHoNq5iYFcCA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Add a basic selftest for the netpoll polling mechanism, specifically targeting the netpoll poll() side. The test creates a scenario where network transmission is running at maximum speed, and netpoll needs to poll the NIC. This is achieved by: 1. Configuring a single RX/TX queue to create contention 2. Generating background traffic to saturate the interface 3. Sending netconsole messages to trigger netpoll polling 4. Using dynamic netconsole targets via configfs 5. Delete and create new netconsole targets after some messages 6. Start a bpftrace in parallel to make sure netpoll_poll_dev() is called 7. If bpftrace exists and netpoll_poll_dev() was called, stop. The test validates a critical netpoll code path by monitoring traffic flow and ensuring netpoll_poll_dev() is called when the normal TX path is blocked. This addresses a gap in netpoll test coverage for a path that is tricky for the network stack. Signed-off-by: Breno Leitao Reviewed-by: Willem de Bruijn --- tools/testing/selftests/drivers/net/Makefile | 1 + .../testing/selftests/drivers/net/netpoll_basic.py | 365 +++++++++++++++++= ++++ 2 files changed, 366 insertions(+) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index bd309b2d39095..9bd84d6b542e5 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -16,6 +16,7 @@ TEST_PROGS :=3D \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ netcons_sysdata.sh \ + netpoll_basic.py \ ping.py \ queues.py \ stats.py \ diff --git a/tools/testing/selftests/drivers/net/netpoll_basic.py b/tools/t= esting/selftests/drivers/net/netpoll_basic.py new file mode 100755 index 0000000000000..398ac959151b3 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netpoll_basic.py @@ -0,0 +1,365 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# Author: Breno Leitao +""" + This test aims to evaluate the netpoll polling mechanism (as in + netpoll_poll_dev()). It presents a complex scenario where the network + attempts to send a packet but fails, prompting it to poll the NIC from wi= thin + the netpoll TX side. + + This has been a crucial path in netpoll that was previously untested. Jak= ub + suggested using a single RX/TX queue, pushing traffic to the NIC, and then + sending netpoll messages (via netconsole) to trigger the poll. + + In parallel, bpftrace is used to detect if netpoll_poll_dev() was called.= If + so, the test passes, otherwise it will be skipped. This test is very depe= ndent on + the driver and environment, given we are trying to trigger a tricky scena= rio. +""" + +import errno +import logging +import os +import random +import string +import threading +import time +from typing import Optional + +from lib.py import ( + bpftrace, + ip, + ethtool, + GenerateTraffic, + ksft_exit, + ksft_pr, + ksft_run, + KsftFailEx, + KsftSkipEx, + NetDrvEpEnv, + KsftXfailEx, +) + +# Configure logging +logging.basicConfig( + level=3Dlogging.INFO, + format=3D"%(asctime)s - %(levelname)s - %(message)s", +) + +NETCONSOLE_CONFIGFS_PATH: str =3D "/sys/kernel/config/netconsole" +NETCONS_REMOTE_PORT: int =3D 6666 +NETCONS_LOCAL_PORT: int =3D 1514 + +# Max number of netcons messages to send. Each iteration will setup +# netconsole and send MAX_WRITES messages +ITERATIONS: int =3D 20 +# Number of writes to /dev/kmsg per iteration +MAX_WRITES: int =3D 40 +# MAPS contains the information coming from bpftrace it will have only one +# key: "hits", which tells the number of times netpoll_poll_dev() was call= ed +MAPS: dict[str, int] =3D {} +# Thread to run bpftrace in parallel +BPF_THREAD: Optional[threading.Thread] =3D None +# Time bpftrace will be running in parallel. +BPFTRACE_TIMEOUT: int =3D 10 + + +def ethtool_read_rx_tx_queue(interface_name: str) -> tuple[int, int]: + """ + Read the number of RX and TX queues using ethtool. This will be used + to restore it after the test + """ + rx_queue =3D 0 + tx_queue =3D 0 + + try: + ethtool_result =3D ethtool(f"-g {interface_name}").stdout + for line in ethtool_result.splitlines(): + if line.startswith("RX:"): + rx_queue =3D int(line.split()[1]) + if line.startswith("TX:"): + tx_queue =3D int(line.split()[1]) + except IndexError as exception: + raise KsftSkipEx( + f"Failed to read RX/TX queues numbers: {exception}. Not going = to mess with them." + ) from exception + + if not rx_queue or not tx_queue: + raise KsftSkipEx( + "Failed to read RX/TX queues numbers. Not going to mess with t= hem." + ) + return rx_queue, tx_queue + + +def ethtool_set_rx_tx_queue(interface_name: str, rx_val: int, tx_val: int)= -> None: + """Set the number of RX and TX queues to 1 using ethtool""" + try: + # This don't need to be reverted, since interfaces will be deleted= after test + ethtool(f"-G {interface_name} rx {rx_val} tx {tx_val}") + except Exception as exception: + raise KsftSkipEx( + f"Failed to configure RX/TX queues: {exception}. Ethtool not a= vailable?" + ) from exception + + +def netcons_generate_random_target_name() -> str: + """Generate a random target name starting with 'netcons'""" + random_suffix =3D "".join(random.choices(string.ascii_lowercase + stri= ng.digits, k=3D8)) + return f"netcons_{random_suffix}" + + +def netcons_create_target( + config_data: dict[str, str], + target_name: str, +) -> None: + """Create a netconsole dynamic target against the interfaces""" + logging.debug("Using netconsole name: %s", target_name) + try: + os.makedirs(f"{NETCONSOLE_CONFIGFS_PATH}/{target_name}", exist_ok= =3DTrue) + logging.debug( + "Created target directory: %s/%s", NETCONSOLE_CONFIGFS_PATH, t= arget_name + ) + except OSError as exception: + if exception.errno !=3D errno.EEXIST: + raise KsftFailEx( + f"Failed to create netconsole target directory: {exception= }" + ) from exception + + try: + for key, value in config_data.items(): + path =3D f"{NETCONSOLE_CONFIGFS_PATH}/{target_name}/{key}" + logging.debug("Writing %s to %s", key, path) + with open(path, "w", encoding=3D"utf-8") as file: + # Always convert to string to write to file + file.write(str(value)) + + # Read all configuration values for debugging purposes + for debug_key in config_data.keys(): + with open( + f"{NETCONSOLE_CONFIGFS_PATH}/{target_name}/{debug_key}", + "r", + encoding=3D"utf-8", + ) as file: + content =3D file.read() + logging.debug( + "%s/%s/%s : %s", + NETCONSOLE_CONFIGFS_PATH, + target_name, + debug_key, + content.strip(), + ) + + except Exception as exception: + raise KsftFailEx( + f"Failed to configure netconsole target: {exception}" + ) from exception + + +def netcons_configure_target( + cfg: NetDrvEpEnv, interface_name: str, target_name: str +) -> None: + """Configure netconsole on the interface with the given target name""" + config_data =3D { + "extended": "1", + "dev_name": interface_name, + "local_port": NETCONS_LOCAL_PORT, + "remote_port": NETCONS_REMOTE_PORT, + "local_ip": cfg.addr_v["4"] if cfg.addr_ipver =3D=3D "4" else cfg.= addr_v["6"], + "remote_ip": ( + cfg.remote_addr_v["4"] if cfg.addr_ipver =3D=3D "4" else cfg.r= emote_addr_v["6"] + ), + "remote_mac": "00:00:00:00:00:00", # Not important for this test + "enabled": "1", + } + + netcons_create_target(config_data, target_name) + logging.debug( + "Created netconsole target: %s on interface %s", target_name, inte= rface_name + ) + + +def netcons_delete_target(name: str) -> None: + """Delete a netconsole dynamic target""" + target_path =3D f"{NETCONSOLE_CONFIGFS_PATH}/{name}" + try: + if os.path.exists(target_path): + os.rmdir(target_path) + except OSError as exception: + raise KsftFailEx( + f"Failed to delete netconsole target: {exception}" + ) from exception + + +def netcons_load_module() -> None: + """Try to load the netconsole module""" + os.system("modprobe netconsole") + + +def bpftrace_call() -> None: + """Call bpftrace to find how many times netpoll_poll_dev() is called. + Output is saved in the global variable `maps`""" + + # This is going to update the global variable, that will be seen by the + # main function + global MAPS # pylint: disable=3DW0603 + + # This will be passed to bpftrace as in bpftrace -e "expr" + expr =3D "kprobe:netpoll_poll_dev { @hits =3D count(); }" + + MAPS =3D bpftrace(expr, timeout=3DBPFTRACE_TIMEOUT, json=3DTrue) + logging.debug("BPFtrace output: %s", MAPS) + + +def bpftrace_start(): + """Start a thread to call `call_bpf` in a parallel thread""" + global BPF_THREAD # pylint: disable=3DW0603 + + BPF_THREAD =3D threading.Thread(target=3Dbpftrace_call) + BPF_THREAD.start() + if not BPF_THREAD.is_alive(): + raise KsftSkipEx("BPFtrace thread is not alive. Skipping test") + + +def bpftrace_stop() -> None: + """Stop the bpftrace thread""" + if BPF_THREAD: + BPF_THREAD.join() + + +def bpftrace_any_hit(join: bool) -> bool: + """Check if netpoll_poll_dev() was called by checking the global varia= ble `maps`""" + if not BPF_THREAD: + raise KsftFailEx("BPFtrace didn't start") + + if BPF_THREAD.is_alive(): + if join: + # Wait for bpftrace to finish + BPF_THREAD.join() + else: + # bpftrace is still running, so, we will not check the result = yet + return False + + logging.debug("MAPS coming from bpftrace =3D %s", MAPS) + if "hits" not in MAPS.keys(): + raise KsftFailEx(f"bpftrace failed to run!?: {MAPS}") + + logging.debug("Got a total of %d hits", MAPS["hits"]) + return MAPS["hits"] > 0 + + +def do_netpoll_flush_monitored(cfg: NetDrvEpEnv, ifname: str, target_name:= str) -> None: + """Print messages to the console, trying to trigger a netpoll poll""" + # Start bpftrace in parallel, so, it is watching + # netpoll_poll_dev() while we are sending netconsole messages + bpftrace_start() + + do_netpoll_flush(cfg, ifname, target_name) + + if bpftrace_any_hit(join=3DTrue): + ksft_pr("netpoll_poll_dev() was called. Success") + return + + raise KsftXfailEx("netpoll_poll_dev() was not called during the test..= .") + + +# toggle the interface up and down, to cause some congestion +def toggle_interface(ifname: str) -> None: + """Toggle the interface up and down""" + logging.debug("Toggling interface %s", ifname) + try: + ip(f"link set dev {ifname} down") + # Send a message while the interface is down, just to + # cause more test scenarios. Netconsole should be + # going down here as well, giving the link was lost + with open("/dev/kmsg", "w", encoding=3D"utf-8") as kmsg: + kmsg.write("netcons test while interface down\n") + + ip(f"link set dev {ifname} up") + except Exception as exception: + raise KsftFailEx(f"Failed to toggle interface: {exception}") from = exception + + +def do_netpoll_flush(cfg: NetDrvEpEnv, ifname: str, target_name: str) -> N= one: + """Print messages to the console, trying to trigger a netpoll poll""" + netcons_configure_target(cfg, ifname, target_name) + retry =3D 0 + + for i in range(int(ITERATIONS)): + if not BPF_THREAD.is_alive() or bpftrace_any_hit(join=3DFalse): + # bpftrace is done, stop sending messages + break + + msg =3D f"netcons test #{i}" + with open("/dev/kmsg", "w", encoding=3D"utf-8") as kmsg: + for j in range(MAX_WRITES): + try: + kmsg.write(f"{msg}-{j}\n") + except OSError as exception: + # in some cases, kmsg can be busy, so, we will retry + time.sleep(1) + retry +=3D 1 + if retry < 5: + logging.info("Failed to write to kmsg. Retrying") + # Just retry a few times + continue + raise KsftFailEx( + f"Failed to write to kmsg: {exception}" + ) from exception + + # Every 5 iterations, toggle the network and netconsole + toggle_interface(ifname) + netcons_delete_target(target_name) + netcons_configure_target(cfg, ifname, target_name) + # If we sleep here, we will have a better chance of triggering + # This number is based on a few tests I ran while developing this = test + time.sleep(0.4) + + +def test_netpoll(cfg: NetDrvEpEnv) -> None: + """ + Test netpoll by sending traffic to the interface and then sending + netconsole messages to trigger a poll + """ + + target_name =3D netcons_generate_random_target_name() + ifname =3D cfg.dev["ifname"] + traffic =3D None + original_queues =3D ethtool_read_rx_tx_queue(ifname) + + try: + # Set RX/TX queues to 1 to force congestion + ethtool_set_rx_tx_queue(ifname, 1, 1) + + traffic =3D GenerateTraffic(cfg) + do_netpoll_flush_monitored(cfg, ifname, target_name) + finally: + if traffic: + traffic.stop() + + # Revert RX/TX queues + ethtool_set_rx_tx_queue(ifname, original_queues[0], original_queue= s[1]) + netcons_delete_target(target_name) + bpftrace_stop() + + +def test_check_dependencies() -> None: + """Check if the dependencies are met""" + if not os.path.exists(NETCONSOLE_CONFIGFS_PATH): + raise KsftSkipEx( + f"Directory {NETCONSOLE_CONFIGFS_PATH} does not exist. CONFIG_= NETCONSOLE_DYNAMIC might not be set." # pylint: disable=3DC0301 + ) + + +def main() -> None: + """Main function to run the test""" + netcons_load_module() + test_check_dependencies() + with NetDrvEpEnv(__file__, nsim_test=3DTrue) as cfg: + ksft_run( + [test_netpoll], + args=3D(cfg,), + ) + ksft_exit() + + +if __name__ =3D=3D "__main__": + main() --=20 2.47.1