Skip to content

Commit 3f2bf7c

Browse files
committed
test: parse WSL kernel version without error
The WSL kernel version is not SemVer compliant, e.g. '6.6.87.1- microsoft-standard-WSL2', which causes a version check error during the io_uring test. This commit modifies the version check function to extract the SemVer-compliant part of the WSL kernel version.
1 parent 0cbff2f commit 3f2bf7c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/std/os/linux/IoUring.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4065,7 +4065,22 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void {
40654065
const release = mem.sliceTo(&uts.release, 0);
40664066
// Strips potential extra, as kernel version might not be semver compliant, example "6.8.9-300.fc40.x86_64"
40674067
const extra_index = std.mem.indexOfAny(u8, release, "-+");
4068-
const stripped = release[0..(extra_index orelse release.len)];
4068+
4069+
// Also strips the string after the third dot because examples exist such as "6.6.87.1-microsoft-standard-WSL2"
4070+
var dot_count: usize = 0;
4071+
var index: usize = 0;
4072+
var third_dot_index: ?usize = null;
4073+
while (std.mem.indexOfScalar(u8, release[index..], '.')) |addend| {
4074+
index += addend;
4075+
dot_count += 1;
4076+
if (dot_count == 3) {
4077+
third_dot_index = index;
4078+
break;
4079+
}
4080+
index += 1;
4081+
}
4082+
4083+
const stripped = release[0..(@min(extra_index orelse release.len, third_dot_index orelse release.len))];
40694084
// Make sure the input don't rely on the extra we just stripped
40704085
try testing.expect(required.pre == null and required.build == null);
40714086

0 commit comments

Comments
 (0)