aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 23:58:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 23:58:09 -0500
commit2a7d2b96d5cba7568139d9ab157a0e97ab32440f (patch)
treead029d8cc7b7068b7250e914360ec6315fdfa114 /tools
parente3c4877de8b9d93bd47b6ee88eb594b1c1e10da5 (diff)
parentb67bfe0d42cac56c512dd5da4b1b347a23f4b70a (diff)
Merge branch 'akpm' (final batch from Andrew)
Merge third patch-bumb from Andrew Morton: "This wraps me up for -rc1. - Lots of misc stuff and things which were deferred/missed from patchbombings 1 & 2. - ocfs2 things - lib/scatterlist - hfsplus - fatfs - documentation - signals - procfs - lockdep - coredump - seqfile core - kexec - Tejun's large IDR tree reworkings - ipmi - partitions - nbd - random() things - kfifo - tools/testing/selftests updates - Sasha's large and pointless hlist cleanup" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (163 commits) hlist: drop the node parameter from iterators kcmp: make it depend on CHECKPOINT_RESTORE selftests: add a simple doc tools/testing/selftests/Makefile: rearrange targets selftests/efivarfs: add create-read test selftests/efivarfs: add empty file creation test selftests: add tests for efivarfs kfifo: fix kfifo_alloc() and kfifo_init() kfifo: move kfifo.c from kernel/ to lib/ arch Kconfig: centralise CONFIG_ARCH_NO_VIRT_TO_BUS w1: add support for DS2413 Dual Channel Addressable Switch memstick: move the dereference below the NULL test drivers/pps/clients/pps-gpio.c: use devm_kzalloc Documentation/DMA-API-HOWTO.txt: fix typo include/linux/eventfd.h: fix incorrect filename is a comment mtd: mtd_stresstest: use prandom_bytes() mtd: mtd_subpagetest: convert to use prandom library mtd: mtd_speedtest: use prandom_bytes mtd: mtd_pagetest: convert to use prandom library mtd: mtd_oobtest: convert to use prandom library ...
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/evlist.c3
-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.sh139
-rw-r--r--tools/testing/selftests/efivarfs/open-unlink.c63
7 files changed, 302 insertions, 3 deletions
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/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..880cdd5dc63f
--- /dev/null
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -0,0 +1,139 @@
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
128check_prereqs
129
130rc=0
131
132run_test test_create
133run_test test_create_empty
134run_test test_create_read
135run_test test_delete
136run_test test_zero_size_delete
137run_test test_open_unlink
138
139exit $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}