From patchwork Mon Jul 6 17:00:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 1323770 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cox0+52z; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4B0sJQ0Mnzz9sSd for ; Tue, 7 Jul 2020 03:00:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729620AbgGFRAV (ORCPT ); Mon, 6 Jul 2020 13:00:21 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:55191 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729537AbgGFRAU (ORCPT ); Mon, 6 Jul 2020 13:00:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594054819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NRhtPMhqlhqnOe1hdlLHWlYessgAjO4kXt3vnlCbry4=; b=cox0+52zwPNarVWeMfndzhffSvChL3l3ScXpWBjXC5GTqzfvtvmjcyRwBL+Njw8NBMPYKc xrqBEo4NRjHcZ990hYC0hGr3N/HtOxbagbM7b9Iyk2Ld51Wad96NNVvxDmknsA5JrWUAHG 7Y05anroDp5TjSfkMrB2pps1onH8XII= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-d6f8FbxVNtKsh-rbiHNnXQ-1; Mon, 06 Jul 2020 13:00:18 -0400 X-MC-Unique: d6f8FbxVNtKsh-rbiHNnXQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90D8B107ACCA; Mon, 6 Jul 2020 17:00:16 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.40.208.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id A541E5C241; Mon, 6 Jul 2020 17:00:12 +0000 (UTC) Received: from [192.168.42.3] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 83E743002D737; Mon, 6 Jul 2020 19:00:11 +0200 (CEST) Subject: [PATCH bpf-next V2 1/2] selftests/bpf: test_progs use another shell exit on non-actions From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Andrii Nakryiko Cc: Jesper Dangaard Brouer , Hangbin Liu , Daniel Borkmann , Alexei Starovoitov , vkabatov@redhat.com, jbenc@redhat.com, yhs@fb.com, kafai@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 06 Jul 2020 19:00:11 +0200 Message-ID: <159405481147.1091613.18095872509921723823.stgit@firesoul> In-Reply-To: <159405478968.1091613.16934652228902650021.stgit@firesoul> References: <159405478968.1091613.16934652228902650021.stgit@firesoul> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is a follow up adjustment to commit 6c92bd5cd465 ("selftests/bpf: Test_progs indicate to shell on non-actions"), that returns shell exit indication EXIT_FAILURE (value 1) when user selects a non-existing test. The problem with using EXIT_FAILURE is that a shell script cannot tell the difference between a non-existing test and the test failing. This patch uses value 2 as shell exit indication. (Aside note unrecognized option parameters use value 64). Fixes: 6c92bd5cd465 ("selftests/bpf: Test_progs indicate to shell on non-actions") Signed-off-by: Jesper Dangaard Brouer --- tools/testing/selftests/bpf/test_progs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index 104e833d0087..e8f7cd5dbae4 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -12,6 +12,8 @@ #include #include /* backtrace */ +#define EXIT_NO_TEST 2 + /* defined in test_progs.h */ struct test_env env = {}; @@ -740,7 +742,7 @@ int main(int argc, char **argv) close(env.saved_netns_fd); if (env.succ_cnt + env.fail_cnt + env.skip_cnt == 0) - return EXIT_FAILURE; + return EXIT_NO_TEST; return env.fail_cnt ? EXIT_FAILURE : EXIT_SUCCESS; } From patchwork Mon Jul 6 17:00:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 1323773 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HfbGgJIr; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4B0sJW0fbvz9sSd for ; Tue, 7 Jul 2020 03:00:27 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729651AbgGFRAZ (ORCPT ); Mon, 6 Jul 2020 13:00:25 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:40116 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729495AbgGFRAZ (ORCPT ); Mon, 6 Jul 2020 13:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594054823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sxp8KWaWgJw4WshhI3nQX8hZlCBBJb92GnlvBY7ow9Q=; b=HfbGgJIr/nI5Kq2pbDtWCWP/VyNH0YbUi578O1mp0n7yj8Ek8FPkGOZS0ChupvHxgo91QU ruDKy6V9QnXBfIFiMFfN2rw6W6j5jRkKxOfzmMNAHMicjh5OAJcPHRisa1Xa0on1zmgsxQ Gj5T0Pq6+gAqo0oVZJ1BgBuzx7zIUh0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-5wWf46BnOtmQAa7b9mq7OQ-1; Mon, 06 Jul 2020 13:00:19 -0400 X-MC-Unique: 5wWf46BnOtmQAa7b9mq7OQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E717787950B; Mon, 6 Jul 2020 17:00:17 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.40.208.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 953235C290; Mon, 6 Jul 2020 17:00:17 +0000 (UTC) Received: from [192.168.42.3] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 95636300019CC; Mon, 6 Jul 2020 19:00:16 +0200 (CEST) Subject: [PATCH bpf-next V2 2/2] selftests/bpf: test_progs avoid minus shell exit codes From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Andrii Nakryiko Cc: Jesper Dangaard Brouer , Hangbin Liu , Daniel Borkmann , Alexei Starovoitov , vkabatov@redhat.com, jbenc@redhat.com, yhs@fb.com, kafai@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 06 Jul 2020 19:00:16 +0200 Message-ID: <159405481655.1091613.6475075949369245359.stgit@firesoul> In-Reply-To: <159405478968.1091613.16934652228902650021.stgit@firesoul> References: <159405478968.1091613.16934652228902650021.stgit@firesoul> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There are a number of places in test_progs that use minus-1 as the argument to exit(). This improper use as a process exit status is masked to be a number between 0 and 255 as defined in man exit(3). This patch use two different positive exit codes instead, to allow a shell script to tell the two error cases apart. Fixes: fd27b1835e70 ("selftests/bpf: Reset process and thread affinity after each test/sub-test") Fixes: 811d7e375d08 ("bpf: selftests: Restore netns after each test") Signed-off-by: Jesper Dangaard Brouer --- tools/testing/selftests/bpf/test_progs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index e8f7cd5dbae4..50803b080593 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -12,7 +12,9 @@ #include #include /* backtrace */ -#define EXIT_NO_TEST 2 +#define EXIT_NO_TEST 2 +#define EXIT_ERR_NETNS 3 +#define EXIT_ERR_RESET_AFFINITY 4 /* defined in test_progs.h */ struct test_env env = {}; @@ -113,13 +115,13 @@ static void reset_affinity() { if (err < 0) { stdio_restore(); fprintf(stderr, "Failed to reset process affinity: %d!\n", err); - exit(-1); + exit(EXIT_ERR_RESET_AFFINITY); } err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); if (err < 0) { stdio_restore(); fprintf(stderr, "Failed to reset thread affinity: %d!\n", err); - exit(-1); + exit(EXIT_ERR_RESET_AFFINITY); } } @@ -128,7 +130,7 @@ static void save_netns(void) env.saved_netns_fd = open("/proc/self/ns/net", O_RDONLY); if (env.saved_netns_fd == -1) { perror("open(/proc/self/ns/net)"); - exit(-1); + exit(EXIT_ERR_NETNS); } } @@ -137,7 +139,7 @@ static void restore_netns(void) if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { stdio_restore(); perror("setns(CLONE_NEWNS)"); - exit(-1); + exit(EXIT_ERR_NETNS); } }