[PATCH] ktest: Sort config keys before writing config files

From: Ricardo B. Marlière (SUSE)

Date: Wed Oct 14 2026 - 14:05:55 EST


apply_min_config(), save_config(), and make_min_config() write CONFIG_*
lines by iterating "keys %hash" with no sort. Perl randomizes hash
iteration order per process by default, so the line order of the resulting
config files is not reproducible across otherwise identical invocations.

When two of those lines are mutually exclusive members of the same Kconfig
"choice", this can change which one "make olddefconfig" keeps,
nondeterministically, from run to run. Observed with
CONFIG_DEBUG_INFO_DWARF5 vs CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT: five
consecutive "-C" builds from identical ADD_CONFIG/MIN_CONFIG inputs
alternated between the two, which is enough to force a near-complete
rebuild each time since CONFIG_DEBUG_INFO_* affects every object's compile
flags.

Sort the keys before writing so the same inputs always produce the same
config output.

Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@xxxxxxxxxxxx>
---
tools/testing/ktest/ktest.pl | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index f94ed2e98887..1945f6ee2483 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -2652,7 +2652,7 @@ sub apply_min_config {
}
close IN;
}
- foreach my $config (keys %force_config) {
+ foreach my $config (sort keys %force_config) {
print OUT "$force_config{$config}\n";
}
close OUT;
@@ -3325,7 +3325,7 @@ sub save_config {

open(OUT, ">$file") or dodie "Can not write to $file";

- foreach my $config (keys %configs) {
+ foreach my $config (sort keys %configs) {
print OUT "$configs{$config}\n";
}
close(OUT);
@@ -4137,7 +4137,7 @@ sub make_min_config {
if (defined($ignore_config)) {
open (OUT, ">$temp_config") or
dodie "Can't write to $temp_config";
- foreach my $config (keys %save_configs) {
+ foreach my $config (sort keys %save_configs) {
print OUT "$save_configs{$config}\n";
}
close OUT;
@@ -4165,10 +4165,10 @@ sub make_min_config {
# Save off all the current mandatory configs
open (OUT, ">$temp_config") or
dodie "Can't write to $temp_config";
- foreach my $config (keys %keep_configs) {
+ foreach my $config (sort keys %keep_configs) {
print OUT "$keep_configs{$config}\n";
}
- foreach my $config (keys %min_configs) {
+ foreach my $config (sort keys %min_configs) {
print OUT "$min_configs{$config}\n";
}
close OUT;

---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20261014-ktest-kconfig-perl-hash-3070ab1a8383

Best regards,
--
Ricardo B. Marlière (SUSE) <ricardo@xxxxxxxxxxxx>