Commit 61de8e53 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-3.19-rc1' of...

Merge tag 'linux-kselftest-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest update from Shuah Khan:
 "kselftest updates for 3.19-rc1:

   - kcmp test include file cleanup
   - kcmp change to build on all architectures
   - A light weight kselftest framework that provides a set of
     interfaces for tests to use to report results.  In addition,
     several tests are updated to use the framework.
   - A new runtime system size test that prints the amount of RAM that
     the currently running system is using"

* tag 'linux-kselftest-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftest: size: Add size test for Linux kernel
  selftests/kcmp: Always try to build the test
  selftests/kcmp: Don't include kernel headers
  kcmp: Move kcmp.h into uapi
  selftests/timers: change test to use ksft framework
  selftests/kcmp: change test to use ksft framework
  selftests/ipc: change test to use ksft framework
  selftests/breakpoints: change test to use ksft framework
  selftests: add kselftest framework for uniform test reporting
  selftests/user: move test out of Makefile into a shell script
  selftests/net: move test out of Makefile into a shell script
parents a7c180aa 3ce51050
...@@ -212,6 +212,7 @@ header-y += ivtv.h ...@@ -212,6 +212,7 @@ header-y += ivtv.h
header-y += ixjuser.h header-y += ixjuser.h
header-y += jffs2.h header-y += jffs2.h
header-y += joystick.h header-y += joystick.h
header-y += kcmp.h
header-y += kdev_t.h header-y += kdev_t.h
header-y += kd.h header-y += kd.h
header-y += kernelcapi.h header-y += kernelcapi.h
......
#ifndef _LINUX_KCMP_H #ifndef _UAPI_LINUX_KCMP_H
#define _LINUX_KCMP_H #define _UAPI_LINUX_KCMP_H
/* Comparison type */ /* Comparison type */
enum kcmp_type { enum kcmp_type {
...@@ -14,4 +14,4 @@ enum kcmp_type { ...@@ -14,4 +14,4 @@ enum kcmp_type {
KCMP_TYPES, KCMP_TYPES,
}; };
#endif /* _LINUX_KCMP_H */ #endif /* _UAPI_LINUX_KCMP_H */
...@@ -16,6 +16,7 @@ TARGETS += sysctl ...@@ -16,6 +16,7 @@ TARGETS += sysctl
TARGETS += firmware TARGETS += firmware
TARGETS += ftrace TARGETS += ftrace
TARGETS += exec TARGETS += exec
TARGETS += size
TARGETS_HOTPLUG = cpu-hotplug TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug TARGETS_HOTPLUG += memory-hotplug
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "../kselftest.h"
/* Breakpoint access modes */ /* Breakpoint access modes */
enum { enum {
...@@ -42,7 +44,7 @@ static void set_breakpoint_addr(void *addr, int n) ...@@ -42,7 +44,7 @@ static void set_breakpoint_addr(void *addr, int n)
offsetof(struct user, u_debugreg[n]), addr); offsetof(struct user, u_debugreg[n]), addr);
if (ret) { if (ret) {
perror("Can't set breakpoint addr\n"); perror("Can't set breakpoint addr\n");
exit(-1); ksft_exit_fail();
} }
} }
...@@ -105,7 +107,7 @@ static void toggle_breakpoint(int n, int type, int len, ...@@ -105,7 +107,7 @@ static void toggle_breakpoint(int n, int type, int len,
offsetof(struct user, u_debugreg[7]), dr7); offsetof(struct user, u_debugreg[7]), dr7);
if (ret) { if (ret) {
perror("Can't set dr7"); perror("Can't set dr7");
exit(-1); ksft_exit_fail();
} }
} }
...@@ -275,7 +277,7 @@ static void check_success(const char *msg) ...@@ -275,7 +277,7 @@ static void check_success(const char *msg)
msg2 = "Ok"; msg2 = "Ok";
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) { if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) {
perror("Can't poke\n"); perror("Can't poke\n");
exit(-1); ksft_exit_fail();
} }
} }
...@@ -390,5 +392,5 @@ int main(int argc, char **argv) ...@@ -390,5 +392,5 @@ int main(int argc, char **argv)
wait(NULL); wait(NULL);
return 0; return ksft_exit_pass();
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <linux/msg.h> #include <linux/msg.h>
#include <fcntl.h> #include <fcntl.h>
#include "../kselftest.h"
#define MAX_MSG_SIZE 32 #define MAX_MSG_SIZE 32
struct msg1 { struct msg1 {
...@@ -195,58 +197,58 @@ int main(int argc, char **argv) ...@@ -195,58 +197,58 @@ int main(int argc, char **argv)
if (getuid() != 0) { if (getuid() != 0) {
printf("Please run the test as root - Exiting.\n"); printf("Please run the test as root - Exiting.\n");
exit(1); return ksft_exit_fail();
} }
msgque.key = ftok(argv[0], 822155650); msgque.key = ftok(argv[0], 822155650);
if (msgque.key == -1) { if (msgque.key == -1) {
printf("Can't make key\n"); printf("Can't make key: %d\n", -errno);
return -errno; return ksft_exit_fail();
} }
msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666); msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
if (msgque.msq_id == -1) { if (msgque.msq_id == -1) {
err = -errno; err = -errno;
printf("Can't create queue\n"); printf("Can't create queue: %d\n", err);
goto err_out; goto err_out;
} }
err = fill_msgque(&msgque); err = fill_msgque(&msgque);
if (err) { if (err) {
printf("Failed to fill queue\n"); printf("Failed to fill queue: %d\n", err);
goto err_destroy; goto err_destroy;
} }
err = dump_queue(&msgque); err = dump_queue(&msgque);
if (err) { if (err) {
printf("Failed to dump queue\n"); printf("Failed to dump queue: %d\n", err);
goto err_destroy; goto err_destroy;
} }
err = check_and_destroy_queue(&msgque); err = check_and_destroy_queue(&msgque);
if (err) { if (err) {
printf("Failed to check and destroy queue\n"); printf("Failed to check and destroy queue: %d\n", err);
goto err_out; goto err_out;
} }
err = restore_queue(&msgque); err = restore_queue(&msgque);
if (err) { if (err) {
printf("Failed to restore queue\n"); printf("Failed to restore queue: %d\n", err);
goto err_destroy; goto err_destroy;
} }
err = check_and_destroy_queue(&msgque); err = check_and_destroy_queue(&msgque);
if (err) { if (err) {
printf("Failed to test queue\n"); printf("Failed to test queue: %d\n", err);
goto err_out; goto err_out;
} }
return 0; return ksft_exit_pass();
err_destroy: err_destroy:
if (msgctl(msgque.msq_id, IPC_RMID, 0)) { if (msgctl(msgque.msq_id, IPC_RMID, 0)) {
printf("Failed to destroy queue: %d\n", -errno); printf("Failed to destroy queue: %d\n", -errno);
return -errno; return ksft_exit_fail();
} }
err_out: err_out:
return err; return ksft_exit_fail();
} }
uname_M := $(shell uname -m 2>/dev/null || echo not) CC := $(CROSS_COMPILE)$(CC)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
ifeq ($(ARCH),i386)
ARCH := x86
CFLAGS := -DCONFIG_X86_32 -D__i386__
endif
ifeq ($(ARCH),x86_64)
ARCH := x86
CFLAGS := -DCONFIG_X86_64 -D__x86_64__
endif
CFLAGS += -I../../../../arch/x86/include/generated/
CFLAGS += -I../../../../include/
CFLAGS += -I../../../../usr/include/ CFLAGS += -I../../../../usr/include/
CFLAGS += -I../../../../arch/x86/include/
all: all: kcmp_test
ifeq ($(ARCH),x86)
gcc $(CFLAGS) kcmp_test.c -o kcmp_test
else
echo "Not an x86 target, can't build kcmp selftest"
endif
run_tests: all run_tests: all
@./kcmp_test || echo "kcmp_test: [FAIL]" @./kcmp_test || echo "kcmp_test: [FAIL]"
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "../kselftest.h"
static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2) static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2)
{ {
return syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2); return syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
...@@ -34,13 +36,13 @@ int main(int argc, char **argv) ...@@ -34,13 +36,13 @@ int main(int argc, char **argv)
if (fd1 < 0) { if (fd1 < 0) {
perror("Can't create file"); perror("Can't create file");
exit(1); ksft_exit_fail();
} }
pid2 = fork(); pid2 = fork();
if (pid2 < 0) { if (pid2 < 0) {
perror("fork failed"); perror("fork failed");
exit(1); ksft_exit_fail();
} }
if (!pid2) { if (!pid2) {
...@@ -50,7 +52,7 @@ int main(int argc, char **argv) ...@@ -50,7 +52,7 @@ int main(int argc, char **argv)
fd2 = open(kpath, O_RDWR, 0644); fd2 = open(kpath, O_RDWR, 0644);
if (fd2 < 0) { if (fd2 < 0) {
perror("Can't open file"); perror("Can't open file");
exit(1); ksft_exit_fail();
} }
/* An example of output and arguments */ /* An example of output and arguments */
...@@ -74,23 +76,34 @@ int main(int argc, char **argv) ...@@ -74,23 +76,34 @@ int main(int argc, char **argv)
if (ret) { if (ret) {
printf("FAIL: 0 expected but %d returned (%s)\n", printf("FAIL: 0 expected but %d returned (%s)\n",
ret, strerror(errno)); ret, strerror(errno));
ksft_inc_fail_cnt();
ret = -1; ret = -1;
} else } else {
printf("PASS: 0 returned as expected\n"); printf("PASS: 0 returned as expected\n");
ksft_inc_pass_cnt();
}
/* Compare with self */ /* Compare with self */
ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0); ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0);
if (ret) { if (ret) {
printf("FAIL: 0 expected but %d returned (%s)\n", printf("FAIL: 0 expected but %d returned (%s)\n",
ret, strerror(errno)); ret, strerror(errno));
ksft_inc_fail_cnt();
ret = -1; ret = -1;
} else } else {
printf("PASS: 0 returned as expected\n"); printf("PASS: 0 returned as expected\n");
ksft_inc_pass_cnt();
}
ksft_print_cnts();
exit(ret); if (ret)
ksft_exit_fail();
else
ksft_exit_pass();
} }
waitpid(pid2, &status, P_ALL); waitpid(pid2, &status, P_ALL);
return 0; return ksft_exit_pass();
} }
/*
* kselftest.h: kselftest framework return codes to include from
* selftests.
*
* Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com>
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
*
* This file is released under the GPLv2.
*/
#ifndef __KSELFTEST_H
#define __KSELFTEST_H
#include <stdlib.h>
#include <unistd.h>
/* counters */
struct ksft_count {
unsigned int ksft_pass;
unsigned int ksft_fail;
unsigned int ksft_xfail;
unsigned int ksft_xpass;
unsigned int ksft_xskip;
};
static struct ksft_count ksft_cnt;
static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
static inline void ksft_print_cnts(void)
{
printf("Pass: %d Fail: %d Xfail: %d Xpass: %d, Xskip: %d\n",
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
ksft_cnt.ksft_xskip);
}
static inline int ksft_exit_pass(void)
{
exit(0);
}
static inline int ksft_exit_fail(void)
{
exit(1);
}
static inline int ksft_exit_xfail(void)
{
exit(2);
}
static inline int ksft_exit_xpass(void)
{
exit(3);
}
static inline int ksft_exit_skip(void)
{
exit(4);
}
#endif /* __KSELFTEST_H */
...@@ -14,12 +14,6 @@ all: $(NET_PROGS) ...@@ -14,12 +14,6 @@ all: $(NET_PROGS)
run_tests: all run_tests: all
@/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]" @/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]"
@/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]" @/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]"
@if /sbin/modprobe test_bpf ; then \ ./test_bpf.sh
/sbin/rmmod test_bpf; \
echo "test_bpf: ok"; \
else \
echo "test_bpf: [FAIL]"; \
exit 1; \
fi
clean: clean:
$(RM) $(NET_PROGS) $(RM) $(NET_PROGS)
#!/bin/sh
# Runs bpf test using test_bpf kernel module
if /sbin/modprobe -q test_bpf ; then
/sbin/modprobe -q -r test_bpf;
echo "test_bpf: ok";
else
echo "test_bpf: [FAIL]";
exit 1;
fi
CC = $(CROSS_COMPILE)gcc
all: get_size
get_size: get_size.c
$(CC) -static -ffreestanding -nostartfiles -s $< -o $@
run_tests: all
./get_size
clean:
$(RM) get_size
/*
* Copyright 2014 Sony Mobile Communications Inc.
*
* Licensed under the terms of the GNU GPL License version 2
*
* Selftest for runtime system size
*
* Prints the amount of RAM that the currently running system is using.
*
* This program tries to be as small as possible itself, to
* avoid perturbing the system memory utilization with its
* own execution. It also attempts to have as few dependencies
* on kernel features as possible.
*
* It should be statically linked, with startup libs avoided.
* It uses no library calls, and only the following 3 syscalls:
* sysinfo(), write(), and _exit()
*
* For output, it avoids printf (which in some C libraries
* has large external dependencies) by implementing it's own
* number output and print routines, and using __builtin_strlen()
*/
#include <sys/sysinfo.h>
#include <unistd.h>
#define STDOUT_FILENO 1
static int print(const char *s)
{
return write(STDOUT_FILENO, s, __builtin_strlen(s));
}
static inline char *num_to_str(unsigned long num, char *buf, int len)
{
unsigned int digit;
/* put digits in buffer from back to front */
buf += len - 1;
*buf = 0;
do {
digit = num % 10;
*(--buf) = digit + '0';
num /= 10;
} while (num > 0);
return buf;
}
static int print_num(unsigned long num)
{
char num_buf[30];
return print(num_to_str(num, num_buf, sizeof(num_buf)));
}
static int print_k_value(const char *s, unsigned long num, unsigned long units)
{
unsigned long long temp;
int ccode;
print(s);
temp = num;
temp = (temp * units)/1024;
num = temp;
ccode = print_num(num);
print("\n");
return ccode;
}
/* this program has no main(), as startup libraries are not used */
void _start(void)
{
int ccode;
struct sysinfo info;
unsigned long used;
print("Testing system size.\n");
print("1..1\n");
ccode = sysinfo(&info);
if (ccode < 0) {
print("not ok 1 get runtime memory use\n");
print("# could not get sysinfo\n");
_exit(ccode);
}
/* ignore cache complexities for now */
used = info.totalram - info.freeram - info.bufferram;
print_k_value("ok 1 get runtime memory use # size = ", used,
info.mem_unit);
print("# System runtime memory report (units in Kilobytes):\n");
print_k_value("# Total: ", info.totalram, info.mem_unit);
print_k_value("# Free: ", info.freeram, info.mem_unit);
print_k_value("# Buffer: ", info.bufferram, info.mem_unit);
print_k_value("# In use: ", used, info.mem_unit);
_exit(0);
}
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <time.h> #include <time.h>
#include <pthread.h> #include <pthread.h>
#include "../kselftest.h"
#define DELAY 2 #define DELAY 2
#define USECS_PER_SEC 1000000 #define USECS_PER_SEC 1000000
...@@ -194,16 +196,16 @@ int main(int argc, char **argv) ...@@ -194,16 +196,16 @@ int main(int argc, char **argv)
printf("based timers if other threads run on the CPU...\n"); printf("based timers if other threads run on the CPU...\n");
if (check_itimer(ITIMER_VIRTUAL) < 0) if (check_itimer(ITIMER_VIRTUAL) < 0)
return -1; return ksft_exit_fail();
if (check_itimer(ITIMER_PROF) < 0) if (check_itimer(ITIMER_PROF) < 0)
return -1; return ksft_exit_fail();
if (check_itimer(ITIMER_REAL) < 0) if (check_itimer(ITIMER_REAL) < 0)
return -1; return ksft_exit_fail();
if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0)
return -1; return ksft_exit_fail();
/* /*
* It's unfortunately hard to reliably test a timer expiration * It's unfortunately hard to reliably test a timer expiration
...@@ -215,7 +217,7 @@ int main(int argc, char **argv) ...@@ -215,7 +217,7 @@ int main(int argc, char **argv)
* find a better solution. * find a better solution.
*/ */
if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0)
return -1; return ksft_exit_fail();
return 0; return ksft_exit_pass();
} }
...@@ -4,10 +4,4 @@ ...@@ -4,10 +4,4 @@
all: all:
run_tests: all run_tests: all
@if /sbin/modprobe test_user_copy ; then \ ./test_user_copy.sh
rmmod test_user_copy; \
echo "user_copy: ok"; \
else \
echo "user_copy: [FAIL]"; \
exit 1; \
fi
#!/bin/sh
# Runs copy_to/from_user infrastructure using test_user_copy kernel module
if /sbin/modprobe -q test_user_copy; then
/sbin/modprobe -q -r test_user_copy
echo "user_copy: ok"
else
echo "user_copy: [FAIL]"
exit 1
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment