diff options
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/powerpc/pmu/Makefile | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/tm/Makefile | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/Makefile | 59 | ||||
| -rwxr-xr-x | tools/testing/selftests/x86/check_cc.sh | 16 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/entry_from_vm86.c | 114 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/run_x86_tests.sh | 13 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/trivial_32bit_program.c | 4 | ||||
| -rw-r--r-- | tools/testing/selftests/x86/trivial_64bit_program.c | 18 | 
8 files changed, 189 insertions, 39 deletions
| diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile index 5a161175bbd4..a9099d9f8f39 100644 --- a/tools/testing/selftests/powerpc/pmu/Makefile +++ b/tools/testing/selftests/powerpc/pmu/Makefile @@ -26,7 +26,7 @@ override define EMIT_TESTS  	$(MAKE) -s -C ebb emit_tests  endef -DEFAULT_INSTALL := $(INSTALL_RULE) +DEFAULT_INSTALL_RULE := $(INSTALL_RULE)  override define INSTALL_RULE  	$(DEFAULT_INSTALL_RULE)  	$(MAKE) -C ebb install diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile index 1b616fa79e93..6bff955e1d55 100644 --- a/tools/testing/selftests/powerpc/tm/Makefile +++ b/tools/testing/selftests/powerpc/tm/Makefile @@ -1,4 +1,4 @@ -TEST_PROGS := tm-resched-dscr tm-syscall +TEST_PROGS := tm-resched-dscr  all: $(TEST_PROGS) diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile index ddf63569df5a..9b0d8baf2934 100644 --- a/tools/testing/selftests/x86/Makefile +++ b/tools/testing/selftests/x86/Makefile @@ -1,48 +1,59 @@ -.PHONY: all all_32 all_64 check_build32 clean run_tests +all: + +include ../lib.mk + +.PHONY: all all_32 all_64 warn_32bit_failure clean  TARGETS_C_BOTHBITS := sigreturn single_step_syscall +TARGETS_C_32BIT_ONLY := entry_from_vm86 -BINARIES_32 := $(TARGETS_C_BOTHBITS:%=%_32) +TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) +BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)  BINARIES_64 := $(TARGETS_C_BOTHBITS:%=%_64)  CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -UNAME_P := $(shell uname -p) +UNAME_M := $(shell uname -m) +CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32) +CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c) -# Always build 32-bit tests +ifeq ($(CAN_BUILD_I386),1)  all: all_32 +TEST_PROGS += $(BINARIES_32) +endif -# If we're on a 64-bit host, build 64-bit tests as well -ifeq ($(shell uname -p),x86_64) +ifeq ($(CAN_BUILD_X86_64),1)  all: all_64 +TEST_PROGS += $(BINARIES_64)  endif -all_32: check_build32 $(BINARIES_32) +all_32: $(BINARIES_32)  all_64: $(BINARIES_64)  clean:  	$(RM) $(BINARIES_32) $(BINARIES_64) -run_tests: -	./run_x86_tests.sh - -$(TARGETS_C_BOTHBITS:%=%_32): %_32: %.c +$(TARGETS_C_32BIT_ALL:%=%_32): %_32: %.c  	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl  $(TARGETS_C_BOTHBITS:%=%_64): %_64: %.c  	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -check_build32: -	@if ! $(CC) -m32 -o /dev/null trivial_32bit_program.c; then	\ -	  echo "Warning: you seem to have a broken 32-bit build" 2>&1; 	\ -	  echo "environment.  If you are using a Debian-like";		\ -	  echo " distribution, try:"; 					\ -	  echo "";							\ -	  echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ -	  echo "";							\ -	  echo "If you are using a Fedora-like distribution, try:";	\ -	  echo "";							\ -	  echo "  yum install glibc-devel.*i686";			\ -	  exit 1;							\ -	fi +# x86_64 users should be encouraged to install 32-bit libraries +ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) +all: warn_32bit_failure + +warn_32bit_failure: +	@echo "Warning: you seem to have a broken 32-bit build" 2>&1; 	\ +	echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \ +	echo "kernels.  If you are using a Debian-like distribution," 2>&1; \ +	echo "try:"; 2>&1; \ +	echo "";							\ +	echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ +	echo "";							\ +	echo "If you are using a Fedora-like distribution, try:";	\ +	echo "";							\ +	echo "  yum install glibc-devel.*i686";				\ +	exit 0; +endif diff --git a/tools/testing/selftests/x86/check_cc.sh b/tools/testing/selftests/x86/check_cc.sh new file mode 100755 index 000000000000..172d3293fb7b --- /dev/null +++ b/tools/testing/selftests/x86/check_cc.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# check_cc.sh - Helper to test userspace compilation support +# Copyright (c) 2015 Andrew Lutomirski +# GPL v2 + +CC="$1" +TESTPROG="$2" +shift 2 + +if "$CC" -o /dev/null "$TESTPROG" -O0 "$@" 2>/dev/null; then +    echo 1 +else +    echo 0 +fi + +exit 0 diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c new file mode 100644 index 000000000000..5c38a187677b --- /dev/null +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -0,0 +1,114 @@ +/* + * entry_from_vm86.c - tests kernel entries from vm86 mode + * Copyright (c) 2014-2015 Andrew Lutomirski + * + * This exercises a few paths that need to special-case vm86 mode. + * + * GPL v2. + */ + +#define _GNU_SOURCE + +#include <assert.h> +#include <stdlib.h> +#include <sys/syscall.h> +#include <sys/signal.h> +#include <sys/ucontext.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <sys/mman.h> +#include <err.h> +#include <stddef.h> +#include <stdbool.h> +#include <errno.h> +#include <sys/vm86.h> + +static unsigned long load_addr = 0x10000; +static int nerrs = 0; + +asm ( +	".pushsection .rodata\n\t" +	".type vmcode_bound, @object\n\t" +	"vmcode:\n\t" +	"vmcode_bound:\n\t" +	".code16\n\t" +	"bound %ax, (2048)\n\t" +	"int3\n\t" +	"vmcode_sysenter:\n\t" +	"sysenter\n\t" +	".size vmcode, . - vmcode\n\t" +	"end_vmcode:\n\t" +	".code32\n\t" +	".popsection" +	); + +extern unsigned char vmcode[], end_vmcode[]; +extern unsigned char vmcode_bound[], vmcode_sysenter[]; + +static void do_test(struct vm86plus_struct *v86, unsigned long eip, +		    const char *text) +{ +	long ret; + +	printf("[RUN]\t%s from vm86 mode\n", text); +	v86->regs.eip = eip; +	ret = vm86(VM86_ENTER, v86); + +	if (ret == -1 && errno == ENOSYS) { +		printf("[SKIP]\tvm86 not supported\n"); +		return; +	} + +	if (VM86_TYPE(ret) == VM86_INTx) { +		char trapname[32]; +		int trapno = VM86_ARG(ret); +		if (trapno == 13) +			strcpy(trapname, "GP"); +		else if (trapno == 5) +			strcpy(trapname, "BR"); +		else if (trapno == 14) +			strcpy(trapname, "PF"); +		else +			sprintf(trapname, "%d", trapno); + +		printf("[OK]\tExited vm86 mode due to #%s\n", trapname); +	} else if (VM86_TYPE(ret) == VM86_UNKNOWN) { +		printf("[OK]\tExited vm86 mode due to unhandled GP fault\n"); +	} else { +		printf("[OK]\tExited vm86 mode due to type %ld, arg %ld\n", +		       VM86_TYPE(ret), VM86_ARG(ret)); +	} +} + +int main(void) +{ +	struct vm86plus_struct v86; +	unsigned char *addr = mmap((void *)load_addr, 4096, +				   PROT_READ | PROT_WRITE | PROT_EXEC, +				   MAP_ANONYMOUS | MAP_PRIVATE, -1,0); +	if (addr != (unsigned char *)load_addr) +		err(1, "mmap"); + +	memcpy(addr, vmcode, end_vmcode - vmcode); +	addr[2048] = 2; +	addr[2050] = 3; + +	memset(&v86, 0, sizeof(v86)); + +	v86.regs.cs = load_addr / 16; +	v86.regs.ss = load_addr / 16; +	v86.regs.ds = load_addr / 16; +	v86.regs.es = load_addr / 16; + +	assert((v86.regs.cs & 3) == 0);	/* Looks like RPL = 0 */ + +	/* #BR -- should deliver SIG??? */ +	do_test(&v86, vmcode_bound - vmcode, "#BR"); + +	/* SYSENTER -- should cause #GP or #UD depending on CPU */ +	do_test(&v86, vmcode_sysenter - vmcode, "SYSENTER"); + +	return (nerrs == 0 ? 0 : 1); +} diff --git a/tools/testing/selftests/x86/run_x86_tests.sh b/tools/testing/selftests/x86/run_x86_tests.sh deleted file mode 100644 index 3fc19b376812..000000000000 --- a/tools/testing/selftests/x86/run_x86_tests.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# This is deliberately minimal.  IMO kselftests should provide a standard -# script here. -./sigreturn_32 || exit 1 -./single_step_syscall_32 || exit 1 - -if [[ "$uname -p" -eq "x86_64" ]]; then -    ./sigreturn_64 || exit 1 -    ./single_step_syscall_64 || exit 1 -fi - -exit 0 diff --git a/tools/testing/selftests/x86/trivial_32bit_program.c b/tools/testing/selftests/x86/trivial_32bit_program.c index 2e231beb0a39..fabdf0f51621 100644 --- a/tools/testing/selftests/x86/trivial_32bit_program.c +++ b/tools/testing/selftests/x86/trivial_32bit_program.c @@ -4,6 +4,10 @@   * GPL v2   */ +#ifndef __i386__ +# error wrong architecture +#endif +  #include <stdio.h>  int main() diff --git a/tools/testing/selftests/x86/trivial_64bit_program.c b/tools/testing/selftests/x86/trivial_64bit_program.c new file mode 100644 index 000000000000..b994946c40fb --- /dev/null +++ b/tools/testing/selftests/x86/trivial_64bit_program.c @@ -0,0 +1,18 @@ +/* + * Trivial program to check that we have a valid 32-bit build environment. + * Copyright (c) 2015 Andy Lutomirski + * GPL v2 + */ + +#ifndef __x86_64__ +# error wrong architecture +#endif + +#include <stdio.h> + +int main() +{ +	printf("\n"); + +	return 0; +} |