Skip to content

Commit 4283b16

Browse files
committed
ktest: Add make_warnings_file and process full warnings
Although the patchcheck test checks for warnings in the files that were changed, this check does not catch warnings that were caused by header file changes and the warnings appear in C files not touched by the commit. Add a new option called WARNINGS_FILE. If this option is set, then the file it points to is read before bulid, and the file should contain a list of known warnings. If a warning appears in the build, this file is checked, and if the warning does not exist in this file, then it fails the build showing the new warning. If the WARNINGS_FILE points to a file that does not exist, this will cause any warning in the build to fail. A new test is also added called "make_warnings_file". This test will create do a build and record any warnings it finds into the WARNINGS_FILE. This test is something that can be run before other tests to build a warnings file of "known warnings", ie, warnings that were there before your changes. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 04262be commit 4283b16

3 files changed

Lines changed: 185 additions & 6 deletions

File tree

‎tools/testing/ktest/examples/include/patchcheck.conf‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
PATCH_START := HEAD~3
1515
PATCH_END := HEAD
1616

17+
# Use the oldconfig if build_type wasn't defined
18+
DEFAULTS IF NOT DEFINED BUILD_TYPE
19+
DO_BUILD_TYPE := oldconfig
20+
21+
DEFAULTS ELSE
22+
DO_BUILD_TYPE := ${BUILD_TYPE}
23+
24+
DEFAULTS
25+
26+
1727
# Change PATCH_CHECKOUT to be the branch you want to test. The test will
1828
# do a git checkout of this branch before starting. Obviously both
1929
# PATCH_START and PATCH_END must be in this branch (and PATCH_START must
@@ -43,6 +53,31 @@ PATCH_TEST_TYPE := boot
4353
# (space delimited)
4454
#IGNORE_WARNINGS = 39eaf7ef884dcc44f7ff1bac803ca2a1dcf43544 6edb2a8a385f0cdef51dae37ff23e74d76d8a6ce
4555

56+
# Instead of just checking for warnings to files that are changed
57+
# it can be advantageous to check for any new warnings. If a
58+
# header file is changed, it could cause a warning in a file not
59+
# touched by the commit. To detect these kinds of warnings, you
60+
# can use the WARNINGS_FILE option.
61+
#
62+
# If the variable CREATE_WARNINGS_FILE is set, this config will
63+
# enable the WARNINGS_FILE during the patchcheck test. Also,
64+
# before running the patchcheck test, it will create the
65+
# warnings file.
66+
#
67+
DEFAULTS IF DEFINED CREATE_WARNINGS_FILE
68+
WARNINGS_FILE = ${OUTPUT_DIR}/warnings_file
69+
70+
TEST_START IF DEFINED CREATE_WARNINGS_FILE
71+
# WARNINGS_FILE is already set by the DEFAULTS above
72+
TEST_TYPE = make_warnings_file
73+
# Checkout the commit before the patches to test,
74+
# and record all the warnings that exist before the patches
75+
# to test are added
76+
CHECKOUT = ${PATCHCHECK_START}~1
77+
# Force a full build
78+
BUILD_NOCLEAN = 0
79+
BUILD_TYPE = ${DO_BUILD_TYPE}
80+
4681
# If you are running a multi test, and the test failed on the first
4782
# test but on, say the 5th patch. If you want to restart on the
4883
# fifth patch, set PATCH_START1. This will make the first test start
@@ -61,6 +96,7 @@ PATCHCHECK_TYPE = ${PATCH_TEST_TYPE}
6196
PATCHCHECK_START = ${PATCH_START1}
6297
PATCHCHECK_END = ${PATCH_END}
6398
CHECKOUT = ${PATCH_CHECKOUT}
99+
BUILD_TYPE = ${DO_BUILD_TYPE}
64100

65101
TEST_START IF ${TEST} == patchcheck && ${MULTI}
66102
TEST_TYPE = patchcheck
@@ -72,3 +108,4 @@ PATCHCHECK_END = ${PATCH_END}
72108
CHECKOUT = ${PATCH_CHECKOUT}
73109
# Use multi to test different compilers?
74110
MAKE_CMD = CC=gcc-4.5.1 make
111+
BUILD_TYPE = ${DO_BUILD_TYPE}

