lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251219092537.1227513-1-davidgow@google.com>
Date: Fri, 19 Dec 2025 17:25:36 +0800
From: David Gow <davidgow@...gle.com>
To: Brendan Higgins <brendan.higgins@...ux.dev>, Rae Moar <raemoar63@...il.com>, 
	Gary Guo <gary@...yguo.net>, Miguel Ojeda <ojeda@...nel.org>, 
	Shuah Khan <skhan@...uxfoundation.org>, Guillaume Gomez <guillaume1.gomez@...il.com>
Cc: David Gow <davidgow@...gle.com>, linux-kselftest@...r.kernel.org, 
	kunit-dev@...glegroups.com, rust-for-linux@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH] rust: doctests: Number tests by line numerically, not lexicographically.

The rust doctests are numbered -- instead of named with the line number
-- in order to keep them moderately consistent even as the source file
changes.

However, the test numbers are generated by sorting the file/line
strings, and so the line numbers were sorted as strings, not integers.
So, for instance, a test on line 7 would sort in-between one on line 65
and one on line 75.

Instead, parse the numbers as an integer, and sort based on that. This
is a bit slower, uglier, and will break things once, but I suspect is
worth it (at least until we have a better solution).

Signed-off-by: David Gow <davidgow@...gle.com>
---

This is a pretty unpolished, likely-unidiomatic patch to work around the
test numbering being horrible.

I have three questions before I decide if this is worth continuing with:

1. Is it worth renumbering all of the tests (hopefully just once), or
would that break too many people's test histories?

2. Is there a better way of doing this in Rust? I can think of ways
which might be nicer if the whole thing is refactored somewhat
seriously, but if there's an easy numeric sort on strings, that'd be
much easier.

3. Should we wait until after all or some of the changes to the test
generation? Does the new --output-format=doctest option make this
easier/harder/different?

Does anyone have opinions/advice on those (or, indeed, on anything
else)?

Cheers,
-- David

---
 scripts/rustdoc_test_gen.rs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index be0561049660..60b0bbfb1896 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -116,7 +116,19 @@ fn main() {
         .collect::<Vec<_>>();
 
     // Sort paths.
-    paths.sort();
+    paths.sort_by(|a, b|{
+        let a_name = a.file_name().unwrap().to_str().unwrap().to_string();
+        let (a_file, a_line) = a_name.rsplit_once('_').unwrap().0.rsplit_once('_').unwrap();
+        let a_line_no = a_line.parse::<u64>().unwrap();
+        let b_name = b.file_name().unwrap().to_str().unwrap().to_string();
+        let (b_file, b_line) = b_name.rsplit_once('_').unwrap().0.rsplit_once('_').unwrap();
+        let b_line_no = b_line.parse::<u64>().unwrap();
+
+        match a_file.cmp(b_file) {
+            std::cmp::Ordering::Equal => a_line_no.cmp(&b_line_no),
+            order => order,
+        }
+    });
 
     let mut rust_tests = String::new();
     let mut c_test_declarations = String::new();
-- 
2.52.0.322.g1dd061c0dc-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