Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2232298/?format=api
{ "id": 2232298, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2232298/?format=api", "web_url": "http://patchwork.ozlabs.org/project/ltp/patch/20260504-fix_clock_settime_helper-v4-1-403149f43d30@suse.com/", "project": { "id": 59, "url": "http://patchwork.ozlabs.org/api/1.1/projects/59/?format=api", "name": "Linux Test Project development", "link_name": "ltp", "list_id": "ltp.lists.linux.it", "list_email": "ltp@lists.linux.it", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260504-fix_clock_settime_helper-v4-1-403149f43d30@suse.com>", "date": "2026-05-04T09:39:51", "name": "[v4] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "62d51f4c3b1bf3e28fccbc2fb2f4f62e710f19e8", "submitter": { "id": 83220, "url": "http://patchwork.ozlabs.org/api/1.1/people/83220/?format=api", "name": "Andrea Cervesato", "email": "andrea.cervesato@suse.de" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/ltp/patch/20260504-fix_clock_settime_helper-v4-1-403149f43d30@suse.com/mbox/", "series": [ { "id": 502632, "url": "http://patchwork.ozlabs.org/api/1.1/series/502632/?format=api", "web_url": "http://patchwork.ozlabs.org/project/ltp/list/?series=502632", "date": "2026-05-04T09:39:51", "name": "[v4] clock_settime: use POSIX runtime detection for CLOCK_MONOTONIC", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/502632/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2232298/comments/", "check": "fail", "checks": "http://patchwork.ozlabs.org/api/patches/2232298/checks/", "tags": {}, "headers": { "Return-Path": "<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "ltp@lists.linux.it" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "ltp@picard.linux.it" ], "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256\n header.s=susede2_rsa header.b=H2P57aH8;\n\tdkim=fail reason=\"signature verification failed\" header.d=suse.de\n header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519\n header.b=OYm09T1f;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key)\n header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa\n header.b=H2P57aH8;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=OYm09T1f;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=213.254.12.146; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)", "smtp-out1.suse.de;\n dkim=pass header.d=suse.de header.s=susede2_rsa header.b=H2P57aH8;\n dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=OYm09T1f" ], "Received": [ "from picard.linux.it (picard.linux.it [213.254.12.146])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g8GpD03v2z1y04\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 19:40:03 +1000 (AEST)", "from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id 764B33E6039\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 4 May 2026 11:40:01 +0200 (CEST)", "from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id 449A13E28D7\n for <ltp@lists.linux.it>; Mon, 4 May 2026 11:39:58 +0200 (CEST)", "from smtp-out1.suse.de (smtp-out1.suse.de\n [IPv6:2a07:de40:b251:101:10:150:64:1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 2753860075F\n for <ltp@lists.linux.it>; Mon, 4 May 2026 11:39:55 +0200 (CEST)", "from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out1.suse.de (Postfix) with ESMTPS id A4C266A81B;\n Mon, 4 May 2026 09:39:54 +0000 (UTC)", "from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 834E3593A3;\n Mon, 4 May 2026 09:39:54 +0000 (UTC)", "from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id sJHnHWpp+GnsLgAAD6G6ig\n (envelope-from <andrea.cervesato@suse.de>); Mon, 04 May 2026 09:39:54 +0000" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1777887594;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=RSrsWlizHCaS/5yvP8VnOcDAUmTCTY4p5i4pdcAcP4k=;\n b=H2P57aH8fStTfM83YUuzkj31SywPLKEQ2XPKRQXh5gHKde1yyu3XbQBhdUZkov5guoF9UO\n yfnPbcogWcNnWH3Rni9mYtQUTQmDpXxhlQC21xq7AQUjmSi08+g/xv1NvQC93lgIWb54dk\n l0WnXBGFvk/JN6r3c3uODLGgTkOCsd0=", "v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1777887594;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=RSrsWlizHCaS/5yvP8VnOcDAUmTCTY4p5i4pdcAcP4k=;\n b=OYm09T1fjPiMEka+1GeVGDZrbaaOtyNSwMDBDR04JeWhE9XxemVOA17QGhp2DkOMAR7QYb\n IJa8QZH7MckwusCA==", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1777887594;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=RSrsWlizHCaS/5yvP8VnOcDAUmTCTY4p5i4pdcAcP4k=;\n b=H2P57aH8fStTfM83YUuzkj31SywPLKEQ2XPKRQXh5gHKde1yyu3XbQBhdUZkov5guoF9UO\n yfnPbcogWcNnWH3Rni9mYtQUTQmDpXxhlQC21xq7AQUjmSi08+g/xv1NvQC93lgIWb54dk\n l0WnXBGFvk/JN6r3c3uODLGgTkOCsd0=", "v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1777887594;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=RSrsWlizHCaS/5yvP8VnOcDAUmTCTY4p5i4pdcAcP4k=;\n b=OYm09T1fjPiMEka+1GeVGDZrbaaOtyNSwMDBDR04JeWhE9XxemVOA17QGhp2DkOMAR7QYb\n IJa8QZH7MckwusCA==" ], "From": "Andrea Cervesato <andrea.cervesato@suse.de>", "Date": "Mon, 04 May 2026 11:39:51 +0200", "MIME-Version": "1.0", "Message-Id": "<20260504-fix_clock_settime_helper-v4-1-403149f43d30@suse.com>", "X-B4-Tracking": "v=1; b=H4sIAGZp+GkC/43OTQ7CIBAF4KsY1mIQCD+uvIdpmkqnQmxLA0g0T\n e8u7UY3Ji5fMvO9N6MIwUFEp92MAmQXnR9L4PsdMrYZb4BdWzKihArCqcade9am9+ZeR0jJDVB\n b6CcIWApJJFHQat6h8j4FKLcbfalK7oIfcLIBmm9Q/QYzxUdMhTHArrKVRJzjI8LB+GHlrYvJh\n 9c2PLO15I+NmW0kUYbpVnGtP2S1LMsbDcSdDQ4BAAA=", "X-Change-ID": "20260429-fix_clock_settime_helper-7670708ed94f", "To": "Linux Test Project <ltp@lists.linux.it>", "X-Mailer": "b4 0.14.2", "X-Developer-Signature": "v=1; a=ed25519-sha256; t=1777887594; l=8633;\n i=andrea.cervesato@suse.com; s=20251210; h=from:subject:message-id;\n bh=xvFqvMhfNt11XV3hmMjilLczt/uB/iNninRzLcH52Fk=;\n b=lSGwV6qSfE+N0v32/NMUpuVqauILv72iOCuwY4LYzKYYimk/2x0+4FlP0fUSvOdq1VOU8crWy\n FpZEI+7/YZLBq6dGODhk9mtfu+RWGH9lhiGXSsiHeROPI+2t1vZwZRe", "X-Developer-Key": "i=andrea.cervesato@suse.com; a=ed25519;\n pk=zKY+6GCauOiuHNZ//d8PQ/UL4jFCTKbXrzXAOQSLevI=", "X-Spamd-Result": "default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000];\n R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[];\n DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com];\n RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+];\n TO_DN_ALL(0.00)[]; FROM_HAS_DN(0.00)[];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[];\n TO_MATCH_ENVRCPT_ALL(0.00)[];\n DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n DKIM_TRACE(0.00)[suse.de:+]; RCVD_VIA_SMTP_AUTH(0.00)[];\n RCVD_TLS_ALL(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim, suse.com:mid, suse.com:email,\n imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns]", "X-Rspamd-Action": "no action", "X-Spam-Score": "-4.51", "X-Spam-Level": "", "X-Rspamd-Server": "rspamd1.dmz-prg2.suse.org", "X-Rspamd-Queue-Id": "A4C266A81B", "X-Spam-Status": "No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no\n autolearn=disabled version=4.0.1", "X-Spam-Checker-Version": "SpamAssassin 4.0.1 (2024-03-25) on in-5.smtp.seeweb.it", "X-Virus-Scanned": "clamav-milter 1.0.9 at in-5.smtp.seeweb.it", "X-Virus-Status": "Clean", "Subject": "[LTP] [PATCH v4] clock_settime: use POSIX runtime detection for\n CLOCK_MONOTONIC", "X-BeenThere": "ltp@lists.linux.it", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "Linux Test Project <ltp.lists.linux.it>", "List-Unsubscribe": "<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>", "List-Archive": "<http://lists.linux.it/pipermail/ltp/>", "List-Post": "<mailto:ltp@lists.linux.it>", "List-Help": "<mailto:ltp-request@lists.linux.it?subject=help>", "List-Subscribe": "<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it", "Sender": "\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>" }, "content": "From: Andrea Cervesato <andrea.cervesato@suse.com>\n\nThe clock_settime helpers.h used a compile-time #ifdef on\n_POSIX_MONOTONIC_CLOCK to select between real and stub\nimplementations of pts_mono_time_start()/pts_mono_time_check().\n\nOn Linux/glibc, _POSIX_MONOTONIC_CLOCK is defined as 0, meaning\nsupport is optional and must be verified at runtime via\nsysconf(_SC_MONOTONIC_CLOCK). The #ifdef treated 0 the same as\n>0 (always available), which is not POSIX-correct.\n\nReplace the compile-time #ifdef/#else split with a runtime\npts_mono_available() helper that performs proper POSIX detection\nvia sysconf(). Extract pts_mono_available() into the shared\ninclude/clock.h so it can be reused by nanosleep helpers as well.\nAlso add a missing #ifndef include guard and #include <unistd.h>\nso _POSIX_MONOTONIC_CLOCK is always defined.\n\nFixes: 9ecb4a004b18 (\"clock_settime: Detect external clock adjustments via CLOCK_MONOTONIC\")\nSigned-off-by: Andrea Cervesato <andrea.cervesato@suse.com>\n---\nChanges in v4:\n- verify that CLOCK_MONOTONIC exists vs _POSIX_MONOTONIC_CLOCK\n- Link to v3: https://lore.kernel.org/r/20260429-fix_clock_settime_helper-v3-1-2608c39d8499@suse.com\n---\n .../conformance/interfaces/clock_settime/4-1.c | 1 +\n .../conformance/interfaces/clock_settime/5-1.c | 1 +\n .../conformance/interfaces/clock_settime/5-2.c | 1 +\n .../conformance/interfaces/clock_settime/7-1.c | 1 +\n .../conformance/interfaces/clock_settime/7-2.c | 1 +\n .../conformance/interfaces/clock_settime/helpers.h | 56 +---------------\n testcases/open_posix_testsuite/include/clock.h | 77 ++++++++++++++++++++++\n 7 files changed, 85 insertions(+), 53 deletions(-)\n\n\n---\nbase-commit: 73cfad509db014e5a631bd2298f4e9d8ea3ee1c1\nchange-id: 20260429-fix_clock_settime_helper-7670708ed94f\n\nBest regards,", "diff": "diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-1.c\nindex 631aad7debb242df88bd3493319a82add7e9f0e9..ebd609963a3651212447ff2ab0885e20b19ba302 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-1.c\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/4-1.c\n@@ -28,6 +28,7 @@\n #include <signal.h>\n #include <unistd.h>\n #include \"posixtest.h\"\n+#include \"clock.h\"\n #include \"helpers.h\"\n \n // SLEEPTIME < TIMEROFFSET\ndiff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-1.c\nindex ff8660f18e73df472463ebd7316a436402b1b6ba..06023036cf4c704c43ec64cfaed75157973f3524 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-1.c\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-1.c\n@@ -23,6 +23,7 @@\n #include <unistd.h>\n #include <stdlib.h>\n #include \"posixtest.h\"\n+#include \"clock.h\"\n #include \"helpers.h\"\n \n #define TIMERSEC 5\ndiff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-2.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-2.c\nindex de1a8e422f86e2cd71e8237fe77d5083f541b599..bb4e86c2fef77e75f9216c7fe59930d71e5715a0 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-2.c\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/5-2.c\n@@ -23,6 +23,7 @@\n #include <unistd.h>\n #include <stdlib.h>\n #include \"posixtest.h\"\n+#include \"clock.h\"\n #include \"helpers.h\"\n \n #define TIMERSEC 5\ndiff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-1.c\nindex 7009b38b42a730a3526724c14843f1656a16d30a..0ed40fe612506d5a571003d4d9b592a3faab608c 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-1.c\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-1.c\n@@ -24,6 +24,7 @@\n #include <unistd.h>\n #include <sys/wait.h>\n #include \"posixtest.h\"\n+#include \"clock.h\"\n #include \"helpers.h\"\n \n #define SLEEPOFFSET 5\ndiff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-2.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-2.c\nindex 6713369be4c31c4076a493a224a85f24b5120a83..6162152e574e51cfce095b518314132d331ee68f 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-2.c\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/7-2.c\n@@ -23,6 +23,7 @@\n #include <unistd.h>\n #include <sys/wait.h>\n #include \"posixtest.h\"\n+#include \"clock.h\"\n #include \"helpers.h\"\n \n #define SLEEPOFFSET 5\ndiff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h\nindex 37bf30926f039553e9e370751b7938ca5ea1d00a..c559c189c163d7f7e1fb995b0806933504b278ab 100644\n--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h\n+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h\n@@ -13,7 +13,8 @@\n * by those tests.\n */\n \n-#include <stdlib.h>\n+#ifndef CLOCK_SETTIME_HELPERS_H\n+#define CLOCK_SETTIME_HELPERS_H\n \n static int getBeforeTime(struct timespec *tpget)\n {\n@@ -35,55 +36,4 @@ static int setBackTime(struct timespec tpset)\n \treturn PTS_PASS;\n }\n \n-#define PTS_MONO_MAX_RETRIES 3\n-\n-#ifdef _POSIX_MONOTONIC_CLOCK\n-static struct timespec _pts_mono_start;\n-\n-static inline int pts_mono_time_start(void)\n-{\n-\tif (clock_gettime(CLOCK_MONOTONIC, &_pts_mono_start) != 0) {\n-\t\tperror(\"clock_gettime(CLOCK_MONOTONIC) failed\");\n-\t\treturn -1;\n-\t}\n-\treturn 0;\n-}\n-\n-static inline int pts_mono_time_check(unsigned int expected_secs)\n-{\n-\tstruct timespec now;\n-\tlong elapsed;\n-\n-\tif (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {\n-\t\tperror(\"clock_gettime(CLOCK_MONOTONIC) failed\");\n-\t\treturn -1;\n-\t}\n-\n-\telapsed = now.tv_sec - _pts_mono_start.tv_sec;\n-\n-\tif (labs(elapsed - (long)expected_secs) > 1) {\n-\t\tprintf(\"Clock adjustment detected (elapsed %lds, expected ~%us)\\n\",\n-\t\t elapsed, expected_secs);\n-\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-#else\n-static inline int pts_mono_time_start(void)\n-{\n-\tstatic int warned;\n-\n-\tif (!warned) {\n-\t\tprintf(\"CLOCK_MONOTONIC unavailable, test may fail due to clock adjustment\\n\");\n-\t\twarned = 1;\n-\t}\n-\treturn 0;\n-}\n-\n-static inline int pts_mono_time_check(unsigned int expected_secs)\n-{\n-\t(void)expected_secs;\n-\treturn 0;\n-}\n-#endif\n-\n+#endif /* CLOCK_SETTIME_HELPERS_H */\ndiff --git a/testcases/open_posix_testsuite/include/clock.h b/testcases/open_posix_testsuite/include/clock.h\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..9a97270cdc7a5ea5c5f52adc5a253eb55912d1aa\n--- /dev/null\n+++ b/testcases/open_posix_testsuite/include/clock.h\n@@ -0,0 +1,77 @@\n+/*\n+ * Copyright (c) 2026, Linux Test Project\n+ * SPDX-License-Identifier: GPL-2.0-or-later\n+ */\n+\n+#ifndef PTS_CLOCK_H\n+#define PTS_CLOCK_H\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <time.h>\n+#include <unistd.h>\n+\n+static inline int pts_mono_available(void)\n+{\n+#ifdef CLOCK_MONOTONIC\n+\tif (_POSIX_MONOTONIC_CLOCK > 0)\n+\t\treturn 1;\n+\n+\tif (!_POSIX_MONOTONIC_CLOCK && sysconf(_SC_MONOTONIC_CLOCK) > 0)\n+\t\treturn 1;\n+#endif\n+\treturn 0;\n+}\n+\n+#define PTS_MONO_MAX_RETRIES 3\n+\n+static struct timespec pts_mono_start;\n+\n+static inline int pts_mono_time_start(void)\n+{\n+\tif (!pts_mono_available()) {\n+\t\tstatic int warned;\n+\n+\t\tif (!warned) {\n+\t\t\tprintf(\"CLOCK_MONOTONIC unavailable, test may fail due to clock adjustment\\n\");\n+\t\t\twarned = 1;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\n+#ifdef CLOCK_MONOTONIC\n+\tif (clock_gettime(CLOCK_MONOTONIC, &pts_mono_start) != 0) {\n+\t\tperror(\"clock_gettime(CLOCK_MONOTONIC) failed\");\n+\t\treturn -1;\n+\t}\n+#endif\n+\treturn 0;\n+}\n+\n+static inline int pts_mono_time_check(unsigned int expected_secs)\n+{\n+#ifdef CLOCK_MONOTONIC\n+\tif (pts_mono_available()) {\n+\t\tstruct timespec now;\n+\t\tlong elapsed;\n+\n+\t\tif (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {\n+\t\t\tperror(\"clock_gettime(CLOCK_MONOTONIC) failed\");\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\telapsed = now.tv_sec - pts_mono_start.tv_sec;\n+\n+\t\tif (labs(elapsed - (long)expected_secs) > 1) {\n+\t\t\tprintf(\"Clock adjustment detected (elapsed %lds, expected ~%us)\\n\",\n+\t\t\t elapsed, expected_secs);\n+\t\t\treturn 1;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+#endif\n+\t(void)expected_secs;\n+\treturn 0;\n+}\n+\n+#endif /* PTS_CLOCK_H */\n", "prefixes": [ "v4" ] }