‎tools/testing/ktest/ktest.pl‎

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
my $output_minconfig;
127127
my $minconfig_type;
128128
my $use_output_minconfig;
129+
my $warnings_file;
129130
my $ignore_config;
130131
my $ignore_errors;
131132
my $addconfig;
@@ -193,6 +194,9 @@
193194
# which would require more options.
194195
my $buildonly = 1;
195196

197+
# tell build not to worry about warnings, even when WARNINGS_FILE is set
198+
my $warnings_ok = 0;
199+
196200
# set when creating a new config
197201
my $newconfig = 0;
198202

@@ -235,6 +239,7 @@
235239
"START_MIN_CONFIG" => \$start_minconfig,
236240
"MIN_CONFIG_TYPE" => \$minconfig_type,
237241
"USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
242+
"WARNINGS_FILE" => \$warnings_file,
238243
"IGNORE_CONFIG" => \$ignore_config,
239244
"TEST" => \$run_test,
240245
"ADD_CONFIG" => \$addconfig,
@@ -1924,7 +1929,60 @@ sub start_monitor_and_boot {
19241929
return monitor;
19251930
}
19261931

1932+
my $check_build_re = ".*:.*(warning|error|Error):.*";
1933+
my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1934+
1935+
# Read buildlog and check against warnings file for any
1936+
# new warnings.
1937+
#
1938+
# Returns 1 if OK
1939+
# 0 otherwise
19271940
sub check_buildlog {
1941+
return 1 if (!defined $warnings_file);
1942+
1943+
my %warnings_list;
1944+
1945+
# Failed builds should not reboot the target
1946+
my $save_no_reboot = $no_reboot;
1947+
$no_reboot = 1;
1948+
1949+
if (-f $warnings_file) {
1950+
open(IN, $warnings_file) or
1951+
dodie "Error opening $warnings_file";
1952+
1953+
while (<IN>) {
1954+
if (/$check_build_re/) {
1955+
chomp;
1956+
$warnings_list{$_} = 1;
1957+
}
1958+
}
1959+
close(IN);
1960+
}
1961+
1962+
# If warnings file didn't exist, and WARNINGS_FILE exist,
1963+
# then we fail on any warning!
1964+
1965+
open(IN, $buildlog) or dodie "Can't open $buildlog";
1966+
while (<IN>) {
1967+
if (/$check_build_re/) {
1968+
1969+
# Some compilers use UTF-8 extended for quotes
1970+
# for distcc heterogeneous systems, this causes issues
1971+
s/$utf8_quote/'/g;
1972+
1973+
chomp;
1974+
if (!defined $warnings_list{$_}) {
1975+
fail "New warning found (not in $warnings_file)\n$_\n";
1976+
$no_reboot = $save_no_reboot;
1977+
return 0;
1978+
}
1979+
}
1980+
}
1981+
$no_reboot = $save_no_reboot;
1982+
close(IN);
1983+
}
1984+
1985+
sub check_patch_buildlog {
19281986
my ($patch) = @_;
19291987

19301988
my @files = `git show $patch | diffstat -l`;
@@ -3080,11 +3138,13 @@ sub patchcheck {
30803138
build "oldconfig" or return 0;
30813139
}
30823140

3083-
3084-
if (!defined($ignored_warnings{$sha1})) {
3085-
check_buildlog $sha1 or return 0;
3141+
# No need to do per patch checking if warnings file exists
3142+
if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3143+
check_patch_buildlog $sha1 or return 0;
30863144
}
30873145

3146+
check_buildlog or return 0;
3147+
30883148
next if ($type eq "build");
30893149

30903150
my $failed = 0;
@@ -3642,6 +3702,39 @@ sub make_min_config {
36423702
return 1;
36433703
}
36443704

3705+
sub make_warnings_file {
3706+
my ($i) = @_;
3707+
3708+
if (!defined($warnings_file)) {
3709+
dodie "Must define WARNINGS_FILE for make_warnings_file test";
3710+
}
3711+
3712+
if ($build_type eq "nobuild") {
3713+
dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3714+
}
3715+
3716+
build $build_type or dodie "Failed to build";
3717+
3718+
open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3719+
3720+
open(IN, $buildlog) or dodie "Can't open $buildlog";
3721+
while (<IN>) {
3722+
3723+
# Some compilers use UTF-8 extended for quotes
3724+
# for distcc heterogeneous systems, this causes issues
3725+
s/$utf8_quote/'/g;
3726+
3727+
if (/$check_build_re/) {
3728+
print OUT;
3729+
}
3730+
}
3731+
close(IN);
3732+
3733+
close(OUT);
3734+
3735+
success $i;
3736+
}
3737+
36453738
$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
36463739

36473740
if ($#ARGV == 0) {
@@ -3843,9 +3936,9 @@ sub set_test_option {
38433936
$run_type = $bisect_type;
38443937
} elsif ($test_type eq "config_bisect") {
38453938
$run_type = $config_bisect_type;
3846-
}
3847-
3848-
if ($test_type eq "make_min_config") {
3939+
} elsif ($test_type eq "make_min_config") {
3940+
$run_type = "";
3941+
} elsif ($test_type eq "make_warnings_file") {
38493942
$run_type = "";
38503943
}
38513944

@@ -3902,10 +3995,15 @@ sub set_test_option {
39023995
} elsif ($test_type eq "make_min_config") {
39033996
make_min_config $i;
39043997
next;
3998+
} elsif ($test_type eq "make_warnings_file") {
3999+
$no_reboot = 1;
4000+
make_warnings_file $i;
4001+
next;
39054002
}
39064003

39074004
if ($build_type ne "nobuild") {
39084005
build $build_type or next;
4006+
check_buildlog or next;
39094007
}
39104008

39114009
if ($test_type eq "install") {

‎tools/testing/ktest/sample.conf‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,20 @@
793793
# Example for a virtual guest call "Guest".
794794
#POWER_OFF = virsh destroy Guest
795795

796+
# To have the build fail on "new" warnings, create a file that
797+
# contains a list of all known warnings (they must match exactly
798+
# to the line with 'warning:', 'error:' or 'Error:'. If the option
799+
# WARNINGS_FILE is set, then that file will be read, and if the
800+
# build detects a warning, it will examine this file and if the
801+
# warning does not exist in it, it will fail the build.
802+
#
803+
# Note, if this option is defined to a file that does not exist
804+
# then any warning will fail the build.
805+
# (see make_warnings_file below)
806+
#
807+
# (optional, default undefined)
808+
#WARNINGS_FILE = ${OUTPUT_DIR}/warnings_file
809+
796810
# The way to execute a command on the target
797811
# (default ssh $SSH_USER@$MACHINE $SSH_COMMAND";)
798812
# The variables SSH_USER, MACHINE and SSH_COMMAND are defined
@@ -1222,3 +1236,33 @@
12221236
# MIN_CONFIG_TYPE = test
12231237
# TEST = ssh ${USER}@${MACHINE} echo hi
12241238
#
1239+
#
1240+
#
1241+
#
1242+
# For TEST_TYPE = make_warnings_file
1243+
#
1244+
# If you want the build to fail when a new warning is discovered
1245+
# you set the WARNINGS_FILE to point to a file of known warnings.
1246+
#
1247+
# The test "make_warnings_file" will let you create a new warnings
1248+
# file before you run other tests, like patchcheck.
1249+
#
1250+
# What this test does is to run just a build, you still need to
1251+
# specify BUILD_TYPE to tell the test what type of config to use.
1252+
# A BUILD_TYPE of nobuild will fail this test.
1253+
#
1254+
# The test will do the build and scan for all warnings. Any warning
1255+
# it discovers will be saved in the WARNINGS_FILE (required) option.
1256+
#
1257+
# It is recommended (but not necessary) to make sure BUILD_NOCLEAN is
1258+
# off, so that a full build is done (make mrproper is performed).
1259+
# That way, all warnings will be captured.
1260+
#
1261+
# Example:
1262+
#
1263+
# TEST_TYPE = make_warnings_file
1264+
# WARNINGS_FILE = ${OUTPUT_DIR}
1265+
# BUILD_TYPE = useconfig:oldconfig
1266+
# CHECKOUT = v3.8
1267+
# BUILD_NOCLEAN = 0
1268+
#

0 commit comments

Comments
 (0)