From patchwork Thu Feb 1 14:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3602 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6d86:b0:554:adf7:68e6 with SMTP id n6csp241654may; Thu, 1 Feb 2024 06:49:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXCNTc8zAM4AzXpqnEdWk8vWb0rvkbkmGMRASkwioveMlkfZXbGg1jPLaD+zxgTMn78f2yzXXFornUWVcTfwJRs44XF7f8= X-Google-Smtp-Source: AGHT+IGW0lOkXmBAuQKq29MolvPHuhzB3FP/8MQIiwNP1exurGMXvOAOpi46j4V4qBtjGxUSXCrD X-Received: by 2002:a17:90b:3889:b0:295:f13f:590e with SMTP id mu9-20020a17090b388900b00295f13f590emr2865259pjb.3.1706798945090; Thu, 01 Feb 2024 06:49:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706798945; cv=none; d=google.com; s=arc-20160816; b=aCtd57Qkr7UdDqmpwQcSXnpubVi0A3w9nNXWPe9dSN8vyacqF/sLCkMaXoh/xjZz7W /CUXpv9XgZHtu+2HFuHyET3oijWv+nBto64N3/06+J8eswsOuvXnHhFVuHXghdlhsdW1 vb4gtt0GdwPwxvEqGpZe5nsq3iHOFzWkgkl9kl49+MAZ5U70HyRJ0bcpQZg64MybdxZg vIXJE9XECpx/Lmesx10ebaWPPitCYNxqiyU28X+zLHDSlgLJWPGhjawr5KO2Kq1QEG5U V96GvAYwVER/PXHgYN6CKj1jdNsgqhgsJPrtkuYOICVpS0nIJUPaVaedVYZmrxOjihN2 IXNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=6RklL86N6dGCduDAxCqx8IR5mcp83PqCHBahzRs4Tng=; fh=YqBJ4a35MZHJAsENIL5wAlWFD6cBZF7HrC/8cvm55PQ=; b=frsDXZK8gxtl98p4W7p5cRw91octmNZxxZ7sYXDq7Q1wCjKZAiJIiKKaZF4GJ/1252 3l5RRfQSOuNG14xguWif5FC4rqWQDViUFyOFiQ/wsG4JJgP2g+wlp7JaSWGdDKDQnG5Z dWsS1tfXfkViTUVrcQr82O5xXUqupijONeNTnu/Mvudb6ePv8baR+cVDmL35rbGMu5kp G0IbPwPzyHhqle+2b6LR1GYrkU7PmyqkBBqzU8It46u58YtR8N9RjAG3x+mrVsmdpsEZ wgubdU5FspgjJVJYSIOmSjQL3JLB1YZm7T/7KYncVoeExSW1R5cwn90Tno6zXGEsleE/ d+rQ==; darn=openvpn.net ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=XCk8+LcH; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Dvo80Iad; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=SXD26fHP; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net X-Forwarded-Encrypted: i=0; AJvYcCUdbsrDY9DRF2vQEfCBGzR6fUt99/ue6CCJnsWAMRLTpjH7fIdinVwEfJ8IO7zRG7oZmvGr9mWq0wI17k4ZWmTrQG1w2KnCrCw+XrO6tPVtXTEAuQvfZmfWfqVL/D2Nr/NHns0/xbAmAymX73y06VVCPoRkmTA= Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id c8-20020a17090abf0800b00290fdc46084si3683207pjs.105.2024.02.01.06.49.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2024 06:49:05 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=XCk8+LcH; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Dvo80Iad; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=SXD26fHP; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rVYMq-0001DS-23; Thu, 01 Feb 2024 14:48:40 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rVYMn-0001DA-O0 for openvpn-devel@lists.sourceforge.net; Thu, 01 Feb 2024 14:48:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wLaHmZjyR7UdI4LTmYOhb+sOjLzDefY+OrAWz7/XSFo=; b=XCk8+LcH6jlVlCHTc126/llVY+ 3VUcWCU6b31eGcFWZfr1oFt5H4PHnbZz2oTgi7s5V8dJULEL494JBJaqbDCP83rIynYCDnKPiy/PJ MNfedNArFDvr/8btksHjJKPOPLXhi4Wthd9bECDqQTnlQcGTAGBkhFu5KqvHWweEN3ng=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wLaHmZjyR7UdI4LTmYOhb+sOjLzDefY+OrAWz7/XSFo=; b=Dvo80Iadpmyx5Yrr+4DNfUEczl Sx6xbEVFjiKAqn1wgXZownfqjzPuV0jJPMgsqVVNritXY4zqwjpIWRcW/gTO5D6+xPuqh4ETewipr EpCms6swdRBM2p6mSC9nDFj10TWjn8zwLjPHD5vsJkufT7N406LxQUQpPyu1hBKA3I64=; Received: from mout-p-202.mailbox.org ([80.241.56.172]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rVYMj-0005Rs-9m for openvpn-devel@lists.sourceforge.net; Thu, 01 Feb 2024 14:48:38 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TQhbl2wgDz9t4y; Thu, 1 Feb 2024 15:48:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1706798899; 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=wLaHmZjyR7UdI4LTmYOhb+sOjLzDefY+OrAWz7/XSFo=; b=SXD26fHP59VXpFEXHaD+7g90wUgQoa0yMwOuOWmvXtkUk16bNES70BGb/Gay7TWvRrgYx1 4ebM3Mw5jXrdEjbMsxwGho8WTjpNhI478tp6wfJTlp5ZbWCvAM9WCTC4sv+s3WD9Htcb0a dcw0rtST10NO1KLX+Qcj14X1NLZMcepD/fK+aATzb4EK7NXC5B99C90/YMHLtoTFhplxjq E0Bkux3XYWKU7tYfPhJj+re+LMpDaWc8r71KJ8GPPUeagTCy5H5axXO+bWbwnXqhM2R8Hl P7w6UOO17zgi8et0vi3t4PcxAfirv48OIKJeVruZrFuZ7IgAa5VpSniWZQMfKQ== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Thu, 1 Feb 2024 15:48:17 +0100 Message-Id: <20240201144817.188884-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Arne Schwabe Settings the environment variable required for running unit tests is tiresome in my IDE (Clion). So allow unit tests to fall back to a hard coded location in case the environment variable is not set. Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.172 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1rVYMj-0005Rs-9m Subject: [Openvpn-devel] [PATCH v1] [CMake] Allow unit tests to fall back to hard coded location X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1789708410536761984?= X-GMAIL-MSGID: =?utf-8?q?1789708410536761984?= From: Arne Schwabe Settings the environment variable required for running unit tests is tiresome in my IDE (Clion). So allow unit tests to fall back to a hard coded location in case the environment variable is not set. Change-Id: Ide72b81f497088dd0fd2cdcfff83cbce5b48f145 Acked-by: Frank Lichtenheld --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/509 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld diff --git a/CMakeLists.txt b/CMakeLists.txt index be55c60..fdd2b01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,6 +682,10 @@ target_include_directories(${test_name} PRIVATE src/openvpn) + # for compat with IDEs like Clion that ignore the tests properties + # for the environment variable srcdir when running tests as fallback + target_compile_definitions(${test_name} PRIVATE "-DUNIT_TEST_SOURCEDIR=\"${CMAKE_SOURCE_DIR}/tests/unit_tests/openvpn\"") + if (NOT ${test_name} STREQUAL "test_buffer") target_sources(${test_name} PRIVATE src/openvpn/buffer.c diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h index 50e16d6..f219e93 100644 --- a/tests/unit_tests/openvpn/test_common.h +++ b/tests/unit_tests/openvpn/test_common.h @@ -32,9 +32,36 @@ * This has a openvpn prefix to avoid confusion with cmocka's unit_test_setup_* * methods */ -void +static inline void openvpn_unit_test_setup() { assert_int_equal(setvbuf(stdout, NULL, _IONBF, BUFSIZ), 0); assert_int_equal(setvbuf(stderr, NULL, _IONBF, BUFSIZ), 0); } + +/** + * Helper function to get a file path from the unit test directory to open it + * or pass its path to another function. This function will first look for + * an environment variable or if failing that, will fall back to a hardcoded + * value from compile time if compiled with CMake. + * + * @param buf buffer holding the path to the file + * @param bufsize size of buf + * @param filename name of the filename to retrieve relative to the + * unit test source directory + */ +void +openvpn_test_get_srcdir_dir(char *buf, size_t bufsize, const char *filename) +{ + const char *srcdir = getenv("srcdir"); + +#if defined(UNIT_TEST_SOURCEDIR) + if (!srcdir) + { + srcdir = UNIT_TEST_SOURCEDIR; + } +#endif + assert_non_null(srcdir); + + snprintf(buf, bufsize, "%s/%s", srcdir, filename); +} diff --git a/tests/unit_tests/openvpn/test_user_pass.c b/tests/unit_tests/openvpn/test_user_pass.c index ab4dfe4..fee5891 100644 --- a/tests/unit_tests/openvpn/test_user_pass.c +++ b/tests/unit_tests/openvpn/test_user_pass.c @@ -35,6 +35,7 @@ #include #include #include +#include "test_common.h" #include "misc.c" @@ -209,11 +210,9 @@ reset_user_pass(&up); unsigned int flags = 0; - const char *srcdir = getenv("srcdir"); - assert_non_null(srcdir); char authfile[PATH_MAX] = { 0 }; + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_pass.txt" ); - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_pass.txt"); /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, authfile, "UT", flags, NULL)); @@ -223,7 +222,7 @@ reset_user_pass(&up); - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_only.txt"); + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_only.txt"); expect_string(query_user_exec_builtin, query_user[i].prompt, "Enter UT Password:"); will_return(query_user_exec_builtin, "cpassword"); will_return(query_user_exec_builtin, true); @@ -236,7 +235,7 @@ reset_user_pass(&up); flags |= GET_USER_PASS_PASSWORD_ONLY; - snprintf(authfile, PATH_MAX, "%s/%s", srcdir, "input/user_only.txt"); + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_only.txt"); /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, authfile, "UT", flags, NULL)); @@ -256,5 +255,6 @@ int main(void) { + openvpn_unit_test_setup(); return cmocka_run_group_tests(user_pass_tests, NULL, NULL); }