Skip to content

Commit

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

Pull Kselftest updates from Shuah Khan:

 - fixes and improvements to the framework, and individual tests

 - a new media test for IR encoders from Sean Young

 - a new watchdog test option to find time left on a timer

* tag 'linux-kselftest-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: Fix test errors related to lib.mk khdr target
  fix dma-buf/udmabuf selftest
  selftests: watchdog: fix spelling mistake "experies" -> "expires"
  selftests: watchdog: Add gettimeleft command line arg
  selftests: do not macro-expand failed assertion expressions
  selftests/ftrace: Fix invalid SPDX identifiers
  selftests: gpio: Find libmount with pkg-config if available
  selftests: firmware: add CONFIG_FW_LOADER_USER_HELPER_FALLBACK to config
  selftests: firmware: remove use of non-standard diff -Z option
  media: rc: self test for IR encoders and decoders
  • Loading branch information
torvalds committed Dec 29, 2018
2 parents 457fa34 + 283ac6d commit 903b77c
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 37 deletions.
2 changes: 2 additions & 0 deletions tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TARGETS += capabilities
TARGETS += cgroup
TARGETS += cpufreq
TARGETS += cpu-hotplug
TARGETS += drivers/dma-buf
TARGETS += efivarfs
TARGETS += exec
TARGETS += filesystems
Expand All @@ -15,6 +16,7 @@ TARGETS += futex
TARGETS += gpio
TARGETS += intel_pstate
TARGETS += ipc
TARGETS += ir
TARGETS += kcmp
TARGETS += kvm
TARGETS += lib
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/drivers/dma-buf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ CFLAGS += -I../../../../../usr/include/

TEST_GEN_PROGS := udmabuf

top_srcdir ?=../../../../..

include ../../lib.mk
11 changes: 9 additions & 2 deletions tools/testing/selftests/drivers/dma-buf/udmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/fcntl.h>
#include <malloc.h>

#include <sys/ioctl.h>
Expand Down Expand Up @@ -33,12 +33,19 @@ int main(int argc, char *argv[])
exit(77);
}

memfd = memfd_create("udmabuf-test", MFD_CLOEXEC);
memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
if (memfd < 0) {
printf("%s: [skip,no-memfd]\n", TEST_PREFIX);
exit(77);
}

ret = fcntl(memfd, F_ADD_SEALS, F_SEAL_SHRINK);
if (ret < 0) {
printf("%s: [skip,fcntl-add-seals]\n", TEST_PREFIX);
exit(77);
}


