Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126131 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id D82961A00BD for ; Mon, 16 Dec 2024 20:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1734379347; bh=t9ujxHVxuWDJe5A2+EWMjaVz7CzCgULHaviHBzAW1RA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jMB1EmAZQC+C5+KLbXxuUNToE9hkb+UD+DOdrlPiyJgBrQZ4Id9EzsSFofs6NQ8sM HLcUCJksEUrwqeA49D7ot8FR5PSd4Va3jJRvJnjT1PhKBTxTCccFX17F/LcWltIs3w KMjFbjgLQYA2vtsWyX8MP8oYcxlA8qaCmfrV9/jIUUW7p2d1o2aEemtW5CGLyLLK8B Jpvyy5wGG2xB9rnb2fR0NUQA3UeYraH7P8qfowS6TVsKd/2rXwTIV771rETzEd8fyi osZdyhtiL6Vt76TOH6squVACnz9OQhGPfg0b3o39Gzpz86JpuhOGWpQcuRpWo+z3zB sdBmi4hpyDqtQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 132E2180077; Mon, 16 Dec 2024 20:02:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS; Mon, 16 Dec 2024 20:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1734379528; x=1734984328; i=cmbecker69@gmx.de; bh=mOo5wXJvjUvP+m18KmZpyeL7jwaQmP4kv5x/yY9m7s8=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=inYXjA84+HPtILmIaieuwxSLckU8g9v9iCor1dIgJCA+fKX8oOJ5ZA5uhB8hp8xP qqKzKbDL52hwn96I/FbZOTDeMpXQ0yecPBROuolCg070hNZlRHfuHDqNI5H66dou6 8rrOiz4iserNfVaMdTTRD/ki/BcoT5wGkzGpqfIZqfqPhQrZNWX7B16445ipw34tu gBOiz0bjEYjuKjr3qACOSShawUOWn5X3pJpQVKSjTO9accmMtLOjoGoVHNwY8y3vQ UKpY5pc4WtWy8oZ7APb4mcPU/j0BQ/M2iEoTdRl6HSnQwxlwGcij7JXYn/ui/rWyL nZxwMB1mxnSB0oeXvg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.2.130] ([79.220.91.186]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpDJd-1tw7Cp0y7T-00cq9g; Mon, 16 Dec 2024 21:05:28 +0100 Message-ID: <7228b901-a6a9-4aa9-8425-5ad51f66a853@gmx.de> Date: Mon, 16 Dec 2024 21:05:28 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] C Unit testing and mocking Content-Language: de-DE To: Jakub Zelenka , PHP internals list References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:7QzzULRgeuFpOprZlfGmEWWiXogTyi3Ivl6ow85hgUMqzqOAb+J ZjjcBHuD+8AHYskL9XskW6OcAsmzJEhGBXMz4F1OidmwfEe4N35mYQ6PTH1d2hyyMOkpWr4 8vjpi6JZCg5GPvl8AtQ985r8hWqazK/tYDRDHpVNJS9lZlObReBHxqiv6DO0VskeE11bq3J YdsfsHaRkScE+rUop3jDg== UI-OutboundReport: notjunk:1;M01:P0:mhtXuG90k1M=;T45EyUtWhVWX/MM3jyR8U8ajR6i /CHRiZzHVpkWREyhFYP7XkleiIJBkuNojtInh5vxNxViC6xtuZYt7hiSfXQFj2brRBnMkWKZX 3XYh5IK0cdiq6nqyS5fOrZJFjRwVcQJAXZi0JErkY6pADmhM6/SrJe+2tJFcpaQm+WDLL72zM 4NZfln5k1cbPyFA2Ffv+c17oPqCU2aStnHuf7gNdfqq7+MqOIjZbS1vpBL5fH2jAbVeLnV0LE PLa72ZEBgizTUJM+KMuYAfTMEnKo/hleOE64vFWBTxEtoq7HR3OfjTtWE3fpKOr4xZJjeqB8O zCgM2pBv1luDaAi+fFPGFV8LewD71XXlC3vcMl/40MW7yKpI2Y8wtXRLZ1us+eJpEFtjJLOfn MWkY6eGEkUg1sVUZ8rZC+IC7pROcc71elTSLAxQWhuKvgc8W20nBOiSfaofq5l5ShXnd+jmZp +l/y+9Qk48opf2PaWFhQSiOZ35spAMGgXQKKs8//b0oLfJxiuVzlJZt0/FZkk9h6eUoE+rv2L 3MxE+brXpN/k98jKjtwTJinKzcfU+vFzOZkDDgRS1OPDSgGoE/FFzV56rmeVBsNXyppwGvoLk GmMxUHW7NKGSJJoP1zan3/sG8ralVO3pM26ktX3B/bCJnRGJlqp1YToJnnFcDhCVeYtE6AsgH eBHY2vUn1JrdzqFbF+hY6I4h0Ac04wjt+noVgd5OcHu+BSsrYhgTFjOQYuvnMrBLof54rZxs3 /Dy4k4fL36gHFvvCWCoqXZ5raqDzTlPSalG1JBSJ5ocIQiv9cD3lDJoNfR/ON6Ry2bOSUiWYQ CoYLti6wNzZXM71WtKUpJkC4Wh1H9wiy4u9jNZ0Te7NZSg1cAtGwZFsls2g+Q1cVCboHTvgZG IUokiqB0Al0mpSVcUpUK8wE2geDhb+DPfEd1+qCypBhu+C0hUYY6tOpUgA2nofIvXyXcP2u3z DGH8Mhn9PBSFTNv/wOeRmdeDLCzVDihW0xvk5NqIEG9f9D9zAsVC4fC5BdjUset5j8e9TS7fO WeLmKKYlbl2obbVSMOR4iayxNpautU3yCBldteJRKCPlQU7AAKNPNa1zcbtbwHhpmWE+XX4Rm +3phXg82SEov4qxfbxodCLJ2DPm1MgEkC9yt49Oh/XwTsJxSuB3dR58oV59GIegFl9n8b68SY = From: cmbecker69@gmx.de ("Christoph M. Becker") On 16.12.2024 at 14:18, Jakub Zelenka wrote: > I have been looking into how to test some cases where integration tests are > very difficult or even impossible to create for. Those are often found in > networking related and system specific code code (network.c, streams, FPM > and more). I was recently fixing one such bug and decided to give a try > which resulted in this PR: https://github.com/php/php-src/pull/16987 . It makes sense to me to have some unit tests for code which is otherwise hard or even impossible to test via integration tests. > There was a suggestion of RFC but that might be a bit too much as it's just > an internal change / addition. But certainly some overview on internals > should be done so writing this instead. I'm fine with not going through the RFC process, although the policy[1] police might come after us. :) > I decided to use cmocka in that PR because I had some experience with that. > It's quite small and still very powerful and allow vast mocking options. > It's a bit manual but it gives a bigger control over the mock. It relies on > --wrap linking option that replaces original functions with wraps. This is > however available only on Linux (or maybe some other Unix variants) but > doesn't work on MacOS or Windows. The developers that want to use it on > those platforms would need to use some Linux Virtualisation option (e.g. > Docker). Especially on Windows, where we have different code paths, and sometimes even completely different code, it would be great to also have these unit tests. Given that link.exe supports /alternatename, a bit of additional macro magic might do the trick[2]. I'll try to have a stab at this soon. > I did also some research into the other mocking libraries in C. Thank you! I barely have any experience with unit testing in C (only one time, long ago, wrote part of unit test for timelib which is using Cpputest), but from a cursory glance cmocka appears to be suitable for our purposes. > In terms of CI. It has got its own build which is very simple and it tests > just specific parts so we could just limit it to run only for changed files > which might be quite convenient. If the tests won't take long, in my opinion we could run them for every push. Or at least in nightly (plus when relevant files changed), to avoid that the suite doesn't run for a long time (possibly weeks), and then suddenly is broken for external reasons. [1] [2] Christoph