Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+252 -66
+3 -3
include/linux/kcmp.h include/uapi/linux/kcmp.h
··· 1 - #ifndef _LINUX_KCMP_H 2 - #define _LINUX_KCMP_H 1 + #ifndef _UAPI_LINUX_KCMP_H 2 + #define _UAPI_LINUX_KCMP_H 3 3 4 4 /* Comparison type */ 5 5 enum kcmp_type { ··· 14 14 KCMP_TYPES, 15 15 }; 16 16 17 - #endif /* _LINUX_KCMP_H */ 17 + #endif /* _UAPI_LINUX_KCMP_H */
+1
include/uapi/linux/Kbuild
··· 212 212 header-y += ixjuser.h 213 213 header-y += jffs2.h 214 214 header-y += joystick.h 215 + header-y += kcmp.h 215 216 header-y += kdev_t.h 216 217 header-y += kd.h 217 218 header-y += kernelcapi.h
+1
tools/testing/selftests/Makefile
··· 16 16 TARGETS += firmware 17 17 TARGETS += ftrace 18 18 TARGETS += exec 19 + TARGETS += size 19 20 20 21 TARGETS_HOTPLUG = cpu-hotplug 21 22 TARGETS_HOTPLUG += memory-hotplug
+6 -4
tools/testing/selftests/breakpoints/breakpoint_test.c
··· 17 17 #include <sys/types.h> 18 18 #include <sys/wait.h> 19 19 20 + #include "../kselftest.h" 21 + 20 22 21 23 /* Breakpoint access modes */ 22 24 enum { ··· 44 42 offsetof(struct user, u_debugreg[n]), addr); 45 43 if (ret) { 46 44 perror("Can't set breakpoint addr\n"); 47 - exit(-1); 45 + ksft_exit_fail(); 48 46 } 49 47 } 50 48 ··· 107 105 offsetof(struct user, u_debugreg[7]), dr7); 108 106 if (ret) { 109 107 perror("Can't set dr7"); 110 - exit(-1); 108 + ksft_exit_fail(); 111 109 } 112 110 } 113 111 ··· 277 275 msg2 = "Ok"; 278 276 if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) { 279 277 perror("Can't poke\n"); 280 - exit(-1); 278 + ksft_exit_fail(); 281 279 } 282 280 } 283 281 ··· 392 390 393 391 wait(NULL); 394 392 395 - return 0; 393 + return ksft_exit_pass(); 396 394 }
+14 -12
tools/testing/selftests/ipc/msgque.c
··· 5 5 #include <linux/msg.h> 6 6 #include <fcntl.h> 7 7 8 + #include "../kselftest.h" 9 + 8 10 #define MAX_MSG_SIZE 32 9 11 10 12 struct msg1 { ··· 197 195 198 196 if (getuid() != 0) { 199 197 printf("Please run the test as root - Exiting.\n"); 200 - exit(1); 198 + return ksft_exit_fail(); 201 199 } 202 200 203 201 msgque.key = ftok(argv[0], 822155650); 204 202 if (msgque.key == -1) { 205 - printf("Can't make key\n"); 206 - return -errno; 203 + printf("Can't make key: %d\n", -errno); 204 + return ksft_exit_fail(); 207 205 } 208 206 209 207 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666); 210 208 if (msgque.msq_id == -1) { 211 209 err = -errno; 212 - printf("Can't create queue\n"); 210 + printf("Can't create queue: %d\n", err); 213 211 goto err_out; 214 212 } 215 213 216 214 err = fill_msgque(&msgque); 217 215 if (err) { 218 - printf("Failed to fill queue\n"); 216 + printf("Failed to fill queue: %d\n", err); 219 217 goto err_destroy; 220 218 } 221 219 222 220 err = dump_queue(&msgque); 223 221 if (err) { 224 - printf("Failed to dump queue\n"); 222 + printf("Failed to dump queue: %d\n", err); 225 223 goto err_destroy; 226 224 } 227 225 228 226 err = check_and_destroy_queue(&msgque); 229 227 if (err) { 230 - printf("Failed to check and destroy queue\n"); 228 + printf("Failed to check and destroy queue: %d\n", err); 231 229 goto err_out; 232 230 } 233 231 234 232 err = restore_queue(&msgque); 235 233 if (err) { 236 - printf("Failed to restore queue\n"); 234 + printf("Failed to restore queue: %d\n", err); 237 235 goto err_destroy; 238 236 } 239 237 240 238 err = check_and_destroy_queue(&msgque); 241 239 if (err) { 242 - printf("Failed to test queue\n"); 240 + printf("Failed to test queue: %d\n", err); 243 241 goto err_out; 244 242 } 245 - return 0; 243 + return ksft_exit_pass(); 246 244 247 245 err_destroy: 248 246 if (msgctl(msgque.msq_id, IPC_RMID, 0)) { 249 247 printf("Failed to destroy queue: %d\n", -errno); 250 - return -errno; 248 + return ksft_exit_fail(); 251 249 } 252 250 err_out: 253 - return err; 251 + return ksft_exit_fail(); 254 252 }
+2 -20
tools/testing/selftests/kcmp/Makefile
··· 1 - uname_M := $(shell uname -m 2>/dev/null || echo not) 2 - ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) 3 - ifeq ($(ARCH),i386) 4 - ARCH := x86 5 - CFLAGS := -DCONFIG_X86_32 -D__i386__ 6 - endif 7 - ifeq ($(ARCH),x86_64) 8 - ARCH := x86 9 - CFLAGS := -DCONFIG_X86_64 -D__x86_64__ 10 - endif 11 - 12 - CFLAGS += -I../../../../arch/x86/include/generated/ 13 - CFLAGS += -I../../../../include/ 1 + CC := $(CROSS_COMPILE)$(CC) 14 2 CFLAGS += -I../../../../usr/include/ 15 - CFLAGS += -I../../../../arch/x86/include/ 16 3 17 - all: 18 - ifeq ($(ARCH),x86) 19 - gcc $(CFLAGS) kcmp_test.c -o kcmp_test 20 - else 21 - echo "Not an x86 target, can't build kcmp selftest" 22 - endif 4 + all: kcmp_test 23 5 24 6 run_tests: all 25 7 @./kcmp_test || echo "kcmp_test: [FAIL]"
+20 -7
tools/testing/selftests/kcmp/kcmp_test.c
··· 17 17 #include <sys/stat.h> 18 18 #include <sys/wait.h> 19 19 20 + #include "../kselftest.h" 21 + 20 22 static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2) 21 23 { 22 24 return syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2); ··· 36 34 37 35 if (fd1 < 0) { 38 36 perror("Can't create file"); 39 - exit(1); 37 + ksft_exit_fail(); 40 38 } 41 39 42 40 pid2 = fork(); 43 41 if (pid2 < 0) { 44 42 perror("fork failed"); 45 - exit(1); 43 + ksft_exit_fail(); 46 44 } 47 45 48 46 if (!pid2) { ··· 52 50 fd2 = open(kpath, O_RDWR, 0644); 53 51 if (fd2 < 0) { 54 52 perror("Can't open file"); 55 - exit(1); 53 + ksft_exit_fail(); 56 54 } 57 55 58 56 /* An example of output and arguments */ ··· 76 74 if (ret) { 77 75 printf("FAIL: 0 expected but %d returned (%s)\n", 78 76 ret, strerror(errno)); 77 + ksft_inc_fail_cnt(); 79 78 ret = -1; 80 - } else 79 + } else { 81 80 printf("PASS: 0 returned as expected\n"); 81 + ksft_inc_pass_cnt(); 82 + } 82 83 83 84 /* Compare with self */ 84 85 ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0); 85 86 if (ret) { 86 87 printf("FAIL: 0 expected but %d returned (%s)\n", 87 88 ret, strerror(errno)); 89 + ksft_inc_fail_cnt(); 88 90 ret = -1; 89 - } else 91 + } else { 90 92 printf("PASS: 0 returned as expected\n"); 93 + ksft_inc_pass_cnt(); 94 + } 91 95 92 - exit(ret); 96 + ksft_print_cnts(); 97 + 98 + if (ret) 99 + ksft_exit_fail(); 100 + else 101 + ksft_exit_pass(); 93 102 } 94 103 95 104 waitpid(pid2, &status, P_ALL); 96 105 97 - return 0; 106 + return ksft_exit_pass(); 98 107 }
+62
tools/testing/selftests/kselftest.h
··· 1 + /* 2 + * kselftest.h: kselftest framework return codes to include from 3 + * selftests. 4 + * 5 + * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com> 6 + * Copyright (c) 2014 Samsung Electronics Co., Ltd. 7 + * 8 + * This file is released under the GPLv2. 9 + */ 10 + #ifndef __KSELFTEST_H 11 + #define __KSELFTEST_H 12 + 13 + #include <stdlib.h> 14 + #include <unistd.h> 15 + 16 + /* counters */ 17 + struct ksft_count { 18 + unsigned int ksft_pass; 19 + unsigned int ksft_fail; 20 + unsigned int ksft_xfail; 21 + unsigned int ksft_xpass; 22 + unsigned int ksft_xskip; 23 + }; 24 + 25 + static struct ksft_count ksft_cnt; 26 + 27 + static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } 28 + static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; } 29 + static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; } 30 + static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } 31 + static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; } 32 + 33 + static inline void ksft_print_cnts(void) 34 + { 35 + printf("Pass: %d Fail: %d Xfail: %d Xpass: %d, Xskip: %d\n", 36 + ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, 37 + ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, 38 + ksft_cnt.ksft_xskip); 39 + } 40 + 41 + static inline int ksft_exit_pass(void) 42 + { 43 + exit(0); 44 + } 45 + static inline int ksft_exit_fail(void) 46 + { 47 + exit(1); 48 + } 49 + static inline int ksft_exit_xfail(void) 50 + { 51 + exit(2); 52 + } 53 + static inline int ksft_exit_xpass(void) 54 + { 55 + exit(3); 56 + } 57 + static inline int ksft_exit_skip(void) 58 + { 59 + exit(4); 60 + } 61 + 62 + #endif /* __KSELFTEST_H */
+1 -7
tools/testing/selftests/net/Makefile
··· 14 14 run_tests: all 15 15 @/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]" 16 16 @/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]" 17 - @if /sbin/modprobe test_bpf ; then \ 18 - /sbin/rmmod test_bpf; \ 19 - echo "test_bpf: ok"; \ 20 - else \ 21 - echo "test_bpf: [FAIL]"; \ 22 - exit 1; \ 23 - fi 17 + ./test_bpf.sh 24 18 clean: 25 19 $(RM) $(NET_PROGS)
+10
tools/testing/selftests/net/test_bpf.sh
··· 1 + #!/bin/sh 2 + # Runs bpf test using test_bpf kernel module 3 + 4 + if /sbin/modprobe -q test_bpf ; then 5 + /sbin/modprobe -q -r test_bpf; 6 + echo "test_bpf: ok"; 7 + else 8 + echo "test_bpf: [FAIL]"; 9 + exit 1; 10 + fi
+1
tools/testing/selftests/size/.gitignore
··· 1 + get_size
+12
tools/testing/selftests/size/Makefile
··· 1 + CC = $(CROSS_COMPILE)gcc 2 + 3 + all: get_size 4 + 5 + get_size: get_size.c 6 + $(CC) -static -ffreestanding -nostartfiles -s $< -o $@ 7 + 8 + run_tests: all 9 + ./get_size 10 + 11 + clean: 12 + $(RM) get_size
+100
tools/testing/selftests/size/get_size.c
··· 1 + /* 2 + * Copyright 2014 Sony Mobile Communications Inc. 3 + * 4 + * Licensed under the terms of the GNU GPL License version 2 5 + * 6 + * Selftest for runtime system size 7 + * 8 + * Prints the amount of RAM that the currently running system is using. 9 + * 10 + * This program tries to be as small as possible itself, to 11 + * avoid perturbing the system memory utilization with its 12 + * own execution. It also attempts to have as few dependencies 13 + * on kernel features as possible. 14 + * 15 + * It should be statically linked, with startup libs avoided. 16 + * It uses no library calls, and only the following 3 syscalls: 17 + * sysinfo(), write(), and _exit() 18 + * 19 + * For output, it avoids printf (which in some C libraries 20 + * has large external dependencies) by implementing it's own 21 + * number output and print routines, and using __builtin_strlen() 22 + */ 23 + 24 + #include <sys/sysinfo.h> 25 + #include <unistd.h> 26 + 27 + #define STDOUT_FILENO 1 28 + 29 + static int print(const char *s) 30 + { 31 + return write(STDOUT_FILENO, s, __builtin_strlen(s)); 32 + } 33 + 34 + static inline char *num_to_str(unsigned long num, char *buf, int len) 35 + { 36 + unsigned int digit; 37 + 38 + /* put digits in buffer from back to front */ 39 + buf += len - 1; 40 + *buf = 0; 41 + do { 42 + digit = num % 10; 43 + *(--buf) = digit + '0'; 44 + num /= 10; 45 + } while (num > 0); 46 + 47 + return buf; 48 + } 49 + 50 + static int print_num(unsigned long num) 51 + { 52 + char num_buf[30]; 53 + 54 + return print(num_to_str(num, num_buf, sizeof(num_buf))); 55 + } 56 + 57 + static int print_k_value(const char *s, unsigned long num, unsigned long units) 58 + { 59 + unsigned long long temp; 60 + int ccode; 61 + 62 + print(s); 63 + 64 + temp = num; 65 + temp = (temp * units)/1024; 66 + num = temp; 67 + ccode = print_num(num); 68 + print("\n"); 69 + return ccode; 70 + } 71 + 72 + /* this program has no main(), as startup libraries are not used */ 73 + void _start(void) 74 + { 75 + int ccode; 76 + struct sysinfo info; 77 + unsigned long used; 78 + 79 + print("Testing system size.\n"); 80 + print("1..1\n"); 81 + 82 + ccode = sysinfo(&info); 83 + if (ccode < 0) { 84 + print("not ok 1 get runtime memory use\n"); 85 + print("# could not get sysinfo\n"); 86 + _exit(ccode); 87 + } 88 + /* ignore cache complexities for now */ 89 + used = info.totalram - info.freeram - info.bufferram; 90 + print_k_value("ok 1 get runtime memory use # size = ", used, 91 + info.mem_unit); 92 + 93 + print("# System runtime memory report (units in Kilobytes):\n"); 94 + print_k_value("# Total: ", info.totalram, info.mem_unit); 95 + print_k_value("# Free: ", info.freeram, info.mem_unit); 96 + print_k_value("# Buffer: ", info.bufferram, info.mem_unit); 97 + print_k_value("# In use: ", used, info.mem_unit); 98 + 99 + _exit(0); 100 + }
+8 -6
tools/testing/selftests/timers/posix_timers.c
··· 15 15 #include <time.h> 16 16 #include <pthread.h> 17 17 18 + #include "../kselftest.h" 19 + 18 20 #define DELAY 2 19 21 #define USECS_PER_SEC 1000000 20 22 ··· 196 194 printf("based timers if other threads run on the CPU...\n"); 197 195 198 196 if (check_itimer(ITIMER_VIRTUAL) < 0) 199 - return -1; 197 + return ksft_exit_fail(); 200 198 201 199 if (check_itimer(ITIMER_PROF) < 0) 202 - return -1; 200 + return ksft_exit_fail(); 203 201 204 202 if (check_itimer(ITIMER_REAL) < 0) 205 - return -1; 203 + return ksft_exit_fail(); 206 204 207 205 if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0) 208 - return -1; 206 + return ksft_exit_fail(); 209 207 210 208 /* 211 209 * It's unfortunately hard to reliably test a timer expiration ··· 217 215 * find a better solution. 218 216 */ 219 217 if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0) 220 - return -1; 218 + return ksft_exit_fail(); 221 219 222 - return 0; 220 + return ksft_exit_pass(); 223 221 }
+1 -7
tools/testing/selftests/user/Makefile
··· 4 4 all: 5 5 6 6 run_tests: all 7 - @if /sbin/modprobe test_user_copy ; then \ 8 - rmmod test_user_copy; \ 9 - echo "user_copy: ok"; \ 10 - else \ 11 - echo "user_copy: [FAIL]"; \ 12 - exit 1; \ 13 - fi 7 + ./test_user_copy.sh
+10
tools/testing/selftests/user/test_user_copy.sh
··· 1 + #!/bin/sh 2 + # Runs copy_to/from_user infrastructure using test_user_copy kernel module 3 + 4 + if /sbin/modprobe -q test_user_copy; then 5 + /sbin/modprobe -q -r test_user_copy 6 + echo "user_copy: ok" 7 + else 8 + echo "user_copy: [FAIL]" 9 + exit 1 10 + fi