Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-4.4-rc1' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:
 "This 12 patch update for 4.4-rc1 consists of a new pstore test and
  fixes to existing tests"

* tag 'linux-kselftest-4.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: breakpoint: Actually build it
  selftests: vm: Try harder to allocate huge pages
  selftests: Make scripts executable
  selftests: kprobe: Choose an always-defined function to probe
  selftests: memfd: Stop unnecessary rebuilds
  selftests: Add missing #include directives
  selftests/seccomp: Be more precise with syscall arguments.
  selftests/seccomp: build and pass on arm64
  selftests: memfd_test: Revised STACK_SIZE to make it 16-byte aligned
  selftests/pstore: add pstore test scripts going with reboot
  selftests/pstore: add pstore test script for pre-reboot
  selftests: add .gitignore for efivarfs
  • Loading branch information
Linus Torvalds committed Nov 11, 2015
2 parents ae36ce0 + 3b5bab3 commit 6a177af
Show file tree
Hide file tree
Showing 22 changed files with 362 additions and 53 deletions.
4 changes: 4 additions & 0 deletions tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TARGETS += mount
TARGETS += mqueue
TARGETS += net
TARGETS += powerpc
TARGETS += pstore
TARGETS += ptrace
TARGETS += seccomp
TARGETS += size
Expand Down Expand Up @@ -66,6 +67,9 @@ clean_hotplug:
make -C $$TARGET clean; \
done;

run_pstore_crash:
make -C pstore run_crash

INSTALL_PATH ?= install
INSTALL_PATH := $(abspath $(INSTALL_PATH))
ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/breakpoints/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ifeq ($(ARCH),x86)
TEST_PROGS := breakpoint_test
endif

all:
all: $(TEST_PROGS)

include ../lib.mk

Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/efivarfs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create-read
open-unlink
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

echo 0 > events/enable
echo > kprobe_events
echo p:myevent do_fork > kprobe_events
echo p:myevent _do_fork > kprobe_events
grep myevent kprobe_events
test -d events/kprobes/myevent
echo > kprobe_events
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

echo 0 > events/enable
echo > kprobe_events
echo p:myevent do_fork > kprobe_events
echo p:myevent _do_fork > kprobe_events
test -d events/kprobes/myevent
echo 1 > events/kprobes/myevent/enable
echo > kprobe_events && exit 1 # this must fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

echo 0 > events/enable
echo > kprobe_events
echo 'p:testprobe do_fork $stack $stack0 +0($stack)' > kprobe_events
echo 'p:testprobe _do_fork $stack $stack0 +0($stack)' > kprobe_events
grep testprobe kprobe_events
test -d events/kprobes/testprobe
echo 1 > events/kprobes/testprobe/enable
Expand Down
14 changes: 7 additions & 7 deletions tools/testing/selftests/ftrace/test.d/kprobe/kprobe_ftrace.tc
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@ grep function available_tracers || exit_unsupported # this is configurable

# prepare
echo nop > current_tracer
echo do_fork > set_ftrace_filter
echo _do_fork > set_ftrace_filter
echo 0 > events/enable
echo > kprobe_events
echo 'p:testprobe do_fork' > kprobe_events
echo 'p:testprobe _do_fork' > kprobe_events

# kprobe on / ftrace off
echo 1 > events/kprobes/testprobe/enable
echo > trace
( echo "forked")
grep testprobe trace
! grep 'do_fork <-' trace
! grep '_do_fork <-' trace

# kprobe on / ftrace on
echo function > current_tracer
echo > trace
( echo "forked")
grep testprobe trace
grep 'do_fork <-' trace
grep '_do_fork <-' trace

# kprobe off / ftrace on
echo 0 > events/kprobes/testprobe/enable
echo > trace
( echo "forked")
! grep testprobe trace
grep 'do_fork <-' trace
grep '_do_fork <-' trace

# kprobe on / ftrace on
echo 1 > events/kprobes/testprobe/enable
echo function > current_tracer
echo > trace
( echo "forked")
grep testprobe trace
grep 'do_fork <-' trace
grep '_do_fork <-' trace

# kprobe on / ftrace off
echo nop > current_tracer
echo > trace
( echo "forked")
grep testprobe trace
! grep 'do_fork <-' trace
! grep '_do_fork <-' trace

# cleanup
echo nop > current_tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

echo 0 > events/enable
echo > kprobe_events
echo 'r:testprobe2 do_fork $retval' > kprobe_events
echo 'r:testprobe2 _do_fork $retval' > kprobe_events
grep testprobe2 kprobe_events
test -d events/kprobes/testprobe2
echo 1 > events/kprobes/testprobe2/enable
Expand Down
12 changes: 6 additions & 6 deletions tools/testing/selftests/memfd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ CFLAGS += -I../../../../include/uapi/
CFLAGS += -I../../../../include/
CFLAGS += -I../../../../usr/include/

all:
$(CC) $(CFLAGS) memfd_test.c -o memfd_test

TEST_PROGS := memfd_test

all: $(TEST_PROGS)

include ../lib.mk

build_fuse:
$(CC) $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt
$(CC) $(CFLAGS) fuse_test.c -o fuse_test
build_fuse: fuse_mnt fuse_test

fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
fuse_mnt: LDFLAGS += $(shell pkg-config fuse --libs)

run_fuse: build_fuse
@./run_fuse_test.sh || echo "fuse_test: [FAIL]"
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/memfd/memfd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>

#define MFD_DEF_SIZE 8192
#define STACK_SIZE 65535
#define STACK_SIZE 65536

static int sys_memfd_create(const char *name,
unsigned int flags)
Expand Down
Empty file modified tools/testing/selftests/memfd/run_fuse_test.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions tools/testing/selftests/mqueue/mq_open_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <error.h>

static char *usage =
"Usage:\n"
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/mqueue/mq_perf_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/stat.h>
#include <mqueue.h>
#include <popt.h>
#include <error.h>

static char *usage =
"Usage:\n"
Expand Down
15 changes: 15 additions & 0 deletions tools/testing/selftests/pstore/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Makefile for pstore selftests.
# Expects pstore backend is registered.

all:

TEST_PROGS := pstore_tests pstore_post_reboot_tests
TEST_FILES := common_tests pstore_crash_test

include ../lib.mk

run_crash:
@sh pstore_crash_test || { echo "pstore_crash_test: [FAIL]"; exit 1; }

