aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2013-03-09 04:58:13 -0500
committerJiri Kosina <jkosina@suse.cz>2013-03-09 05:01:06 -0500
commit83a44ac8bf4a8e6cbbf0c00ff281a482778f708a (patch)
tree325be1e4d52372db888396549908f25c5370caee /tools
parent4ba25d3f87fe3ed6634f61da2a6904e2dfd09192 (diff)
parentd381f45c890a3fb136afb0dc1cbe025e066cb981 (diff)
HID: Merge branch 'master' into for-3.10/hid-driver-transport-cleanups
Sync with Linus' tree. This is necessary to resolve build conflict caused by dcd9006b1b053c7b ("HID: logitech-dj: do not directly call hid_output_raw_report() during probe") which issues direct call to usbhid_submit_report(), but that is gone in this branch and hid_hw_request() has to be used instead. Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/perf.h12
-rw-r--r--tools/perf/util/evlist.c3
-rw-r--r--tools/testing/ktest/examples/include/patchcheck.conf37
-rwxr-xr-xtools/testing/ktest/ktest.pl190
-rw-r--r--tools/testing/ktest/sample.conf44
-rw-r--r--tools/testing/selftests/Makefile8
-rw-r--r--tools/testing/selftests/README.txt42
-rw-r--r--tools/testing/selftests/efivarfs/Makefile12
-rw-r--r--tools/testing/selftests/efivarfs/create-read.c38
-rw-r--r--tools/testing/selftests/efivarfs/efivarfs.sh198
-rw-r--r--tools/testing/selftests/efivarfs/open-unlink.c63
11 files changed, 626 insertions, 21 deletions
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index c2206c87fc9f..74659ecf93e0 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -94,6 +94,18 @@
94#define CPUINFO_PROC "cpu model" 94#define CPUINFO_PROC "cpu model"
95#endif 95#endif
96 96
97#ifdef __arc__
98#define rmb() asm volatile("" ::: "memory")
99#define cpu_relax() rmb()
100#define CPUINFO_PROC "Processor"
101#endif
102
103#ifdef __metag__
104#define rmb() asm volatile("" ::: "memory")
105#define cpu_relax() asm volatile("" ::: "memory")
106#define CPUINFO_PROC "CPU"
107#endif
108
97#include <time.h> 109#include <time.h>
98#include <unistd.h> 110#include <unistd.h>
99#include <sys/types.h> 111#include <sys/types.h>
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index bc4ad7977438..c8be0fbc5145 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -314,7 +314,6 @@ static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
314struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) 314struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
315{ 315{
316 struct hlist_head *head; 316 struct hlist_head *head;
317 struct hlist_node *pos;
318 struct perf_sample_id *sid; 317 struct perf_sample_id *sid;
319 int hash; 318 int hash;
320 319
@@ -324,7 +323,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
324 hash = hash_64(id, PERF_EVLIST__HLIST_BITS); 323 hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
325 head = &evlist->heads[hash]; 324 head = &evlist->heads[hash];
326 325
327 hlist_for_each_entry(sid, pos, head, node) 326 hlist_for_each_entry(sid, head, node)
328 if (sid->id == id) 327 if (sid->id == id)
329 return sid->evsel; 328 return sid->evsel;
330 329
diff --git a/tools/testing/ktest/examples/include/patchcheck.conf b/tools/testing/ktest/examples/include/patchcheck.conf
index 339d3e1700ff..0eb0a5ac77da 100644
--- a/tools/testing/ktest/examples/include/patchcheck.conf
+++ b/tools/testing/ktest/examples/include/patchcheck.conf
@@ -14,6 +14,16 @@
14PATCH_START := HEAD~3 14PATCH_START := HEAD~3
15PATCH_END := HEAD 15PATCH_END := HEAD
16 16
17# Use the oldconfig if build_type wasn't defined
18DEFAULTS IF NOT DEFINED BUILD_TYPE
19DO_BUILD_TYPE := oldconfig
20
21DEFAULTS ELSE
22DO_BUILD_TYPE := ${BUILD_TYPE}
23
24DEFAULTS
25
26
17# Change PATCH_CHECKOUT to be the branch you want to test. The test will 27# Change PATCH_CHECKOUT to be the branch you want to test. The test will
18# do a git checkout of this branch before starting. Obviously both 28# do a git checkout of this branch before starting. Obviously both
19# PATCH_START and PATCH_END must be in this branch (and PATCH_START must 29# PATCH_START and PATCH_END must be in this branch (and PATCH_START must
@@ -43,6 +53,31 @@ PATCH_TEST_TYPE := boot
43# (space delimited) 53# (space delimited)
44#IGNORE_WARNINGS = 39eaf7ef884dcc44f7ff1bac803ca2a1dcf43544 6edb2a8a385f0cdef51dae37ff23e74d76d8a6ce 54#IGNORE_WARNINGS = 39eaf7ef884dcc44f7ff1bac803ca2a1dcf43544 6edb2a8a385f0cdef51dae37ff23e74d76d8a6ce
45 55
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#
67DEFAULTS IF DEFINED CREATE_WARNINGS_FILE
68WARNINGS_FILE = ${OUTPUT_DIR}/warnings_file
69
70TEST_START IF DEFINED CREATE_WARNINGS_FILE
71# WARNINGS_FILE is already set by the DEFAULTS above
72TEST_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
76CHECKOUT = ${PATCHCHECK_START}~1
77# Force a full build
78BUILD_NOCLEAN = 0
79BUILD_TYPE = ${DO_BUILD_TYPE}
80
46# If you are running a multi test, and the test failed on the first 81# If you are running a multi test, and the test failed on the first
47# test but on, say the 5th patch. If you want to restart on the 82# test but on, say the 5th patch. If you want to restart on the
48# fifth patch, set PATCH_START1. This will make the first test start 83# fifth patch, set PATCH_START1. This will make the first test start
@@ -61,6 +96,7 @@ PATCHCHECK_TYPE = ${PATCH_TEST_TYPE}
61PATCHCHECK_START = ${PATCH_START1} 96PATCHCHECK_START = ${PATCH_START1}
62PATCHCHECK_END = ${PATCH_END} 97PATCHCHECK_END = ${PATCH_END}
63CHECKOUT = ${PATCH_CHECKOUT} 98CHECKOUT = ${PATCH_CHECKOUT}
99BUILD_TYPE = ${DO_BUILD_TYPE}
64 100
65TEST_START IF ${TEST} == patchcheck && ${MULTI} 101TEST_START IF ${TEST} == patchcheck && ${MULTI}
66TEST_TYPE = patchcheck 102TEST_TYPE = patchcheck
@@ -72,3 +108,4 @@ PATCHCHECK_END = ${PATCH_END}
72CHECKOUT = ${PATCH_CHECKOUT} 108CHECKOUT = ${PATCH_CHECKOUT}
73# Use multi to test different compilers? 109# Use multi to test different compilers?
74MAKE_CMD = CC=gcc-4.5.1 make 110MAKE_CMD = CC=gcc-4.5.1 make
111BUILD_TYPE = ${DO_BUILD_TYPE}
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 35fc584a4ffe..4e67d52eb3a2 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -126,6 +126,7 @@ my $start_minconfig_defined;
126my $output_minconfig; 126my $output_minconfig;
127my $minconfig_type; 127my $minconfig_type;
128my $use_output_minconfig; 128my $use_output_minconfig;
129my $warnings_file;
129my $ignore_config; 130my $ignore_config;
130my $ignore_errors; 131my $ignore_errors;
131my $addconfig; 132my $addconfig;
@@ -193,6 +194,9 @@ my $patchcheck_end;
193# which would require more options. 194# which would require more options.
194my $buildonly = 1; 195my $buildonly = 1;
195 196
197# tell build not to worry about warnings, even when WARNINGS_FILE is set
198my $warnings_ok = 0;
199
196# set when creating a new config 200# set when creating a new config
197my $newconfig = 0; 201my $newconfig = 0;
198 202
@@ -235,6 +239,7 @@ my %option_map = (
235 "START_MIN_CONFIG" => \$start_minconfig, 239 "START_MIN_CONFIG" => \$start_minconfig,
236 "MIN_CONFIG_TYPE" => \$minconfig_type, 240 "MIN_CONFIG_TYPE" => \$minconfig_type,
237 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig, 241 "USE_OUTPUT_MIN_CONFIG" => \$use_output_minconfig,
242 "WARNINGS_FILE" => \$warnings_file,
238 "IGNORE_CONFIG" => \$ignore_config, 243 "IGNORE_CONFIG" => \$ignore_config,
239 "TEST" => \$run_test, 244 "TEST" => \$run_test,
240 "ADD_CONFIG" => \$addconfig, 245 "ADD_CONFIG" => \$addconfig,
@@ -619,6 +624,18 @@ sub set_value {
619 # Note if a test is something other than build, then we 624 # Note if a test is something other than build, then we
620 # will need other manditory options. 625 # will need other manditory options.
621 if ($prvalue ne "install") { 626 if ($prvalue ne "install") {
627 # for bisect, we need to check BISECT_TYPE
628 if ($prvalue ne "bisect") {
629 $buildonly = 0;
630 }
631 } else {
632 # install still limits some manditory options.
633 $buildonly = 2;
634 }
635 }
636
637 if ($buildonly && $lvalue =~ /^BISECT_TYPE(\[.*\])?$/ && $prvalue ne "build") {
638 if ($prvalue ne "install") {
622 $buildonly = 0; 639 $buildonly = 0;
623 } else { 640 } else {
624 # install still limits some manditory options. 641 # install still limits some manditory options.
@@ -1062,7 +1079,7 @@ sub read_config {
1062} 1079}
1063 1080
1064sub __eval_option { 1081sub __eval_option {
1065 my ($option, $i) = @_; 1082 my ($name, $option, $i) = @_;
1066 1083
1067 # Add space to evaluate the character before $ 1084 # Add space to evaluate the character before $
1068 $option = " $option"; 1085 $option = " $option";
@@ -1094,7 +1111,11 @@ sub __eval_option {
1094 my $o = "$var\[$i\]"; 1111 my $o = "$var\[$i\]";
1095 my $parento = "$var\[$parent\]"; 1112 my $parento = "$var\[$parent\]";
1096 1113
1097 if (defined($opt{$o})) { 1114 # If a variable contains itself, use the default var
1115 if (($var eq $name) && defined($opt{$var})) {
1116 $o = $opt{$var};
1117 $retval = "$retval$o";
1118 } elsif (defined($opt{$o})) {
1098 $o = $opt{$o}; 1119 $o = $opt{$o};
1099 $retval = "$retval$o"; 1120 $retval = "$retval$o";
1100 } elsif ($repeated && defined($opt{$parento})) { 1121 } elsif ($repeated && defined($opt{$parento})) {
@@ -1118,7 +1139,7 @@ sub __eval_option {
1118} 1139}
1119 1140
1120sub eval_option { 1141sub eval_option {
1121 my ($option, $i) = @_; 1142 my ($name, $option, $i) = @_;
1122 1143
1123 my $prev = ""; 1144 my $prev = "";
1124 1145
@@ -1134,7 +1155,7 @@ sub eval_option {
1134 "Check for recursive variables\n"; 1155 "Check for recursive variables\n";
1135 } 1156 }
1136 $prev = $option; 1157 $prev = $option;
1137 $option = __eval_option($option, $i); 1158 $option = __eval_option($name, $option, $i);
1138 } 1159 }
1139 1160
1140 return $option; 1161 return $option;
@@ -1191,11 +1212,24 @@ sub reboot {
1191 } 1212 }
1192 1213
1193 if (defined($time)) { 1214 if (defined($time)) {
1194 if (wait_for_monitor($time, $reboot_success_line)) { 1215
1216 # We only want to get to the new kernel, don't fail
1217 # if we stumble over a call trace.
1218 my $save_ignore_errors = $ignore_errors;
1219 $ignore_errors = 1;
1220
1221 # Look for the good kernel to boot
1222 if (wait_for_monitor($time, "Linux version")) {
1195 # reboot got stuck? 1223 # reboot got stuck?
1196 doprint "Reboot did not finish. Forcing power cycle\n"; 1224 doprint "Reboot did not finish. Forcing power cycle\n";
1197 run_command "$power_cycle"; 1225 run_command "$power_cycle";
1198 } 1226 }
1227
1228 $ignore_errors = $save_ignore_errors;
1229
1230 # Still need to wait for the reboot to finish
1231 wait_for_monitor($time, $reboot_success_line);
1232
1199 end_monitor; 1233 end_monitor;
1200 } 1234 }
1201} 1235}
@@ -1279,6 +1313,7 @@ sub start_monitor {
1279} 1313}
1280 1314
1281sub end_monitor { 1315sub end_monitor {
1316 return if (!defined $console);
1282 if (--$monitor_cnt) { 1317 if (--$monitor_cnt) {
1283 return; 1318 return;
1284 } 1319 }
@@ -1585,7 +1620,7 @@ sub wait_for_input
1585 1620
1586 $rin = ''; 1621 $rin = '';
1587 vec($rin, fileno($fp), 1) = 1; 1622 vec($rin, fileno($fp), 1) = 1;
1588 $ready = select($rin, undef, undef, $time); 1623 ($ready, $time) = select($rin, undef, undef, $time);
1589 1624
1590 $line = ""; 1625 $line = "";
1591 1626
@@ -1891,23 +1926,102 @@ sub get_version {
1891 1926
1892sub start_monitor_and_boot { 1927sub start_monitor_and_boot {
1893 # Make sure the stable kernel has finished booting 1928 # Make sure the stable kernel has finished booting
1894 start_monitor; 1929
1895 wait_for_monitor 5; 1930 # Install bisects, don't need console
1896 end_monitor; 1931 if (defined $console) {
1932 start_monitor;
1933 wait_for_monitor 5;
1934 end_monitor;
1935 }
1897 1936
1898 get_grub_index; 1937 get_grub_index;
1899 get_version; 1938 get_version;
1900 install; 1939 install;
1901 1940
1902 start_monitor; 1941 start_monitor if (defined $console);
1903 return monitor; 1942 return monitor;
1904} 1943}
1905 1944
1945my $check_build_re = ".*:.*(warning|error|Error):.*";
1946my $utf8_quote = "\\x{e2}\\x{80}(\\x{98}|\\x{99})";
1947
1948sub process_warning_line {
1949 my ($line) = @_;
1950
1951 chomp $line;
1952
1953 # for distcc heterogeneous systems, some compilers
1954 # do things differently causing warning lines
1955 # to be slightly different. This makes an attempt
1956 # to fixe those issues.
1957
1958 # chop off the index into the line
1959 # using distcc, some compilers give different indexes
1960 # depending on white space
1961 $line =~ s/^(\s*\S+:\d+:)\d+/$1/;
1962
1963 # Some compilers use UTF-8 extended for quotes and some don't.
1964 $line =~ s/$utf8_quote/'/g;
1965
1966 return $line;
1967}
1968
1969# Read buildlog and check against warnings file for any
1970# new warnings.
1971#
1972# Returns 1 if OK
1973# 0 otherwise
1906sub check_buildlog { 1974sub check_buildlog {
1975 return 1 if (!defined $warnings_file);
1976
1977 my %warnings_list;
1978
1979 # Failed builds should not reboot the target
1980 my $save_no_reboot = $no_reboot;
1981 $no_reboot = 1;
1982
1983 if (-f $warnings_file) {
1984 open(IN, $warnings_file) or
1985 dodie "Error opening $warnings_file";
1986
1987 while (<IN>) {
1988 if (/$check_build_re/) {
1989 my $warning = process_warning_line $_;
1990
1991 $warnings_list{$warning} = 1;
1992 }
1993 }
1994 close(IN);
1995 }
1996
1997 # If warnings file didn't exist, and WARNINGS_FILE exist,
1998 # then we fail on any warning!
1999
2000 open(IN, $buildlog) or dodie "Can't open $buildlog";
2001 while (<IN>) {
2002 if (/$check_build_re/) {
2003 my $warning = process_warning_line $_;
2004
2005 if (!defined $warnings_list{$warning}) {
2006 fail "New warning found (not in $warnings_file)\n$_\n";
2007 $no_reboot = $save_no_reboot;
2008 return 0;
2009 }
2010 }
2011 }
2012 $no_reboot = $save_no_reboot;
2013 close(IN);
2014}
2015
2016sub check_patch_buildlog {
1907 my ($patch) = @_; 2017 my ($patch) = @_;
1908 2018
1909 my @files = `git show $patch | diffstat -l`; 2019 my @files = `git show $patch | diffstat -l`;
1910 2020
2021 foreach my $file (@files) {
2022 chomp $file;
2023 }
2024
1911 open(IN, "git show $patch |") or 2025 open(IN, "git show $patch |") or
1912 dodie "failed to show $patch"; 2026 dodie "failed to show $patch";
1913 while (<IN>) { 2027 while (<IN>) {
@@ -3055,11 +3169,13 @@ sub patchcheck {
3055 build "oldconfig" or return 0; 3169 build "oldconfig" or return 0;
3056 } 3170 }
3057 3171
3058 3172 # No need to do per patch checking if warnings file exists
3059 if (!defined($ignored_warnings{$sha1})) { 3173 if (!defined($warnings_file) && !defined($ignored_warnings{$sha1})) {
3060 check_buildlog $sha1 or return 0; 3174 check_patch_buildlog $sha1 or return 0;
3061 } 3175 }
3062 3176
3177 check_buildlog or return 0;
3178
3063 next if ($type eq "build"); 3179 next if ($type eq "build");
3064 3180
3065 my $failed = 0; 3181 my $failed = 0;
@@ -3617,6 +3733,39 @@ sub make_min_config {
3617 return 1; 3733 return 1;
3618} 3734}
3619 3735
3736sub make_warnings_file {
3737 my ($i) = @_;
3738
3739 if (!defined($warnings_file)) {
3740 dodie "Must define WARNINGS_FILE for make_warnings_file test";
3741 }
3742
3743 if ($build_type eq "nobuild") {
3744 dodie "BUILD_TYPE can not be 'nobuild' for make_warnings_file test";
3745 }
3746
3747 build $build_type or dodie "Failed to build";
3748
3749 open(OUT, ">$warnings_file") or dodie "Can't create $warnings_file";
3750
3751 open(IN, $buildlog) or dodie "Can't open $buildlog";
3752 while (<IN>) {
3753
3754 # Some compilers use UTF-8 extended for quotes
3755 # for distcc heterogeneous systems, this causes issues
3756 s/$utf8_quote/'/g;
3757
3758 if (/$check_build_re/) {
3759 print OUT;
3760 }
3761 }
3762 close(IN);
3763
3764 close(OUT);
3765
3766 success $i;
3767}
3768
3620$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n"; 3769$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";
3621 3770
3622if ($#ARGV == 0) { 3771if ($#ARGV == 0) {
@@ -3662,7 +3811,7 @@ EOF
3662read_config $ktest_config; 3811read_config $ktest_config;
3663 3812
3664if (defined($opt{"LOG_FILE"})) { 3813if (defined($opt{"LOG_FILE"})) {
3665 $opt{"LOG_FILE"} = eval_option($opt{"LOG_FILE"}, -1); 3814 $opt{"LOG_FILE"} = eval_option("LOG_FILE", $opt{"LOG_FILE"}, -1);
3666} 3815}
3667 3816
3668# Append any configs entered in manually to the config file. 3817# Append any configs entered in manually to the config file.
@@ -3739,7 +3888,7 @@ sub set_test_option {
3739 my $option = __set_test_option($name, $i); 3888 my $option = __set_test_option($name, $i);
3740 return $option if (!defined($option)); 3889 return $option if (!defined($option));
3741 3890
3742 return eval_option($option, $i); 3891 return eval_option($name, $option, $i);
3743} 3892}
3744 3893
3745# First we need to do is the builds 3894# First we need to do is the builds
@@ -3818,9 +3967,9 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3818 $run_type = $bisect_type; 3967 $run_type = $bisect_type;
3819 } elsif ($test_type eq "config_bisect") { 3968 } elsif ($test_type eq "config_bisect") {
3820 $run_type = $config_bisect_type; 3969 $run_type = $config_bisect_type;
3821 } 3970 } elsif ($test_type eq "make_min_config") {
3822 3971 $run_type = "";
3823 if ($test_type eq "make_min_config") { 3972 } elsif ($test_type eq "make_warnings_file") {
3824 $run_type = ""; 3973 $run_type = "";
3825 } 3974 }
3826 3975
@@ -3877,10 +4026,15 @@ for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {
3877 } elsif ($test_type eq "make_min_config") { 4026 } elsif ($test_type eq "make_min_config") {
3878 make_min_config $i; 4027 make_min_config $i;
3879 next; 4028 next;
4029 } elsif ($test_type eq "make_warnings_file") {
4030 $no_reboot = 1;
4031 make_warnings_file $i;
4032 next;
3880 } 4033 }
3881 4034
3882 if ($build_type ne "nobuild") { 4035 if ($build_type ne "nobuild") {
3883 build $build_type or next; 4036 build $build_type or next;
4037 check_buildlog or next;
3884 } 4038 }
3885 4039
3886 if ($test_type eq "install") { 4040 if ($test_type eq "install") {
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 4012e9330344..0a290fb4cd5e 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -793,6 +793,20 @@
793# Example for a virtual guest call "Guest". 793# Example for a virtual guest call "Guest".
794#POWER_OFF = virsh destroy Guest 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# The way to execute a command on the target 810# The way to execute a command on the target
797# (default ssh $SSH_USER@$MACHINE $SSH_COMMAND";) 811# (default ssh $SSH_USER@$MACHINE $SSH_COMMAND";)
798# The variables SSH_USER, MACHINE and SSH_COMMAND are defined 812# The variables SSH_USER, MACHINE and SSH_COMMAND are defined
@@ -1222,3 +1236,33 @@
1222# MIN_CONFIG_TYPE = test 1236# MIN_CONFIG_TYPE = test
1223# TEST = ssh ${USER}@${MACHINE} echo hi 1237# TEST = ssh ${USER}@${MACHINE} echo hi
1224# 1238#
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#
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 85baf11e2acd..3cc0ad7ae863 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,4 +1,10 @@
1TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug 1TARGETS = breakpoints
2TARGETS += kcmp
3TARGETS += mqueue
4TARGETS += vm
5TARGETS += cpu-hotplug
6TARGETS += memory-hotplug
7TARGETS += efivarfs
2 8
3all: 9all:
4 for TARGET in $(TARGETS); do \ 10 for TARGET in $(TARGETS); do \
diff --git a/tools/testing/selftests/README.txt b/tools/testing/selftests/README.txt
new file mode 100644
index 000000000000..5e2faf9c55d3
--- /dev/null
+++ b/tools/testing/selftests/README.txt
@@ -0,0 +1,42 @@
1Linux Kernel Selftests
2
3The kernel contains a set of "self tests" under the tools/testing/selftests/
4directory. These are intended to be small unit tests to exercise individual
5code paths in the kernel.
6
7Running the selftests
8=====================
9
10To build the tests:
11
12 $ make -C tools/testing/selftests
13
14
15To run the tests:
16
17 $ make -C tools/testing/selftests run_tests
18
19- note that some tests will require root privileges.
20
21
22To run only tests targetted for a single subsystem:
23
24 $ make -C tools/testing/selftests TARGETS=cpu-hotplug run_tests
25
26See the top-level tools/testing/selftests/Makefile for the list of all possible
27targets.
28
29
30Contributing new tests
31======================
32
33In general, the rules for for selftests are
34
35 * Do as much as you can if you're not root;
36
37 * Don't take too long;
38
39 * Don't break the build on any architecture, and
40
41 * Don't cause the top-level "make run_tests" to fail if your feature is
42 unconfigured.
diff --git a/tools/testing/selftests/efivarfs/Makefile b/tools/testing/selftests/efivarfs/Makefile
new file mode 100644
index 000000000000..29e8c6bc81b0
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/Makefile
@@ -0,0 +1,12 @@
1CC = $(CROSS_COMPILE)gcc
2CFLAGS = -Wall
3
4test_objs = open-unlink create-read
5
6all: $(test_objs)
7
8run_tests: all
9 @/bin/bash ./efivarfs.sh || echo "efivarfs selftests: [FAIL]"
10
11clean:
12 rm -f $(test_objs)
diff --git a/tools/testing/selftests/efivarfs/create-read.c b/tools/testing/selftests/efivarfs/create-read.c
new file mode 100644
index 000000000000..7feef1880968
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/create-read.c
@@ -0,0 +1,38 @@
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8#include <errno.h>
9#include <string.h>
10
11int main(int argc, char **argv)
12{
13 const char *path;
14 char buf[4];
15 int fd, rc;
16
17 if (argc < 2) {
18 fprintf(stderr, "usage: %s <path>\n", argv[0]);
19 return EXIT_FAILURE;
20 }
21
22 path = argv[1];
23
24 /* create a test variable */
25 fd = open(path, O_RDWR | O_CREAT, 0600);
26 if (fd < 0) {
27 perror("open(O_WRONLY)");
28 return EXIT_FAILURE;
29 }
30
31 rc = read(fd, buf, sizeof(buf));
32 if (rc != 0) {
33 fprintf(stderr, "Reading a new var should return EOF\n");
34 return EXIT_FAILURE;
35 }
36
37 return EXIT_SUCCESS;
38}
diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh
new file mode 100644
index 000000000000..77edcdcc016b
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -0,0 +1,198 @@
1#!/bin/bash
2
3efivarfs_mount=/sys/firmware/efi/efivars
4test_guid=210be57c-9849-4fc7-a635-e6382d1aec27
5
6check_prereqs()
7{
8 local msg="skip all tests:"
9
10 if [ $UID != 0 ]; then
11 echo $msg must be run as root >&2
12 exit 0
13 fi
14
15 if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc/mounts; then
16 echo $msg efivarfs is not mounted on $efivarfs_mount >&2
17 exit 0
18 fi
19}
20
21run_test()
22{
23 local test="$1"
24
25 echo "--------------------"
26 echo "running $test"
27 echo "--------------------"
28
29 if [ "$(type -t $test)" = 'function' ]; then
30 ( $test )
31 else
32 ( ./$test )
33 fi
34
35 if [ $? -ne 0 ]; then
36 echo " [FAIL]"
37 rc=1
38 else
39 echo " [PASS]"
40 fi
41}
42
43test_create()
44{
45 local attrs='\x07\x00\x00\x00'
46 local file=$efivarfs_mount/$FUNCNAME-$test_guid
47
48 printf "$attrs\x00" > $file
49
50 if [ ! -e $file ]; then
51 echo "$file couldn't be created" >&2
52 exit 1
53 fi
54
55 if [ $(stat -c %s $file) -ne 5 ]; then
56 echo "$file has invalid size" >&2
57 exit 1
58 fi
59}
60
61test_create_empty()
62{
63 local file=$efivarfs_mount/$FUNCNAME-$test_guid
64
65 : > $file
66
67 if [ ! -e $file ]; then
68 echo "$file can not be created without writing" >&2
69 exit 1
70 fi
71}
72
73test_create_read()
74{
75 local file=$efivarfs_mount/$FUNCNAME-$test_guid
76 ./create-read $file
77}
78
79test_delete()
80{
81 local attrs='\x07\x00\x00\x00'
82 local file=$efivarfs_mount/$FUNCNAME-$test_guid
83
84 printf "$attrs\x00" > $file
85
86 if [ ! -e $file ]; then
87 echo "$file couldn't be created" >&2
88 exit 1
89 fi
90
91 rm $file
92
93 if [ -e $file ]; then
94 echo "$file couldn't be deleted" >&2
95 exit 1
96 fi
97
98}
99
100# test that we can remove a variable by issuing a write with only
101# attributes specified
102test_zero_size_delete()
103{
104 local attrs='\x07\x00\x00\x00'
105 local file=$efivarfs_mount/$FUNCNAME-$test_guid
106
107 printf "$attrs\x00" > $file
108
109 if [ ! -e $file ]; then
110 echo "$file does not exist" >&2
111 exit 1
112 fi
113
114 printf "$attrs" > $file
115
116 if [ -e $file ]; then
117 echo "$file should have been deleted" >&2
118 exit 1
119 fi
120}
121
122test_open_unlink()
123{
124 local file=$efivarfs_mount/$FUNCNAME-$test_guid
125 ./open-unlink $file
126}
127
128# test that we can create a range of filenames
129test_valid_filenames()
130{
131 local attrs='\x07\x00\x00\x00'
132 local ret=0
133
134 local file_list="abc dump-type0-11-1-1362436005 1234 -"
135 for f in $file_list; do
136 local file=$efivarfs_mount/$f-$test_guid
137
138 printf "$attrs\x00" > $file
139
140 if [ ! -e $file ]; then
141 echo "$file could not be created" >&2
142 ret=1
143 else
144 rm $file
145 fi
146 done
147
148 exit $ret
149}
150
151test_invalid_filenames()
152{
153 local attrs='\x07\x00\x00\x00'
154 local ret=0
155
156 local file_list="
157 -1234-1234-1234-123456789abc
158 foo
159 foo-bar
160 -foo-
161 foo-barbazba-foob-foob-foob-foobarbazfoo
162 foo-------------------------------------
163 -12345678-1234-1234-1234-123456789abc
164 a-12345678=1234-1234-1234-123456789abc
165 a-12345678-1234=1234-1234-123456789abc
166 a-12345678-1234-1234=1234-123456789abc
167 a-12345678-1234-1234-1234=123456789abc
168 1112345678-1234-1234-1234-123456789abc"
169
170 for f in $file_list; do
171 local file=$efivarfs_mount/$f
172
173 printf "$attrs\x00" 2>/dev/null > $file
174
175 if [ -e $file ]; then
176 echo "Creating $file should have failed" >&2
177 rm $file
178 ret=1
179 fi
180 done
181
182 exit $ret
183}
184
185check_prereqs
186
187rc=0
188
189run_test test_create
190run_test test_create_empty
191run_test test_create_read
192run_test test_delete
193run_test test_zero_size_delete
194run_test test_open_unlink
195run_test test_valid_filenames
196run_test test_invalid_filenames
197
198exit $rc
diff --git a/tools/testing/selftests/efivarfs/open-unlink.c b/tools/testing/selftests/efivarfs/open-unlink.c
new file mode 100644
index 000000000000..8c0764407b3c
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/open-unlink.c
@@ -0,0 +1,63 @@
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8
9int main(int argc, char **argv)
10{
11 const char *path;
12 char buf[5];
13 int fd, rc;
14
15 if (argc < 2) {
16 fprintf(stderr, "usage: %s <path>\n", argv[0]);
17 return EXIT_FAILURE;
18 }
19
20 path = argv[1];
21
22 /* attributes: EFI_VARIABLE_NON_VOLATILE |
23 * EFI_VARIABLE_BOOTSERVICE_ACCESS |
24 * EFI_VARIABLE_RUNTIME_ACCESS
25 */
26 *(uint32_t *)buf = 0x7;
27 buf[4] = 0;
28
29 /* create a test variable */
30 fd = open(path, O_WRONLY | O_CREAT);
31 if (fd < 0) {
32 perror("open(O_WRONLY)");
33 return EXIT_FAILURE;
34 }
35
36 rc = write(fd, buf, sizeof(buf));
37 if (rc != sizeof(buf)) {
38 perror("write");
39 return EXIT_FAILURE;
40 }
41
42 close(fd);
43
44 fd = open(path, O_RDONLY);
45 if (fd < 0) {
46 perror("open");
47 return EXIT_FAILURE;
48 }
49
50 if (unlink(path) < 0) {
51 perror("unlink");
52 return EXIT_FAILURE;
53 }
54
55 rc = read(fd, buf, sizeof(buf));
56 if (rc > 0) {
57 fprintf(stderr, "reading from an unlinked variable "
58 "shouldn't be possible\n");
59 return EXIT_FAILURE;
60 }
61
62 return EXIT_SUCCESS;
63}