diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/lib/traceevent/Makefile | 2 | ||||
| -rw-r--r-- | tools/perf/Makefile | 8 | ||||
| -rw-r--r-- | tools/perf/bench/bench.h | 24 | ||||
| -rw-r--r-- | tools/perf/builtin-record.c | 6 | ||||
| -rw-r--r-- | tools/perf/perf.h | 12 | ||||
| -rw-r--r-- | tools/perf/util/evlist.c | 3 | ||||
| -rw-r--r-- | tools/perf/util/hist.h | 5 | ||||
| -rw-r--r-- | tools/perf/util/strlist.c | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/Makefile | 8 | ||||
| -rw-r--r-- | tools/testing/selftests/README.txt | 42 | ||||
| -rw-r--r-- | tools/testing/selftests/efivarfs/Makefile | 12 | ||||
| -rw-r--r-- | tools/testing/selftests/efivarfs/create-read.c | 38 | ||||
| -rw-r--r-- | tools/testing/selftests/efivarfs/efivarfs.sh | 198 | ||||
| -rw-r--r-- | tools/testing/selftests/efivarfs/open-unlink.c | 63 | ||||
| -rw-r--r-- | tools/usb/ffs-test.c | 2 | 
15 files changed, 414 insertions, 11 deletions
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile index a20e3203343..0b0a90787db 100644 --- a/tools/lib/traceevent/Makefile +++ b/tools/lib/traceevent/Makefile @@ -122,7 +122,7 @@ export Q VERBOSE  EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) -INCLUDES = -I. -I/usr/local/include $(CONFIG_INCLUDES) +INCLUDES = -I. $(CONFIG_INCLUDES)  # Set compile option CFLAGS if not set elsewhere  CFLAGS ?= -g -Wall diff --git a/tools/perf/Makefile b/tools/perf/Makefile index a2108ca1cc1..bb74c79cd16 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -95,7 +95,7 @@ ifeq ("$(origin DEBUG)", "command line")    PERF_DEBUG = $(DEBUG)  endif  ifndef PERF_DEBUG -  CFLAGS_OPTIMIZE = -O6 -D_FORTIFY_SOURCE=2 +  CFLAGS_OPTIMIZE = -O6  endif  ifdef PARSER_DEBUG @@ -180,6 +180,12 @@ ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-W         CFLAGS := $(CFLAGS) -Wvolatile-register-var  endif +ifndef PERF_DEBUG +	ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y) +		CFLAGS := $(CFLAGS) -D_FORTIFY_SOURCE=2 +	endif +endif +  ### --- END CONFIGURATION SECTION ---  ifeq ($(srctree),) diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index a5223e6a7b4..0fdc85269c4 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h @@ -1,6 +1,30 @@  #ifndef BENCH_H  #define BENCH_H +/* + * The madvise transparent hugepage constants were added in glibc + * 2.13. For compatibility with older versions of glibc, define these + * tokens if they are not already defined. + * + * PA-RISC uses different madvise values from other architectures and + * needs to be special-cased. + */ +#ifdef __hppa__ +# ifndef MADV_HUGEPAGE +#  define MADV_HUGEPAGE		67 +# endif +# ifndef MADV_NOHUGEPAGE +#  define MADV_NOHUGEPAGE	68 +# endif +#else +# ifndef MADV_HUGEPAGE +#  define MADV_HUGEPAGE		14 +# endif +# ifndef MADV_NOHUGEPAGE +#  define MADV_NOHUGEPAGE	15 +# endif +#endif +  extern int bench_numa(int argc, const char **argv, const char *prefix);  extern int bench_sched_messaging(int argc, const char **argv, const char *prefix);  extern int bench_sched_pipe(int argc, const char **argv, const char *prefix); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 774c90713a5..f1a939ebc19 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -573,13 +573,15 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)  					 perf_event__synthesize_guest_os, tool);  	} -	if (!opts->target.system_wide) +	if (perf_target__has_task(&opts->target))  		err = perf_event__synthesize_thread_map(tool, evsel_list->threads,  						  process_synthesized_event,  						  machine); -	else +	else if (perf_target__has_cpu(&opts->target))  		err = perf_event__synthesize_threads(tool, process_synthesized_event,  					       machine); +	else /* command specified */ +		err = 0;  	if (err != 0)  		goto out_delete_session; diff --git a/tools/perf/perf.h b/tools/perf/perf.h index c2206c87fc9..74659ecf93e 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -94,6 +94,18 @@  #define CPUINFO_PROC	"cpu model"  #endif +#ifdef __arc__ +#define rmb()		asm volatile("" ::: "memory") +#define cpu_relax()	rmb() +#define CPUINFO_PROC	"Processor" +#endif + +#ifdef __metag__ +#define rmb()		asm volatile("" ::: "memory") +#define cpu_relax()	asm volatile("" ::: "memory") +#define CPUINFO_PROC	"CPU" +#endif +  #include <time.h>  #include <unistd.h>  #include <sys/types.h> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index bc4ad797743..c8be0fbc514 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,  struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)  {  	struct hlist_head *head; -	struct hlist_node *pos;  	struct perf_sample_id *sid;  	int hash; @@ -324,7 +323,7 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)  	hash = hash_64(id, PERF_EVLIST__HLIST_BITS);  	head = &evlist->heads[hash]; -	hlist_for_each_entry(sid, pos, head, node) +	hlist_for_each_entry(sid, head, node)  		if (sid->id == id)  			return sid->evsel; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 38624686ee9..226a4ae2f93 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -208,8 +208,9 @@ static inline int script_browse(const char *script_opt __maybe_unused)  	return 0;  } -#define K_LEFT -1 -#define K_RIGHT -2 +#define K_LEFT  -1000 +#define K_RIGHT -2000 +#define K_SWITCH_INPUT_DATA -3000  #endif  #ifdef GTK2_SUPPORT diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c index 55433aa42c8..eabdce0a2da 100644 --- a/tools/perf/util/strlist.c +++ b/tools/perf/util/strlist.c @@ -143,7 +143,7 @@ struct strlist *strlist__new(bool dupstr, const char *list)  		slist->rblist.node_delete = strlist__node_delete;  		slist->dupstr	 = dupstr; -		if (slist && strlist__parse_list(slist, list) != 0) +		if (list && strlist__parse_list(slist, list) != 0)  			goto out_error;  	} diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 85baf11e2ac..3cc0ad7ae86 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -1,4 +1,10 @@ -TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug +TARGETS = breakpoints +TARGETS += kcmp +TARGETS += mqueue +TARGETS += vm +TARGETS += cpu-hotplug +TARGETS += memory-hotplug +TARGETS += efivarfs  all:  	for TARGET in $(TARGETS); do \ diff --git a/tools/testing/selftests/README.txt b/tools/testing/selftests/README.txt new file mode 100644 index 00000000000..5e2faf9c55d --- /dev/null +++ b/tools/testing/selftests/README.txt @@ -0,0 +1,42 @@ +Linux Kernel Selftests + +The kernel contains a set of "self tests" under the tools/testing/selftests/ +directory. These are intended to be small unit tests to exercise individual +code paths in the kernel. + +Running the selftests +===================== + +To build the tests: + +  $ make -C tools/testing/selftests + + +To run the tests: + +  $ make -C tools/testing/selftests run_tests + +- note that some tests will require root privileges. + + +To run only tests targetted for a single subsystem: + +  $  make -C tools/testing/selftests TARGETS=cpu-hotplug run_tests + +See the top-level tools/testing/selftests/Makefile for the list of all possible +targets. + + +Contributing new tests +====================== + +In general, the rules for for selftests are + + * Do as much as you can if you're not root; + + * Don't take too long; + + * Don't break the build on any architecture, and + + * Don't cause the top-level "make run_tests" to fail if your feature is +   unconfigured. diff --git a/tools/testing/selftests/efivarfs/Makefile b/tools/testing/selftests/efivarfs/Makefile new file mode 100644 index 00000000000..29e8c6bc81b --- /dev/null +++ b/tools/testing/selftests/efivarfs/Makefile @@ -0,0 +1,12 @@ +CC = $(CROSS_COMPILE)gcc +CFLAGS = -Wall + +test_objs = open-unlink create-read + +all: $(test_objs) + +run_tests: all +	@/bin/bash ./efivarfs.sh || echo "efivarfs selftests: [FAIL]" + +clean: +	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 00000000000..7feef188096 --- /dev/null +++ b/tools/testing/selftests/efivarfs/create-read.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> + +int main(int argc, char **argv) +{ +	const char *path; +	char buf[4]; +	int fd, rc; + +	if (argc < 2) { +		fprintf(stderr, "usage: %s <path>\n", argv[0]); +		return EXIT_FAILURE; +	} + +	path = argv[1]; + +	/* create a test variable */ +	fd = open(path, O_RDWR | O_CREAT, 0600); +	if (fd < 0) { +		perror("open(O_WRONLY)"); +		return EXIT_FAILURE; +	} + +	rc = read(fd, buf, sizeof(buf)); +	if (rc != 0) { +		fprintf(stderr, "Reading a new var should return EOF\n"); +		return EXIT_FAILURE; +	} + +	return EXIT_SUCCESS; +} diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh new file mode 100644 index 00000000000..77edcdcc016 --- /dev/null +++ b/tools/testing/selftests/efivarfs/efivarfs.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +efivarfs_mount=/sys/firmware/efi/efivars +test_guid=210be57c-9849-4fc7-a635-e6382d1aec27 + +check_prereqs() +{ +	local msg="skip all tests:" + +	if [ $UID != 0 ]; then +		echo $msg must be run as root >&2 +		exit 0 +	fi + +	if ! grep -q "^\S\+ $efivarfs_mount efivarfs" /proc/mounts; then +		echo $msg efivarfs is not mounted on $efivarfs_mount >&2 +		exit 0 +	fi +} + +run_test() +{ +	local test="$1" + +	echo "--------------------" +	echo "running $test" +	echo "--------------------" + +	if [ "$(type -t $test)" = 'function' ]; then +		( $test ) +	else +		( ./$test ) +	fi + +	if [ $? -ne 0 ]; then +		echo "  [FAIL]" +		rc=1 +	else +		echo "  [PASS]" +	fi +} + +test_create() +{ +	local attrs='\x07\x00\x00\x00' +	local file=$efivarfs_mount/$FUNCNAME-$test_guid + +	printf "$attrs\x00" > $file + +	if [ ! -e $file ]; then +		echo "$file couldn't be created" >&2 +		exit 1 +	fi + +	if [ $(stat -c %s $file) -ne 5 ]; then +		echo "$file has invalid size" >&2 +		exit 1 +	fi +} + +test_create_empty() +{ +	local file=$efivarfs_mount/$FUNCNAME-$test_guid + +	: > $file + +	if [ ! -e $file ]; then +		echo "$file can not be created without writing" >&2 +		exit 1 +	fi +} + +test_create_read() +{ +	local file=$efivarfs_mount/$FUNCNAME-$test_guid +	./create-read $file +} + +test_delete() +{ +	local attrs='\x07\x00\x00\x00' +	local file=$efivarfs_mount/$FUNCNAME-$test_guid + +	printf "$attrs\x00" > $file + +	if [ ! -e $file ]; then +		echo "$file couldn't be created" >&2 +		exit 1 +	fi + +	rm $file + +	if [ -e $file ]; then +		echo "$file couldn't be deleted" >&2 +		exit 1 +	fi + +} + +# test that we can remove a variable by issuing a write with only +# attributes specified +test_zero_size_delete() +{ +	local attrs='\x07\x00\x00\x00' +	local file=$efivarfs_mount/$FUNCNAME-$test_guid + +	printf "$attrs\x00" > $file + +	if [ ! -e $file ]; then +		echo "$file does not exist" >&2 +		exit 1 +	fi + +	printf "$attrs" > $file + +	if [ -e $file ]; then +		echo "$file should have been deleted" >&2 +		exit 1 +	fi +} + +test_open_unlink() +{ +	local file=$efivarfs_mount/$FUNCNAME-$test_guid +	./open-unlink $file +} + +# test that we can create a range of filenames +test_valid_filenames() +{ +	local attrs='\x07\x00\x00\x00' +	local ret=0 + +	local file_list="abc dump-type0-11-1-1362436005 1234 -" +	for f in $file_list; do +		local file=$efivarfs_mount/$f-$test_guid + +		printf "$attrs\x00" > $file + +		if [ ! -e $file ]; then +			echo "$file could not be created" >&2 +			ret=1 +		else +			rm $file +		fi +	done + +	exit $ret +} + +test_invalid_filenames() +{ +	local attrs='\x07\x00\x00\x00' +	local ret=0 + +	local file_list=" +		-1234-1234-1234-123456789abc +		foo +		foo-bar +		-foo- +		foo-barbazba-foob-foob-foob-foobarbazfoo +		foo------------------------------------- +		-12345678-1234-1234-1234-123456789abc +		a-12345678=1234-1234-1234-123456789abc +		a-12345678-1234=1234-1234-123456789abc +		a-12345678-1234-1234=1234-123456789abc +		a-12345678-1234-1234-1234=123456789abc +		1112345678-1234-1234-1234-123456789abc" + +	for f in $file_list; do +		local file=$efivarfs_mount/$f + +		printf "$attrs\x00" 2>/dev/null > $file + +		if [ -e $file ]; then +			echo "Creating $file should have failed" >&2 +			rm $file +			ret=1 +		fi +	done + +	exit $ret +} + +check_prereqs + +rc=0 + +run_test test_create +run_test test_create_empty +run_test test_create_read +run_test test_delete +run_test test_zero_size_delete +run_test test_open_unlink +run_test test_valid_filenames +run_test test_invalid_filenames + +exit $rc diff --git a/tools/testing/selftests/efivarfs/open-unlink.c b/tools/testing/selftests/efivarfs/open-unlink.c new file mode 100644 index 00000000000..8c0764407b3 --- /dev/null +++ b/tools/testing/selftests/efivarfs/open-unlink.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main(int argc, char **argv) +{ +	const char *path; +	char buf[5]; +	int fd, rc; + +	if (argc < 2) { +		fprintf(stderr, "usage: %s <path>\n", argv[0]); +		return EXIT_FAILURE; +	} + +	path = argv[1]; + +	/* attributes: EFI_VARIABLE_NON_VOLATILE | +	 *		EFI_VARIABLE_BOOTSERVICE_ACCESS | +	 *		EFI_VARIABLE_RUNTIME_ACCESS +	 */ +	*(uint32_t *)buf = 0x7; +	buf[4] = 0; + +	/* create a test variable */ +	fd = open(path, O_WRONLY | O_CREAT); +	if (fd < 0) { +		perror("open(O_WRONLY)"); +		return EXIT_FAILURE; +	} + +	rc = write(fd, buf, sizeof(buf)); +	if (rc != sizeof(buf)) { +		perror("write"); +		return EXIT_FAILURE; +	} + +	close(fd); + +	fd = open(path, O_RDONLY); +	if (fd < 0) { +		perror("open"); +		return EXIT_FAILURE; +	} + +	if (unlink(path) < 0) { +		perror("unlink"); +		return EXIT_FAILURE; +	} + +	rc = read(fd, buf, sizeof(buf)); +	if (rc > 0) { +		fprintf(stderr, "reading from an unlinked variable " +				"shouldn't be possible\n"); +		return EXIT_FAILURE; +	} + +	return EXIT_SUCCESS; +} diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c index 8674b9ec14f..fe1e66b6ef4 100644 --- a/tools/usb/ffs-test.c +++ b/tools/usb/ffs-test.c @@ -38,7 +38,7 @@  #include <unistd.h>  #include <tools/le_byteshift.h> -#include "../../include/linux/usb/functionfs.h" +#include "../../include/uapi/linux/usb/functionfs.h"  /******************** Little Endian Handling ********************************/  |