size = getpagesize() * NUM_PAGES;
ret = ftruncate(memfd, size);
if (ret == -1) {
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/firmware/config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CONFIG_TEST_FIRMWARE=y
CONFIG_FW_LOADER=y
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
CONFIG_IKCONFIG=y
CONFIG_IKCONFIG_PROC=y
9 changes: 3 additions & 6 deletions tools/testing/selftests/firmware/fw_filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,8 @@ read_firmwares()
{
for i in $(seq 0 3); do
config_set_read_fw_idx $i
# Verify the contents are what we expect.
# -Z required for now -- check for yourself, md5sum
# on $FW and DIR/read_firmware will yield the same. Even
# cmp agrees, so something is off.
if ! diff -q -Z "$FW" $DIR/read_firmware 2>/dev/null ; then
# Verify the contents match
if ! diff -q "$FW" $DIR/read_firmware 2>/dev/null ; then
echo "request #$i: firmware was not loaded" >&2
exit 1
fi
Expand All @@ -171,7 +168,7 @@ read_firmwares_expect_nofile()
for i in $(seq 0 3); do
config_set_read_fw_idx $i
# Ensures contents differ
if diff -q -Z "$FW" $DIR/read_firmware 2>/dev/null ; then
if diff -q "$FW" $DIR/read_firmware 2>/dev/null ; then
echo "request $i: file was not expected to match" >&2
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2.0
# SPDX-License-Identifier: GPL-2.0
# description: ftrace - stacktrace filter command
# flags: instance

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2.0
# SPDX-License-Identifier: GPL-2.0
# description: ftrace - function trace with cpumask

if ! which nproc ; then
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/ftrace/test.d/template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2.0
# SPDX-License-Identifier: GPL-2.0
# description: %HERE DESCRIBE WHAT THIS DOES%
# you have to add ".tc" extention for your testcase file
# Note that all tests are run with "errexit" option.
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/ftrace/test.d/tracer/wakeup.tc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2.0
# SPDX-License-Identifier: GPL-2.0
# description: Test wakeup tracer

if ! which chrt ; then
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/ftrace/test.d/tracer/wakeup_rt.tc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL2.0
# SPDX-License-Identifier: GPL-2.0
# description: Test wakeup RT tracer

if ! which chrt ; then
Expand Down
10 changes: 8 additions & 2 deletions tools/testing/selftests/gpio/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# SPDX-License-Identifier: GPL-2.0

CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
LDLIBS += -lmount -I/usr/include/libmount
MOUNT_CFLAGS := $(shell pkg-config --cflags mount 2>/dev/null)
MOUNT_LDLIBS := $(shell pkg-config --libs mount 2>/dev/null)
ifeq ($(MOUNT_LDLIBS),)
MOUNT_LDLIBS := -lmount -I/usr/include/libmount
endif

CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/ $(MOUNT_CFLAGS)
LDLIBS += $(MOUNT_LDLIBS)

TEST_PROGS := gpio-mockup.sh
TEST_FILES := gpio-mockup-sysfs.sh
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/ir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ir_loopback
5 changes: 5 additions & 0 deletions tools/testing/selftests/ir/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
TEST_PROGS := ir_loopback.sh
TEST_GEN_PROGS_EXTENDED := ir_loopback

include ../lib.mk
199 changes: 199 additions & 0 deletions tools/testing/selftests/ir/ir_loopback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// SPDX-License-Identifier: GPL-2.0
// test ir decoder
//
// Copyright (C) 2018 Sean Young <sean@mess.org>

// When sending LIRC_MODE_SCANCODE, the IR will be encoded. rc-loopback
// will send this IR to the receiver side, where we try to read the decoded
// IR. Decoding happens in a separate kernel thread, so we will need to
// wait until that is scheduled, hence we use poll to check for read
// readiness.

#include <linux/lirc.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>
#include <time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../kselftest.h"

#define TEST_SCANCODES 10
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

static const struct {
enum rc_proto proto;
const char *name;
unsigned int mask;
const char *decoder;
} protocols[] = {
{ RC_PROTO_RC5, "rc-5", 0x1f7f, "rc-5" },
{ RC_PROTO_RC5X_20, "rc-5x-20", 0x1f7f3f, "rc-5" },
{ RC_PROTO_RC5_SZ, "rc-5-sz", 0x2fff, "rc-5-sz" },
{ RC_PROTO_JVC, "jvc", 0xffff, "jvc" },
{ RC_PROTO_SONY12, "sony-12", 0x1f007f, "sony" },
{ RC_PROTO_SONY15, "sony-15", 0xff007f, "sony" },
{ RC_PROTO_SONY20, "sony-20", 0x1fff7f, "sony" },
{ RC_PROTO_NEC, "nec", 0xffff, "nec" },
{ RC_PROTO_NECX, "nec-x", 0xffffff, "nec" },
{ RC_PROTO_NEC32, "nec-32", 0xffffffff, "nec" },
{ RC_PROTO_SANYO, "sanyo", 0x1fffff, "sanyo" },
{ RC_PROTO_RC6_0, "rc-6-0", 0xffff, "rc-6" },
{ RC_PROTO_RC6_6A_20, "rc-6-6a-20", 0xfffff, "rc-6" },
{ RC_PROTO_RC6_6A_24, "rc-6-6a-24", 0xffffff, "rc-6" },
{ RC_PROTO_RC6_6A_32, "rc-6-6a-32", 0xffffffff, "rc-6" },
{ RC_PROTO_RC6_MCE, "rc-6-mce", 0x00007fff, "rc-6" },
{ RC_PROTO_SHARP, "sharp", 0x1fff, "sharp" },
};

int lirc_open(const char *rc)
{
struct dirent *dent;
char buf[100];
DIR *d;
int fd;

snprintf(buf, sizeof(buf), "/sys/class/rc/%s", rc);

d = opendir(buf);
if (!d)
ksft_exit_fail_msg("cannot open %s: %m\n", buf);

while ((dent = readdir(d)) != NULL) {
if (!strncmp(dent->d_name, "lirc", 4)) {
snprintf(buf, sizeof(buf), "/dev/%s", dent->d_name);
break;
}
}

if (!dent)
ksft_exit_fail_msg("cannot find lirc device for %s\n", rc);

closedir(d);

fd = open(buf, O_RDWR | O_NONBLOCK);
if (fd == -1)
ksft_exit_fail_msg("cannot open: %s: %m\n", buf);

return fd;
}

int main(int argc, char **argv)
{
unsigned int mode;
char buf[100];
int rlircfd, wlircfd, protocolfd, i, n;

srand(time(NULL));

if (argc != 3)
ksft_exit_fail_msg("Usage: %s <write rcN> <read rcN>\n",
argv[0]);

rlircfd = lirc_open(argv[2]);
mode = LIRC_MODE_SCANCODE;
if (ioctl(rlircfd, LIRC_SET_REC_MODE, &mode))
ksft_exit_fail_msg("failed to set scancode rec mode %s: %m\n",
argv[2]);

wlircfd = lirc_open(argv[1]);
if (ioctl(wlircfd, LIRC_SET_SEND_MODE, &mode))
ksft_exit_fail_msg("failed to set scancode send mode %s: %m\n",
argv[1]);

snprintf(buf, sizeof(buf), "/sys/class/rc/%s/protocols", argv[2]);
protocolfd = open(buf, O_WRONLY);
if (protocolfd == -1)
ksft_exit_fail_msg("failed to open %s: %m\n", buf);

printf("Sending IR on %s and receiving IR on %s.\n", argv[1], argv[2]);

for (i = 0; i < ARRAY_SIZE(protocols); i++) {
if (write(protocolfd, protocols[i].decoder,
strlen(protocols[i].decoder)) == -1)
ksft_exit_fail_msg("failed to set write decoder\n");

printf("Testing protocol %s for decoder %s (%d/%d)...\n",
protocols[i].name, protocols[i].decoder,
i + 1, (int)ARRAY_SIZE(protocols));

for (n = 0; n < TEST_SCANCODES; n++) {
unsigned int scancode = rand() & protocols[i].mask;
unsigned int rc_proto = protocols[i].proto;

if (rc_proto == RC_PROTO_RC6_MCE)
scancode |= 0x800f0000;

if (rc_proto == RC_PROTO_NECX &&
(((scancode >> 16) ^ ~(scancode >> 8)) & 0xff) == 0)
continue;

if (rc_proto == RC_PROTO_NEC32 &&
(((scancode >> 8) ^ ~scancode) & 0xff) == 0)
continue;

struct lirc_scancode lsc = {
.rc_proto = rc_proto,
.scancode = scancode
};

printf("Testing scancode:%x\n", scancode);

while (write(wlircfd, &lsc, sizeof(lsc)) < 0) {
if (errno == EINTR)
continue;

ksft_exit_fail_msg("failed to send ir: %m\n");
}

struct pollfd pfd = { .fd = rlircfd, .events = POLLIN };
struct lirc_scancode lsc2;

poll(&pfd, 1, 1000);

bool decoded = true;

while (read(rlircfd, &lsc2, sizeof(lsc2)) < 0) {
if (errno == EINTR)
continue;

ksft_test_result_error("no scancode decoded: %m\n");
decoded = false;
break;
}

if (!decoded)
continue;

if (lsc.rc_proto != lsc2.rc_proto)
ksft_test_result_error("decoded protocol is different: %d\n",
lsc2.rc_proto);

else if (lsc.scancode != lsc2.scancode)
ksft_test_result_error("decoded scancode is different: %llx\n",
lsc2.scancode);
else
ksft_inc_pass_cnt();
}

printf("OK\n");
}

close(rlircfd);
close(wlircfd);
close(protocolfd);

if (ksft_get_fail_cnt() > 0)
ksft_exit_fail();
else
ksft_exit_pass();

return 0;
}
20 changes: 20 additions & 0 deletions tools/testing/selftests/ir/ir_loopback.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

if ! /sbin/modprobe -q -n rc-loopback; then
echo "ir_loopback: module rc-loopback is not found [SKIP]"
exit $ksft_skip
fi

/sbin/modprobe rc-loopback
if [ $? -ne 0 ]; then
exit
fi

RCDEV=$(grep -l DRV_NAME=rc-loopback /sys/class/rc/rc*/uevent | grep -o 'rc[0-9]\+')

./ir_loopback $RCDEV $RCDEV
exit
Loading

0 comments on commit 903b77c

Please sign in to comment.