From patchwork Fri Nov 3 11:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=SUnvluen; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ3z662xz1yQx for ; Fri, 3 Nov 2023 22:12:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229492AbjKCLMJ (ORCPT ); Fri, 3 Nov 2023 07:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKCLMH (ORCPT ); Fri, 3 Nov 2023 07:12:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 801821A8 for ; Fri, 3 Nov 2023 04:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5R/htTHNKbPe4E+x/FqT14eQVCBsdC3XifjhyE87t3E=; b=SUnvluen5+PAtmYQD4qYoTzAz/xzvysWKcy6l3osQfWEOxPExCBj0pR+Dl05vOHZDggo6R oJC40uPchNLd4MtoFkfUGf+qUBwz8wX+0iqlxbQKoMiUzuN0xZLKV+FIoFAtGuH8bXcuCn xFuSI7U/oz4femrkHTLfCCpoKl3apJQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-D9mzKKj9OoqCpm-ouWSIrQ-1; Fri, 03 Nov 2023 07:11:14 -0400 X-MC-Unique: D9mzKKj9OoqCpm-ouWSIrQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38AD6101A529 for ; Fri, 3 Nov 2023 11:11:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD40B1C060BE; Fri, 3 Nov 2023 11:11:13 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 1/6] gitignore: ignore build artifacts from top level file Date: Fri, 3 Nov 2023 12:05:43 +0100 Message-ID: <20231103111102.2801624-2-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org I don't think that having multiple .gitignore files for a small project like nftables is best. Anyway. The build artifacts like "*.o" will not only be found under "src/". Move those patterns. Signed-off-by: Thomas Haller --- .gitignore | 7 ++++++- src/.gitignore | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a62e31f31c6b..51429020ceb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ -# Generated by autoconf/configure/automake +# Generated by autoconf/configure/automake/make *.m4 +*.la +*.lo +*.o +.deps/ .dirstamp +.libs/ Makefile Makefile.in stamp-h1 diff --git a/src/.gitignore b/src/.gitignore index 2d907425cbb0..f34105c6cda4 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,8 +1,3 @@ -*.la -*.lo -*.o -.deps/ -.libs/ nft parser_bison.c parser_bison.h From patchwork Fri Nov 3 11:05:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=SLTSmRWI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ405qcWz1yR1 for ; Fri, 3 Nov 2023 22:12:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjKCLMP (ORCPT ); Fri, 3 Nov 2023 07:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKCLMO (ORCPT ); Fri, 3 Nov 2023 07:12:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F6A6D43 for ; Fri, 3 Nov 2023 04:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DMh26LiZ3YqlGuQUvIUrKY5srmaBAnvMPvKz0tXDook=; b=SLTSmRWI470337MfQKIMU/BfK+7gGQGanFb2NGfkp9/9uYPRzoT1ew0UVboKsbCXIR27W1 N8FRW8IrlIVkmz6xvN/b75oS2fUvlpZ6uJNBpGye8zScqmuITz3yUi5/oExAd0EK/3FhO7 0w2kIghlVpgVnMRK4Lk45SlZ8AvBlyg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-UzgojzXrPRKa3AcFKbvnLw-1; Fri, 03 Nov 2023 07:11:15 -0400 X-MC-Unique: UzgojzXrPRKa3AcFKbvnLw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0073481B161 for ; Fri, 3 Nov 2023 11:11:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74D671C060BA; Fri, 3 Nov 2023 11:11:14 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 2/6] build: add basic "check-{local,more,all}" and "build-all" make targets Date: Fri, 3 Nov 2023 12:05:44 +0100 Message-ID: <20231103111102.2801624-3-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org Add targets "check-local" and "check-more", which later will hook up additional tests. For now, they are empty targets. Signed-off-by: Thomas Haller --- Makefile.am | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Makefile.am b/Makefile.am index 0ed831a19e95..93bd47970077 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,8 +31,11 @@ lib_LTLIBRARIES = noinst_LTLIBRARIES = sbin_PROGRAMS = check_PROGRAMS = +check_LTLIBRARIES = dist_man_MANS = CLEANFILES = +check_local = +check_more = ############################################################################### @@ -409,3 +412,23 @@ EXTRA_DIST += \ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libnftables.pc + +############################################################################### + +build-all: all $(check_PROGRAMS) $(check_LTLIBRARIES) + +.PHONY: build-all + +############################################################################### + +check-local: build-all $(check_local) + +.PHONY: check-local $(check_local) + +check-more: build-all $(check_more) + +.PHONY: check-more $(check_more) + +check-all: check check-more + +.PHONY: check-all From patchwork Fri Nov 3 11:05:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=ihZs/bbL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ4014pmz1yR0 for ; Fri, 3 Nov 2023 22:12:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbjKCLMM (ORCPT ); Fri, 3 Nov 2023 07:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKCLML (ORCPT ); Fri, 3 Nov 2023 07:12:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7128A1BF for ; Fri, 3 Nov 2023 04:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=knrR0jUrzRdrVY2OqFasxlya4annWwkL6Gg9dhcAOwA=; b=ihZs/bbLIXHivcZ1x4VsSzAPEqUYpuOZ5tyblHLZrVKCGiVgVDLHaK2vnEokxMndRfetTl 2PJUoWJ1LWdZ9hGvtXXS4sylaE9WJmZmVbEJl9y+AmSq4SjBMri2MNOsc0gYerPLQaOGQd 8ahRWF4BUc3MNEYJujduMdBApSvYFyI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-522-G3_dutjEP-aJ-FxZevpiQw-1; Fri, 03 Nov 2023 07:11:16 -0400 X-MC-Unique: G3_dutjEP-aJ-FxZevpiQw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC983185A780 for ; Fri, 3 Nov 2023 11:11:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C46B1C060BA; Fri, 3 Nov 2023 11:11:15 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 3/6] build: add `make check-tests-build` to add build test Date: Fri, 3 Nov 2023 12:05:45 +0100 Message-ID: <20231103111102.2801624-4-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org Call "./tests/build/run-tests.sh" from a new make target "check-tests-build". This script performs the build check. As this script takes a rather long time, it's not hooked with "check-local", and consequently not run by `make check`. Instead, it is a dependency of `make check-more`. Signed-off-by: Thomas Haller --- Makefile.am | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile.am b/Makefile.am index 93bd47970077..f39d6cdd0ca3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -421,6 +421,14 @@ build-all: all $(check_PROGRAMS) $(check_LTLIBRARIES) ############################################################################### +check-tests-build: build-all + cd "$(srcdir)/tests/build/" ; \ + CC="$(CC)" CFLAGS='-Werror' ./run-tests.sh + +check_more += check-tests-build + +############################################################################### + check-local: build-all $(check_local) .PHONY: check-local $(check_local) From patchwork Fri Nov 3 11:05:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=EDV7JeVH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ403SRGz1yQ5 for ; Fri, 3 Nov 2023 22:12:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbjKCLMN (ORCPT ); Fri, 3 Nov 2023 07:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKCLMN (ORCPT ); Fri, 3 Nov 2023 07:12:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B5518B for ; Fri, 3 Nov 2023 04:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96anuPFrO5gsM8CHmLpFB1X3aSARSwSEMh7SFENNt/w=; b=EDV7JeVHl8CEPf3/jyfAJ3CUHfwZa8aXPl2CeZGG0BLNc30zspAgrcrFGY3D9VrL1kdwFo TqLHtzn7MI2wZBZHMl554ei4BHYCZ/pFeCRGRnk6RTbEkD8INd7/wjxxnvd9yUe6SciBll EFrZ6qCVPtz4+5hXgpgy3cvVPMeuz5k= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-XxOot2TtNpKSdOE6bErrFQ-1; Fri, 03 Nov 2023 07:11:16 -0400 X-MC-Unique: XxOot2TtNpKSdOE6bErrFQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8344B1C05132 for ; Fri, 3 Nov 2023 11:11:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 038741C060BA; Fri, 3 Nov 2023 11:11:15 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 4/6] build: add check for consistency of source tree Date: Fri, 3 Nov 2023 12:05:46 +0100 Message-ID: <20231103111102.2801624-5-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org The script "tools/check-tree.sh" performs some consistency checks of the source tree. Call it from a make target "check-tree". Signed-off-by: Thomas Haller --- Makefile.am | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile.am b/Makefile.am index f39d6cdd0ca3..94c40fc3c6a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -408,6 +408,7 @@ EXTRA_DIST += \ EXTRA_DIST += \ files \ tests \ + tools \ $(NULL) pkgconfigdir = $(libdir)/pkgconfig @@ -429,6 +430,13 @@ check_more += check-tests-build ############################################################################### +check-tree: + "$(srcdir)/tools/check-tree.sh" + +check_local += check-tree + +############################################################################### + check-local: build-all $(check_local) .PHONY: check-local $(check_local) From patchwork Fri Nov 3 11:05:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=MAYq4ZY8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ4m6L8bz1yQx for ; Fri, 3 Nov 2023 22:12:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbjKCLM5 (ORCPT ); Fri, 3 Nov 2023 07:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjKCLM4 (ORCPT ); Fri, 3 Nov 2023 07:12:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAE8FD45 for ; Fri, 3 Nov 2023 04:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y5xzeJhwOzNKjeNrUnon6so8UZY4mXOb669i/F3TTVg=; b=MAYq4ZY8XWDM9NuQEYcGbrCFpJdUHYTJNHPLUb/1UCG7iXkixOOrcUCqAh79APxCddcmsi 51MQzq4oQGkjH6225YjOYvdIeDLke7cW/FshuMFzDlsWYm3pXCgWojZzXeYU5o/IvGRZjN UmRjoOSLj+pykZzGQ6KhZR8x4PDT2oQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-Xc27GE_wMR6aTViEo3RcQQ-1; Fri, 03 Nov 2023 07:11:17 -0400 X-MC-Unique: Xc27GE_wMR6aTViEo3RcQQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4BBD8811E7B for ; Fri, 3 Nov 2023 11:11:17 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFD111C060BA; Fri, 3 Nov 2023 11:11:16 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 5/6] build: cleanup if blocks for conditional compilation Date: Fri, 3 Nov 2023 12:05:47 +0100 Message-ID: <20231103111102.2801624-6-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org `configure` sets those $(*_LIBS) variables to something empty, if the dependency is not available. It's cumbersome and unnecessary to explicitly checking. Also, the order in which libraries are specified on the command line matters. Commonly we want our own libraries first (src/libminigmp.la should come pretty early). That is cumbersome to get right otherwise. Also, as "xt.c" is always built, just directly add it to the list of source files. Signed-off-by: Thomas Haller --- Makefile.am | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index 94c40fc3c6a2..f06fab8e3b9f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -195,6 +195,12 @@ src_libminigmp_la_CFLAGS = \ -Wno-sign-compare \ $(NULL) +LIBMINIGMP_LIBS = src/libminigmp.la + +else + +LIBMINIGMP_LIBS = + endif ############################################################################### @@ -247,10 +253,9 @@ src_libnftables_la_SOURCES = \ src/tcpopt.c \ src/utils.c \ src/xfrm.c \ + src/xt.c \ $(NULL) -src_libnftables_la_SOURCES += src/xt.c - if BUILD_JSON src_libnftables_la_SOURCES += \ src/json.c \ @@ -264,23 +269,14 @@ src_libnftables_la_LDFLAGS = \ $(NULL) src_libnftables_la_LIBADD = \ + src/libparser.la \ + $(LIBMINIGMP_LIBS) \ $(LIBMNL_LIBS) \ $(LIBNFTNL_LIBS) \ - src/libparser.la \ + $(XTABLES_LIBS) \ + $(JANSSON_LIBS) \ $(NULL) -if BUILD_MINIGMP -src_libnftables_la_LIBADD += src/libminigmp.la -endif - -if BUILD_XTABLES -src_libnftables_la_LIBADD += $(XTABLES_LIBS) -endif - -if BUILD_JSON -src_libnftables_la_LIBADD += $(JANSSON_LIBS) -endif - ############################################################################### sbin_PROGRAMS += src/nft From patchwork Fri Nov 3 11:05:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Haller X-Patchwork-Id: 1858867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=OJJZ0x3O; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4SMJ4m2HDvz1yQ5 for ; Fri, 3 Nov 2023 22:12:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjKCLM4 (ORCPT ); Fri, 3 Nov 2023 07:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKCLM4 (ORCPT ); Fri, 3 Nov 2023 07:12:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA315D48 for ; Fri, 3 Nov 2023 04:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699009879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WlH/2BWKUb0KxrJVIFXIgilkrmuM5puW06UfS2fF7YU=; b=OJJZ0x3OD5kyLZ4VNRu9CMDdWyEqvzwuM7zrOKPWPMBOXiy7Cp6J7cs1umlI2N+3/6r884 xD26jEQiLFwk2pOUrUelmMhN+gc0av97VT9fxiFjkSuLtBmxKTanpTJa8b0pwgFACnV4q3 KunZlgg83kYDo2PLDidz7tX20hqBgF0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-3c2n5NJMOLKLKyJBLwOqzQ-1; Fri, 03 Nov 2023 07:11:18 -0400 X-MC-Unique: 3c2n5NJMOLKLKyJBLwOqzQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34809101A529 for ; Fri, 3 Nov 2023 11:11:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.193.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 880701C060BA; Fri, 3 Nov 2023 11:11:17 +0000 (UTC) From: Thomas Haller To: NetFilter Cc: Thomas Haller Subject: [PATCH nft 6/6] tests/unit: add unit tests for libnftables Date: Fri, 3 Nov 2023 12:05:48 +0100 Message-ID: <20231103111102.2801624-7-thaller@redhat.com> In-Reply-To: <20231103111102.2801624-1-thaller@redhat.com> References: <20231103111102.2801624-1-thaller@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: netfilter-devel@vger.kernel.org We have a lot of tests/shell tests, that use the nft binary. However, it's useful to also write unit tests, that can test the internal C code specifically. Since no such tests exist yet, it would be cumbersome to add a test. Add two binaries, that can be used as a place for such tests. Currently there are no real tests there, it's only to show how it works, and that those dummy tests pass (including that the linking and execution works). To access the internals, build an intermediate static library src/libnftables-static.la, which then makes up the public, dynamic src/libnftables.la library. There are two tests: - tests/unit/test-libnftables-static - tests/unit/test-libnftables The former statically links with src/libnftables-static.la and can test internal API from headers under "include/*.h". The latter dynamically links with src/libnftables.la, and can only test the public API from includes/nftables/libnftables.h. You can run the unit tests alone with `make check-TESTS`. Calling 'VALGRIND=y make check' works as expected. Also add a LOG_COMPILER script "tools/test-runner.sh". This wraps the execution of the tests. Even for manual testing, you likely don't want to run "tests/unit/test-*" directly, but rather $ ./tools/test-runner.sh tests/unit/test-libnftables This sets up an unshared namespace and honors VALGRIND=y to run the test under valgrind. Set NFT_TEST_WRAPPER=gdb to start with a debugger. Signed-off-by: Thomas Haller --- .gitignore | 8 +- Makefile.am | 69 ++++++-- tests/unit/nft-test.h | 14 ++ tests/unit/test-libnftables-static.c | 16 ++ tests/unit/test-libnftables.c | 21 +++ tools/test-runner.sh | 228 +++++++++++++++++++++++++++ 6 files changed, 346 insertions(+), 10 deletions(-) create mode 100644 tests/unit/nft-test.h create mode 100644 tests/unit/test-libnftables-static.c create mode 100644 tests/unit/test-libnftables.c create mode 100755 tools/test-runner.sh diff --git a/.gitignore b/.gitignore index 51429020ceb6..369678a13987 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,13 @@ libtool # Generated by tests *.payload.got -tests/build/tests.log +test-suite.log +tests/**/*.log +tests/**/*.trs +tests/**/*.valgrind-log + +tests/unit/test-libnftables +tests/unit/test-libnftables-static # Debian package build temporary files build-stamp diff --git a/Makefile.am b/Makefile.am index f06fab8e3b9f..074d2076c53d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,12 +31,18 @@ lib_LTLIBRARIES = noinst_LTLIBRARIES = sbin_PROGRAMS = check_PROGRAMS = +noinst_PROGRAMS = check_LTLIBRARIES = dist_man_MANS = CLEANFILES = +TESTS = +test_programs = check_local = check_more = +TESTS_ENVIRONMENT = VERBOSE="$(V)" NFT_TEST_MAKE=n +LOG_COMPILER = "$(srcdir)/tools/test-runner.sh" --srcdir "$(abs_srcdir)" --builddir "$(abs_builddir)" -- + ############################################################################### pkginclude_HEADERS = \ @@ -205,11 +211,9 @@ endif ############################################################################### -lib_LTLIBRARIES += src/libnftables.la +noinst_LTLIBRARIES += src/libnftables-static.la -src_libnftables_la_SOURCES = \ - src/libnftables.map \ - \ +src_libnftables_static_la_SOURCES = \ src/cache.c \ src/cmd.c \ src/ct.c \ @@ -257,20 +261,36 @@ src_libnftables_la_SOURCES = \ $(NULL) if BUILD_JSON -src_libnftables_la_SOURCES += \ +src_libnftables_static_la_SOURCES += \ src/json.c \ src/parser_json.c \ $(NULL) endif +src_libnftables_static_la_LIBADD = \ + src/libparser.la \ + $(LIBMINIGMP_LIBS) \ + $(LIBMNL_LIBS) \ + $(LIBNFTNL_LIBS) \ + $(XTABLES_LIBS) \ + $(JANSSON_LIBS) \ + $(NULL) + +############################################################################### + +lib_LTLIBRARIES += src/libnftables.la + +src_libnftables_la_SOURCES = \ + src/libnftables.map \ + $(NULL) + src_libnftables_la_LDFLAGS = \ -version-info "${libnftables_LIBVERSION}" \ -Wl,--version-script="$(srcdir)/src//libnftables.map" \ $(NULL) src_libnftables_la_LIBADD = \ - src/libparser.la \ - $(LIBMINIGMP_LIBS) \ + src/libnftables-static.la \ $(LIBMNL_LIBS) \ $(LIBNFTNL_LIBS) \ $(XTABLES_LIBS) \ @@ -303,6 +323,22 @@ examples_nft_json_file_LDADD = src/libnftables.la ############################################################################### +EXTRA_DIST += tests/unit/nft-test.h + +############################################################################### + +test_programs += tests/unit/test-libnftables-static + +tests_unit_test_libnftables_static_LDADD = src/libnftables-static.la + +############################################################################### + +test_programs += tests/unit/test-libnftables + +tests_unit_test_libnftables_LDADD = src/libnftables.la + +############################################################################### + if BUILD_MAN dist_man_MANS += \ @@ -390,6 +426,16 @@ dist_pkgsysconf_DATA = \ ############################################################################### +EXTRA_DIST += \ + tests/build \ + tests/json_echo \ + tests/monitor \ + tests/py \ + tests/shell \ + $(NULL) + +############################################################################### + EXTRA_DIST += \ py/pyproject.toml \ py/setup.cfg \ @@ -403,7 +449,6 @@ EXTRA_DIST += \ EXTRA_DIST += \ files \ - tests \ tools \ $(NULL) @@ -412,7 +457,13 @@ pkgconfig_DATA = libnftables.pc ############################################################################### -build-all: all $(check_PROGRAMS) $(check_LTLIBRARIES) +check_PROGRAMS += $(test_programs) + +TESTS += $(test_programs) + +############################################################################### + +build-all: all $(check_PROGRAMS) $(test_programs) $(check_LTLIBRARIES) .PHONY: build-all diff --git a/tests/unit/nft-test.h b/tests/unit/nft-test.h new file mode 100644 index 000000000000..cab97b42c669 --- /dev/null +++ b/tests/unit/nft-test.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __NFT_TEST__H__ +#define __NFT_TEST__H__ + +#undef NDEBUG + +#include + +#include +#include +#include + +#endif /* __NFT_TEST__H__ */ diff --git a/tests/unit/test-libnftables-static.c b/tests/unit/test-libnftables-static.c new file mode 100644 index 000000000000..e34fcfd77f39 --- /dev/null +++ b/tests/unit/test-libnftables-static.c @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "nft-test.h" + +#include + +static void test_datatype(void) +{ + assert(!datatype_lookup(-1)); +} + +int main(int argc, char **argv) +{ + test_datatype(); + return 0; +} diff --git a/tests/unit/test-libnftables.c b/tests/unit/test-libnftables.c new file mode 100644 index 000000000000..100558cd5e0f --- /dev/null +++ b/tests/unit/test-libnftables.c @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "nft-test.h" + +#include + +static void test_nft_ctx(void) +{ + struct nft_ctx *ctx; + + ctx = nft_ctx_new(0); + assert(ctx); + + nft_ctx_free(ctx); +} + +int main(int argc, char **argv) +{ + test_nft_ctx(); + return 0; +} diff --git a/tools/test-runner.sh b/tools/test-runner.sh new file mode 100755 index 000000000000..18658ba4adf1 --- /dev/null +++ b/tools/test-runner.sh @@ -0,0 +1,228 @@ +#!/bin/bash + +set -e + +die() { + printf '%s\n' "$*" + exit 1 +} + +as_bool() { + if [ "$#" -eq 0 ] ; then + return 1 + fi + case "$1" in + y|Y|yes|Yes|YES|1|true|True|TRUE) + return 0 + ;; + n|N|no|No|NO|0|false|False|FALSE) + return 1 + ;; + *) + # Fallback to the next in the list. + shift + rc=0 + as_bool "$@" || rc=$? + return "$rc" + esac +} + +as_bool_str() { + if as_bool "$@" ; then + printf y + else + printf n + fi +} + +usage() { + echo " $0 [OPTIONS] TEST" + echo + echo "Run TEST" + echo + echo "Options:" + echo " --srcdir dir: Sets SRCDIR=dir." + echo " --builddir dir: Sets BUILDDIR=dir." + echo " -V|--valgrind: Sets VALGRIND=y." + echo " -G|--gdb: Sets NFT_TEST_WRAPPER=gdb." + echo " -m|--make: Sets NFT_TEST_MAKE=y." + echo " --: Separates options from test name." + echo " TEST: the path of the test executable to run." + echo + echo "Environment variables:" + echo " SRCDIR: set to \$(srcdir) of the project." + echo " BUILDDIR: set to \$(builddir) of the project." + echo " VERBOSE: for verbose output." + echo " VALGRIND: if set to TRUE, run the test under valgrind. NFT_TEST_UNDER_VALGRIND is ignored." + echo " NFT_TEST_UNSHARE_CMD: override the command to unshare the netns." + echo " Set to empty to not unshare." + echo " NFT_TEST_WRAPPER: usually empty. For manual testing, this is prepended to TEST." + echo " Set for example got \"gdb\"." + echo " NFT_TEST_MAKE: if true, call \`make\` on the test first." +} + +usage_and_die() { + usage + echo + die "$@" +} + +TIMESTAMP=$(date '+%Y%m%d-%H%M%S.%3N') + +# SRCDIR +# BUILDDIR +VERBOSE="$(as_bool_str "$VERBOSE")" +VALGRIND="$(as_bool_str "$VALGRIND")" +NFT_TEST_UNSHARE_CMD="${NFT_TEST_UNSHARE_CMD-unshare -m -U --map-root-user -n}" +NFT_TEST_WRAPPER="${NFT_TEST_WRAPPER}" +NFT_TEST_MAKE="$(as_bool_str "$NFT_TEST_MAKE")" + +unset TEST + +while [ $# -gt 0 ] ; do + A="$1" + shift + case "$A" in + -h|--help) + usage + exit 0 + ;; + --srcdir) + SRCDIR="$1" + shift + ;; + --builddir) + BUILDDIR="$1" + shift + ;; + -V|--valgrind) + VALGRIND=y + ;; + -G|--gdb) + NFT_TEST_WRAPPER=gdb + ;; + -m|--make) + NFT_TEST_MAKE=y + ;; + --) + if [ $# -ne 1 ] ; then + usage_and_die "Requires a TEST argument after --" + fi + TEST="$1" + shift + ;; + *) + if [ -n "${TEST+x}" ] ; then + usage_and_die "Unknown argument \"$A\"" + fi + TEST="$A" + ;; + esac +done + +if [ -z "$TEST" ] ; then + usage_and_die "Missing test argument. See --help" +fi + +if [ -z "${SRCDIR+x}" ] ; then + SRCDIR="$(readlink -f "$(dirname "$0")/..")" +fi +if [ ! -d "$SRCDIR" ] ; then + die "Invalid \$SRCDIR=\"$SRCDIR\"" +fi + +if [ -z "${BUILDDIR+x}" ] ; then + re='^(.*/|)(tests/unit/test-[^/]*)$' + if [[ "$TEST" =~ $re ]] ; then + BUILDDIR="$(readlink -f "${BASH_REMATCH[1]:-.}")" || : + else + BUILDDIR="$SRCDIR" + fi +fi +if [ ! -d "$BUILDDIR" ] ; then + die "Invalid \$BUILDDIR=\"$BUILDDIR\"" +fi + +export TESTDIR="$(dirname "$TEST")" +export SRCDIR +export BUILDDIR + +if [ "$VALGRIND" = y ] ; then + export NFT_TEST_UNDER_VALGRIND=1 +fi + +run_unit() { + local TEST="$1" + + if [ "$NFT_TEST_MAKE" = y ] ; then + local d="$(readlink -f "$BUILDDIR")" + local tf="$(readlink -f "$TEST")" + local t="${tf#$d/}" + + if [ "$tf" != "$d/$t" ] ; then + die "Cannot detect paths for making \"$TEST\" in \"$BUILDDIR\" (\"$d\" and \"$t\")" + fi + # Don't use "make -C" to avoid the extra "Entering/Leaving directory" messages + (cd "$d" && make "$t" ) || die "Making \"$TEST\" failed" + fi + + if [ "$VALGRIND" != y ] ; then + rc_test=0 + $NFT_TEST_UNSHARE_CMD \ + libtool \ + --mode=execute \ + $NFT_TEST_WRAPPER \ + "$TEST" || rc_test=$? + if [ "$rc_test" -ne 0 -a "$rc_test" -ne 77 ] ; then + die "exec \"$TEST\" failed with exit code $rc_test" + fi + exit "$rc_test" + fi + + LOGFILE="$TEST.valgrind-log" + + rc_test=0 + $NFT_TEST_UNSHARE_CMD \ + libtool \ + --mode=execute \ + valgrind \ + --quiet \ + --error-exitcode=122 \ + --leak-check=full \ + --gen-suppressions=all \ + --num-callers=100 \ + --log-file="$LOGFILE" \ + --vgdb-prefix="${TMP:-/tmp}/vgdb-pipe-nft-test-runner-$TIMESTAMP-$$" \ + $NFT_TEST_VALGRIND_OPTS \ + "$TEST" \ + || rc_test=$? + + if [ -s "$LOGFILE" ] ; then + if [ "$rc_test" -eq 0 -o "$rc_test" -eq 122 ] ; then + echo "valgrind failed. Logfile at \"$LOGFILE\" :" + cat "$LOGFILE" + rc_test=122 + else + echo "valgrind also failed. Check logfile at \"$LOGFILE\"" + fi + elif [ ! -f "$LOGFILE" ] ; then + echo "valgrind logfile \"$LOGFILE\" missing" + if [ "$rc_test" -eq 0 ] ; then + rc_test=122 + fi + else + rm -rf "$LOGFILE" + fi + + exit "$rc_test" +} + +case "$TEST" in + tests/unit/test-* | \ + */tests/unit/test-* ) + run_unit "$TEST" + ;; + *) + die "Unrecognized test \"$TEST\"" + ;; +esac