Message ID | 20230310061048.1418400-1-void@manifault.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp712663wrd; Thu, 9 Mar 2023 22:24:37 -0800 (PST) X-Google-Smtp-Source: AK7set/UmWDwi8Er6SPWqrJ7/sT27u34NkKlP/BYFds1kFlILo6uTpCzZSfsZvHfPikwsfOkWeas X-Received: by 2002:a05:6a20:a00e:b0:cc:9643:1f8f with SMTP id p14-20020a056a20a00e00b000cc96431f8fmr3888592pzj.13.1678429477400; Thu, 09 Mar 2023 22:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678429477; cv=none; d=google.com; s=arc-20160816; b=x+TL8iS1gqkZAgcCiEC7lxeK2o97SbOC2Bm5wqQ+w39YYweTCw8v6Z6gszE0/qoNO0 n4B7zSiwUfVROX+hp6siCQJre2lrj0fpbvAos13JOT9JqlUMHBKDrxFdQpBH15oHuB+j EPNp6lfhEMV8tzzgnenDSiXYwag6LDFn0DcUZ0N5HP6880id/b4b8wm0o8xJDr/4Lb5j vjxfCe7MumbisA5QtmjjJuZiYWXPDOyTLUrHef5uHMVFn+FeLeSzNRNx4+c2KdVFCWW9 z/e6TrPV0ImJpbsL3mu1YHIkVZJYwhBtrag++xUCYH/A/396scXOaRJwUnYIBg2oNk0j stXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=TKs6blxuG9zlni0sl4k3Jn1Rpj+hd6hKaAuGgne6E3I=; b=uBgqxFpjSZs54hbZ7+x96SAeToZ7RjQLKSgT2WH/6ejIsmxjg0PBL8K4oQMqpa1x+P 0BndtlSmAC2vx7fbWC4umUYh+rjyRbifmKuMQsAd5CFb6UTGWyZ7GYZeHnCBwcIAJj1t FBRPFg9iHytyjcydhLerjoEKaU4hG28igQ/ZovDsxkL2PAGwIpsCKTU58VnR5xxtZdI7 vbLkUkpybEum/pYvhzAQG5stQS1Rc+2DediGa+/6P4lHjpdp4isPcEW+1WybcX/yFpK0 Q3EZhgE1pOSniQph7fii/Jx0BZqGs+a/pPzOjstx8OQRmdE9Eh6JVqzKD3Z4qf2oqnOU 5rSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 67-20020a630346000000b00502d85bfb5fsi1218043pgd.451.2023.03.09.22.24.22; Thu, 09 Mar 2023 22:24:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbjCJGK6 (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Fri, 10 Mar 2023 01:10:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCJGK4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 10 Mar 2023 01:10:56 -0500 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD6631033BA; Thu, 9 Mar 2023 22:10:55 -0800 (PST) Received: by mail-qt1-f180.google.com with SMTP id c18so4714414qte.5; Thu, 09 Mar 2023 22:10:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678428654; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TKs6blxuG9zlni0sl4k3Jn1Rpj+hd6hKaAuGgne6E3I=; b=Arfhtvk5OCmG97S8NBEhVc7lOecrFGxT2QnPwa+Odby5bmHE1VKgNNYT38wIyAs0HF hn7DkUkIm1CSXod+zHdCx/MGtMgZ0N6RsHuqA8wgtmOoeNHeLA4Faicks7JDzD4hcZ8N oV5XvwkvSrzPMvCmXm4r1IKXO5J4SH/UEXR05PxiS3NRHsHqDeLIOZWr77FnGriWHP/4 LJgPAxOJZytBxQhfQKjIhcrQem2CGb7Ij8jEHB6PP5hVKbhuju6PRYrxxeVtH8MO5rsi tawmLrnBO8J9QRJZnPpcPzUwds9UltA55ekt7gCbmWOWoHtM2cR3Blffv/tpeTAHvSVn x6Zg== X-Gm-Message-State: AO0yUKV80lwfdsjm2Twykl/ufAS+AIJy/6Y0ytITvPVnhdRTDBJymj6A JtLa44BsQWYBWHY68hixdVXr63GyNdRK5X4p X-Received: by 2002:a05:622a:181d:b0:3b8:689f:d8ef with SMTP id t29-20020a05622a181d00b003b8689fd8efmr39564041qtc.18.1678428654450; Thu, 09 Mar 2023 22:10:54 -0800 (PST) Received: from localhost ([2620:10d:c091:400::5:388b]) by smtp.gmail.com with ESMTPSA id m12-20020ac866cc000000b003bfc335f124sm801321qtp.79.2023.03.09.22.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 22:10:53 -0800 (PST) From: David Vernet <void@manifault.com> To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@meta.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next] bpf/selftests: Fix send_signal tracepoint tests Date: Fri, 10 Mar 2023 00:10:48 -0600 Message-Id: <20230310061048.1418400-1-void@manifault.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759960867930253530?= X-GMAIL-MSGID: =?utf-8?q?1759960867930253530?= |
Series |
[bpf-next] bpf/selftests: Fix send_signal tracepoint tests
|
|
Commit Message
David Vernet
March 10, 2023, 6:10 a.m. UTC
The send_signal tracepoint tests are non-deterministically failing in
CI. The test works as follows:
1. Two pairs of file descriptors are created using the pipe() function.
One pair is used to communicate between a parent process -> child
process, and the other for the reverse direction.
2. A child is fork()'ed. The child process registers a signal handler,
notifies its parent that the signal handler is registered, and then
and waits for its parent to have enabled a BPF program that sends a
signal.
3. The parent opens and loads a BPF skeleton with programs that send
signals to the child process. The different programs are triggered by
different perf events (either NMI or normal perf), or by regular
tracepoints. The signal is delivered to the child whenever the child
triggers the program.
4. The child's signal handler is invoked, which sets a flag saying that
the signal handler was reached. The child then signals to the parent
that it received the signal, and the test ends.
The perf testcases (send_signal_perf{_thread} and
send_signal_nmi{_thread}) work 100% of the time, but the tracepoint
testcases fail non-deterministically because the tracepoint is not
always being fired for the child.
There are two tracepoint programs registered in the test:
'tracepoint/sched/sched_switch', and
'tracepoint/syscalls/sys_enter_nanosleep'. The child never intentionally
blocks, nor sleeps, so neither tracepoint is guaranteed to be triggered.
To fix this, we can have the child trigger the nanosleep program with a
usleep().
Before this patch, the test would fail locally every 2-3 runs. Now, it
doesn't fail after more than 1000 runs.
Signed-off-by: David Vernet <void@manifault.com>
---
tools/testing/selftests/bpf/prog_tests/send_signal.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Fri, Mar 10, 2023 at 12:10:48AM -0600, David Vernet wrote: > The send_signal tracepoint tests are non-deterministically failing in > CI. The test works as follows: > > 1. Two pairs of file descriptors are created using the pipe() function. > One pair is used to communicate between a parent process -> child > process, and the other for the reverse direction. > > 2. A child is fork()'ed. The child process registers a signal handler, > notifies its parent that the signal handler is registered, and then > and waits for its parent to have enabled a BPF program that sends a > signal. > > 3. The parent opens and loads a BPF skeleton with programs that send > signals to the child process. The different programs are triggered by > different perf events (either NMI or normal perf), or by regular > tracepoints. The signal is delivered to the child whenever the child > triggers the program. > > 4. The child's signal handler is invoked, which sets a flag saying that > the signal handler was reached. The child then signals to the parent > that it received the signal, and the test ends. > > The perf testcases (send_signal_perf{_thread} and > send_signal_nmi{_thread}) work 100% of the time, but the tracepoint > testcases fail non-deterministically because the tracepoint is not > always being fired for the child. > > There are two tracepoint programs registered in the test: > 'tracepoint/sched/sched_switch', and > 'tracepoint/syscalls/sys_enter_nanosleep'. The child never intentionally > blocks, nor sleeps, so neither tracepoint is guaranteed to be triggered. > To fix this, we can have the child trigger the nanosleep program with a > usleep(). > > Before this patch, the test would fail locally every 2-3 runs. Now, it > doesn't fail after more than 1000 runs. > > Signed-off-by: David Vernet <void@manifault.com> > --- > tools/testing/selftests/bpf/prog_tests/send_signal.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c > index d63a20fbed33..61cc83fca53c 100644 > --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c > +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c > @@ -64,8 +64,11 @@ static void test_send_signal_common(struct perf_event_attr *attr, > ASSERT_EQ(read(pipe_p2c[0], buf, 1), 1, "pipe_read"); > > /* wait a little for signal handler */ > - for (int i = 0; i < 1000000000 && !sigusr1_received; i++) > + for (int i = 0; i < 1000000000 && !sigusr1_received; i++) { > j /= i + j + 1; > + if (!attr) > + ASSERT_EQ(usleep(1), 0, "nanosleep_tp"); As soon as I sent this out, it occurred to me that having an ASSERT_EQ like this is not a good idea. usleep() could be interrupted by a signal and return EINTR, and the whole point of this test is to send signals to the child. Let me resend this as v2 without the ASSERT_EQ. > + } > > buf[0] = sigusr1_received ? '2' : '0'; > ASSERT_EQ(sigusr1_received, 1, "sigusr1_received"); > -- > 2.39.0 >
diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c index d63a20fbed33..61cc83fca53c 100644 --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c @@ -64,8 +64,11 @@ static void test_send_signal_common(struct perf_event_attr *attr, ASSERT_EQ(read(pipe_p2c[0], buf, 1), 1, "pipe_read"); /* wait a little for signal handler */ - for (int i = 0; i < 1000000000 && !sigusr1_received; i++) + for (int i = 0; i < 1000000000 && !sigusr1_received; i++) { j /= i + j + 1; + if (!attr) + ASSERT_EQ(usleep(1), 0, "nanosleep_tp"); + } buf[0] = sigusr1_received ? '2' : '0'; ASSERT_EQ(sigusr1_received, 1, "sigusr1_received");