Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+185 -6
+37
tools/testing/ktest/examples/include/patchcheck.conf
··· 14 14 PATCH_START := HEAD~3 15 15 PATCH_END := HEAD 16 16 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 + 17 27 # Change PATCH_CHECKOUT to be the branch you want to test. The test will 18 28 # do a git checkout of this branch before starting. Obviously both 19 29 # PATCH_START and PATCH_END must be in this branch (and PATCH_START must ··· 53 43 # (space delimited) 54 44 #IGNORE_WARNINGS = 39eaf7ef884dcc44f7ff1bac803ca2a1dcf43544 6edb2a8a385f0cdef51dae37ff23e74d76d8a6ce 55 45 46 + # Instead of just checking for warnings to files that are changed 47 + # it can be advantageous to check for any new warnings. If a 48 + # header file is changed, it could cause a warning in a file not 49 + # touched by the commit. To detect these kinds of warnings, you 50 + # can use the WARNINGS_FILE option. 51 + # 52 + # If the variable CREATE_WARNINGS_FILE is set, this config will 53 + # enable the WARNINGS_FILE during the patchcheck test. Also, 54 + # before running the patchcheck test, it will create the 55 + # warnings file. 56 + # 57 + DEFAULTS IF DEFINED CREATE_WARNINGS_FILE 58 + WARNINGS_FILE = ${OUTPUT_DIR}/warnings_file 59 + 60 + TEST_START IF DEFINED CREATE_WARNINGS_FILE 61 + # WARNINGS_FILE is already set by the DEFAULTS above 62 + TEST_TYPE = make_warnings_file 63 + # Checkout the commit before the patches to test, 64 + # and record all the warnings that exist before the patches 65 + # to test are added 66 + CHECKOUT = ${PATCHCHECK_START}~1 67 + # Force a full build 68 + BUILD_NOCLEAN = 0 69 + BUILD_TYPE = ${DO_BUILD_TYPE} 70 + 56 71 # If you are running a multi test, and the test failed on the first 57 72 # test but on, say the 5th patch. If you want to restart on the 58 73 # fifth patch, set PATCH_START1. This will make the first test start ··· 96 61 PATCHCHECK_START = ${PATCH_START1} 97 62 PATCHCHECK_END = ${PATCH_END} 98 63 CHECKOUT = ${PATCH_CHECKOUT} 64 + BUILD_TYPE = ${DO_BUILD_TYPE} 99 65 100 66 TEST_START IF ${TEST} == patchcheck && ${MULTI} 101 67 TEST_TYPE = patchcheck ··· 108 72 CHECKOUT = ${PATCH_CHECKOUT} 109 73 # Use multi to test different compilers? 110 74 MAKE_CMD = CC=gcc-4.5.1 make 75 + BUILD_TYPE = ${DO_BUILD_TYPE}
+104 -6
tools/testing/ktest/ktest.pl
··· 126 126 my $output_minconfig; 127 127 my $minconfig_type; 128 128 my $use_output_minconfig; 129 + my $warnings_file; 129 130 my $ignore_config; 130 131 my $ignore_errors; 131 132 my $addconfig; ··· 194 193 # which would require more options. 195 194 my $buildonly = 1; 196 195 196 + # tell build not to worry about warnings, even when WARNINGS_FILE is set 197 + my $warnings_ok = 0; 198 + 197 199 # set when creating a new config 198 200 my $newconfig = 0; 199 201 ··· 239 235 "START_MIN_CONFIG" => \$start_minconfig, 240 236 "MIN_CONFIG_TYPE" => \$minconfig_type, 241 237 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig, 238 + "WARNINGS_FILE" => \$warnings_file, 242 239 "IGNORE_CONFIG" => \$ignore_config, 243 240 "TEST" => \$run_test, 244 241 "ADD_CONFIG" => \$addconfig, ··· 1929 1924 return monitor; 1930 1925 } 1931 1926 1927 + my $check_build_re = ".*:.*(warning|error|Error):.*"; 1928 + my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})"; 1929 + 1930 + # Read buildlog and check against warnings file for any 1931 + # new warnings. 1932 + # 1933 + # Returns 1 if OK 1934 + # 0 otherwise 1932 1935 sub check_buildlog { 1936 + return 1 if (!defined $warnings_file); 1937 + 1938 + my %warnings_list; 1939 + 1940 + # Failed builds should not reboot the target 1941 + my $save_no_reboot = $no_reboot; 1942 + $no_reboot = 1; 1943 + 1944 + if (-f $warnings_file) { 1945 + open(IN, $warnings_file) or 1946 + dodie "Error opening $warnings_file"; 1947 + 1948 + while (<IN>) { 1949 + if (/$check_build_re/) { 1950 + chomp; 1951 + $warnings_list{$_} = 1; 1952 + } 1953 + } 1954 + close(IN); 1955 + } 1956 + 1957 + # If warnings file didn't exist, and WARNINGS_FILE exist, 1958 + # then we fail on any warning! 1959 + 1960 + open(IN, $buildlog) or dodie "Can't open $buildlog"; 1961 + while (<IN>) { 1962 + if (/$check_build_re/) { 1963 + 1964 + # Some compilers use UTF-8 extended for quotes 1965 + # for distcc heterogeneous systems, this causes issues 1966 + s/$utf8_quote/'/g; 1967 + 1968 + chomp; 1969 + if (!defined $warnings_list{$_}) { 1970 + fail "New warning found (not in $warnings_file)\n$_\n"; 1971 + $no_reboot = $save_no_reboot; 1972 + return 0; 1973 + } 1974 + } 1975 + } 1976 + $no_reboot = $save_no_reboot; 1977 + close(IN); 1978 + } 1979 + 1980 + sub check_patch_buildlog { 1933 1981 my ($patch) = @_; 1934 1982 1935 1983 my @files = `git show $patch | diffstat -l`; ··· 3138 3080 build "oldconfig" or return 0; 3139 3081 } 3140 3082 3141 - 3142 - if (!defined($ignored_warnings{$sha1})) { 3143 - check_buildlog $sha1 or return 0; 3083 + # No need to do per patch checking if warnings file exists 3084 + if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) { 3085 + check_patch_buildlog $sha1 or return 0; 3144 3086 } 3087 + 3088 + check_buildlog or return 0; 3145 3089 3146 3090 next if ($type eq "build"); 3147 3091 ··· 3702 3642 return 1; 3703 3643 } 3704 3644 3645 + sub make_warnings_file { 3646 + my ($i) = @_; 3647 + 3648 + if (!defined($warnings_file)) { 3649 + dodie "Must define WARNINGS_FILE for make_warnings_file test"; 3650 + } 3651 + 3652 + if ($build_type eq "nobuild") { 3653 + dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test"; 3654 + } 3655 + 3656 + build $build_type or dodie "Failed to build"; 3657 + 3658 + open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file"; 3659 + 3660 + open(IN, $buildlog) or dodie "Can't open $buildlog"; 3661 + while (<IN>) { 3662 + 3663 + # Some compilers use UTF-8 extended for quotes 3664 + # for distcc heterogeneous systems, this causes issues 3665 + s/$utf8_quote/'/g; 3666 + 3667 + if (/$check_build_re/) { 3668 + print OUT; 3669 + } 3670 + } 3671 + close(IN); 3672 + 3673 + close(OUT); 3674 + 3675 + success $i; 3676 + } 3677 + 3705 3678 $#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; 3706 3679 3707 3680 if ($#ARGV == 0) { ··· 3936 3843 $run_type = $bisect_type; 3937 3844 } elsif ($test_type eq "config_bisect") { 3938 3845 $run_type = $config_bisect_type; 3939 - } 3940 - 3941 - if ($test_type eq "make_min_config") { 3846 + } elsif ($test_type eq "make_min_config") { 3847 + $run_type = ""; 3848 + } elsif ($test_type eq "make_warnings_file") { 3942 3849 $run_type = ""; 3943 3850 } 3944 3851 ··· 3995 3902 } elsif ($test_type eq "make_min_config") { 3996 3903 make_min_config $i; 3997 3904 next; 3905 + } elsif ($test_type eq "make_warnings_file") { 3906 + $no_reboot = 1; 3907 + make_warnings_file $i; 3908 + next; 3998 3909 } 3999 3910 4000 3911 if ($build_type ne "nobuild") { 4001 3912 build $build_type or next; 3913 + check_buildlog or next; 4002 3914 } 4003 3915 4004 3916 if ($test_type eq "install") {
+44
tools/testing/ktest/sample.conf
··· 793 793 # Example for a virtual guest call "Guest". 794 794 #POWER_OFF = virsh destroy Guest 795 795 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 + 796 810 # The way to execute a command on the target 797 811 # (default ssh $SSH_USER@$MACHINE $SSH_COMMAND";) 798 812 # The variables SSH_USER, MACHINE and SSH_COMMAND are defined ··· 1235 1221 # IGNORE_CONFIG = /path/to/config-tested 1236 1222 # MIN_CONFIG_TYPE = test 1237 1223 # TEST = ssh ${USER}@${MACHINE} echo hi 1224 + # 1225 + # 1226 + # 1227 + # 1228 + # For TEST_TYPE = make_warnings_file 1229 + # 1230 + # If you want the build to fail when a new warning is discovered 1231 + # you set the WARNINGS_FILE to point to a file of known warnings. 1232 + # 1233 + # The test "make_warnings_file" will let you create a new warnings 1234 + # file before you run other tests, like patchcheck. 1235 + # 1236 + # What this test does is to run just a build, you still need to 1237 + # specify BUILD_TYPE to tell the test what type of config to use. 1238 + # A BUILD_TYPE of nobuild will fail this test. 1239 + # 1240 + # The test will do the build and scan for all warnings. Any warning 1241 + # it discovers will be saved in the WARNINGS_FILE (required) option. 1242 + # 1243 + # It is recommended (but not necessary) to make sure BUILD_NOCLEAN is 1244 + # off, so that a full build is done (make mrproper is performed). 1245 + # That way, all warnings will be captured. 1246 + # 1247 + # Example: 1248 + # 1249 + # TEST_TYPE = make_warnings_file 1250 + # WARNINGS_FILE = ${OUTPUT_DIR} 1251 + # BUILD_TYPE = useconfig:oldconfig 1252 + # CHECKOUT = v3.8 1253 + # BUILD_NOCLEAN = 0 1238 1254 #