clean:
rm -rf logs/* *uuid
83 changes: 83 additions & 0 deletions tools/testing/selftests/pstore/common_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/sh

# common_tests - Shell script commonly used by pstore test scripts
#
# Copyright (C) Hitachi Ltd., 2015
# Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
#
# Released under the terms of the GPL v2.

# Utilities
errexit() { # message
echo "Error: $1" 1>&2
exit 1
}

absdir() { # file_path
(cd `dirname $1`; pwd)
}

show_result() { # result_value
if [ $1 -eq 0 ]; then
prlog "ok"
else
prlog "FAIL"
rc=1
fi
}

check_files_exist() { # type of pstorefs file
if [ -e ${1}-${backend}-0 ]; then
prlog "ok"
for f in `ls ${1}-${backend}-*`; do
prlog -e "\t${f}"
done
else
prlog "FAIL"
rc=1
fi
}

operate_files() { # tested value, files, operation
if [ $1 -eq 0 ]; then
prlog
for f in $2; do
prlog -ne "\t${f} ... "
# execute operation
$3 $f
show_result $?
done
else
prlog " ... FAIL"
rc=1
fi
}

# Parameters
TEST_STRING_PATTERN="Testing pstore: uuid="
UUID=`cat /proc/sys/kernel/random/uuid`
TOP_DIR=`absdir $0`
LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`_${UUID}/
REBOOT_FLAG=$TOP_DIR/reboot_flag

# Preparing logs
LOG_FILE=$LOG_DIR/`basename $0`.log
mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
date > $LOG_FILE
prlog() { # messages
/bin/echo "$@" | tee -a $LOG_FILE
}

# Starting tests
rc=0
prlog "=== Pstore unit tests (`basename $0`) ==="
prlog "UUID="$UUID

prlog -n "Checking pstore backend is registered ... "
backend=`cat /sys/module/pstore/parameters/backend`
show_result $?
prlog -e "\tbackend=${backend}"
prlog -e "\tcmdline=`cat /proc/cmdline`"
if [ $rc -ne 0 ]; then
exit 1
fi
30 changes: 30 additions & 0 deletions tools/testing/selftests/pstore/pstore_crash_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# pstore_crash_test - Pstore test shell script which causes crash and reboot
#
# Copyright (C) Hitachi Ltd., 2015
# Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
#
# Released under the terms of the GPL v2.

# exit if pstore backend is not registered
. ./common_tests

prlog "Causing kernel crash ..."

# enable all functions triggered by sysrq
echo 1 > /proc/sys/kernel/sysrq
# setting to reboot in 3 seconds after panic
echo 3 > /proc/sys/kernel/panic

# save uuid file by different name because next test execution will replace it.
mv $TOP_DIR/uuid $TOP_DIR/prev_uuid

# create a file as reboot flag
touch $REBOOT_FLAG
sync

# cause crash
# Note: If you use kdump and want to see kmesg-* files after reboot, you should
# specify 'crash_kexec_post_notifiers' in 1st kernel's cmdline.
echo c > /proc/sysrq-trigger
77 changes: 77 additions & 0 deletions tools/testing/selftests/pstore/pstore_post_reboot_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

# pstore_post_reboot_tests - Check pstore's behavior after crash/reboot
#
# Copyright (C) Hitachi Ltd., 2015
# Written by Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
#
# Released under the terms of the GPL v2.

. ./common_tests

if [ -e $REBOOT_FLAG ]; then
rm $REBOOT_FLAG
else
prlog "pstore_crash_test has not been executed yet. we skip further tests."
exit 0
fi

prlog -n "Mounting pstore filesystem ... "
mount_info=`grep pstore /proc/mounts`
if [ $? -eq 0 ]; then
mount_point=`echo ${mount_info} | cut -d' ' -f2 | head -n1`
prlog "ok"
else
mount none /sys/fs/pstore -t pstore
if [ $? -eq 0 ]; then
mount_point=`grep pstore /proc/mounts | cut -d' ' -f2 | head -n1`
prlog "ok"
else
prlog "FAIL"
exit 1
fi
fi

cd ${mount_point}

prlog -n "Checking dmesg files exist in pstore filesystem ... "
check_files_exist dmesg

prlog -n "Checking console files exist in pstore filesystem ... "
check_files_exist console

prlog -n "Checking pmsg files exist in pstore filesystem ... "
check_files_exist pmsg

prlog -n "Checking dmesg files contain oops end marker"
grep_end_trace() {
grep -q "\---\[ end trace" $1
}
files=`ls dmesg-${backend}-*`
operate_files $? "$files" grep_end_trace

prlog -n "Checking console file contains oops end marker ... "
grep -q "\---\[ end trace" console-${backend}-0
show_result $?

prlog -n "Checking pmsg file properly keeps the content written before crash ... "
prev_uuid=`cat $TOP_DIR/prev_uuid`
if [ $? -eq 0 ]; then
nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0`
if [ $nr_matched -eq 1 ]; then
grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0
show_result $?
else
prlog "FAIL"
rc=1
fi
else
prlog "FAIL"
rc=1
fi

prlog -n "Removing all files in pstore filesystem "
files=`ls *-${backend}-*`
operate_files $? "$files" rm

exit $rc
Loading

0 comments on commit 6a177af

Please sign in to comment.