Skip to contentSkip to conversation

selftests: drivers: fpga: A test for interrupt support

PATCH Superseded [email protected] 2 participants 3 messages Jan 16, 2021 – Jan 17, 2021

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

PATCH v2 1/1 selftests: drivers: fpga: A test for interrupt support

From: Tom Rix <[email protected]>

Check that the ioctl DFL_FPGA_PORT_ERR_GET_IRQ_NUM returns an expected result.

Tested on vf device 0xbcc1

Sample run with

 # make -C tools/testing/selftests TARGETS=drivers/fpga run_tests
 ...
 TAP version 13
 1..1
 # selftests: drivers/fpga: intr
 # TAP version 13
 # 1..1
 # # Starting 1 tests from 1 test cases.
 # #  RUN           global.afu_intr ...
 # #            OK  global.afu_intr
 # ok 1 global.afu_intr
 # # PASSED: 1 / 1 tests passed.
 # # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/fpga: intr

---
v1: Convert to kselftest_harness.h framework

---
 MAINTAINERS                                   |  1 +
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/drivers/fpga/Makefile |  7 ++++
 tools/testing/selftests/drivers/fpga/config   |  1 +
 tools/testing/selftests/drivers/fpga/intr.c   | 36 +++++++++++++++++++
 5 files changed, 46 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/fpga/Makefile
 create mode 100644 tools/testing/selftests/drivers/fpga/config
 create mode 100644 tools/testing/selftests/drivers/fpga/intr.c
MAINTAINERS +1 -0
index de610a06cb5c..7ed3ce58d95e 100644
@@ -6973,6 +6973,7 @@ F:	Documentation/driver-api/fpga/
 F:	Documentation/fpga/
 F:	drivers/fpga/
 F:	include/linux/fpga/
+F:	tools/testing/selftests/drivers/fpga/
 
 FPGA SECURITY MANAGER DRIVERS
 M:	Russ Weight <[email protected]>
tools/testing/selftests/Makefile +1 -0
index afbab4aeef3c..aad4763ec348 100644
@@ -9,6 +9,7 @@ TARGETS += core
 TARGETS += cpufreq
 TARGETS += cpu-hotplug
 TARGETS += drivers/dma-buf
+TARGETS += drivers/fpga
 TARGETS += efivarfs
 TARGETS += exec
 TARGETS += filesystems
tools/testing/selftests/drivers/fpga/Makefile new file +7 -0
new file mode 100644
index 000000000000..eba35c405d5b
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+CFLAGS += -I../../../../../usr/include/
+CFLAGS += -I../../../../../include/uapi/
+
+TEST_GEN_PROGS := intr
+
+include ../../lib.mk
tools/testing/selftests/drivers/fpga/config new file +1 -0
new file mode 100644
index 000000000000..e2111b81d8d7
@@ -0,0 +1 @@
+CONFIG_FPGA_DFL_AFU=m
tools/testing/selftests/drivers/fpga/intr.c new file +36 -0
new file mode 100644
index 000000000000..b362fb1f788d
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/fpga-dfl.h>
+
+#include "../../kselftest_harness.h"
+
+TEST(afu_intr)
+{
+	int devfd, status;
+	struct dfl_fpga_port_info port_info;
+	uint32_t irq_num = UINT32_MAX;
+
+	devfd = open("/dev/dfl-port.0", O_RDONLY);
+	if (devfd < 0)
+		SKIP(0, "no fpga afu device 0");
+	/*
+	 * From fpga-dl.h :
+	 * Currently hardware supports up to 1 irq.
+	 * Return: 0 on success, -errno on failure.
+	 */
+	status = ioctl(devfd, DFL_FPGA_PORT_ERR_GET_IRQ_NUM, &irq_num);
+	ASSERT_EQ(0, status) {
+		TH_LOG("ioctl() failed to get the number irqs");
+	}
+	ASSERT_LT(irq_num, 256) {
+		TH_LOG("unexpeced number of irqs");
+	}
+	close(devfd);
+}
+
+TEST_HARNESS_MAIN
Signature · 1 line
2.27.0
maintainer
#1 lore raw

Hi Tom,

Quoted 87 lines · On Sat, Jan 16, 2021 at 11:33:21AM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

Check that the ioctl DFL_FPGA_PORT_ERR_GET_IRQ_NUM returns an expected result.

Tested on vf device 0xbcc1

Sample run with

 # make -C tools/testing/selftests TARGETS=drivers/fpga run_tests
 ...
 TAP version 13
 1..1
 # selftests: drivers/fpga: intr
 # TAP version 13
 # 1..1
 # # Starting 1 tests from 1 test cases.
 # #  RUN           global.afu_intr ...
 # #            OK  global.afu_intr
 # ok 1 global.afu_intr
 # # PASSED: 1 / 1 tests passed.
 # # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/fpga: intr

---
v1: Convert to kselftest_harness.h framework

---
 MAINTAINERS                                   |  1 +
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/drivers/fpga/Makefile |  7 ++++
 tools/testing/selftests/drivers/fpga/config   |  1 +
 tools/testing/selftests/drivers/fpga/intr.c   | 36 +++++++++++++++++++
 5 files changed, 46 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/fpga/Makefile
 create mode 100644 tools/testing/selftests/drivers/fpga/config
 create mode 100644 tools/testing/selftests/drivers/fpga/intr.c
MAINTAINERS +1 -0
index de610a06cb5c..7ed3ce58d95e 100644
@@ -6973,6 +6973,7 @@ F:	Documentation/driver-api/fpga/
 F:	Documentation/fpga/
 F:	drivers/fpga/
 F:	include/linux/fpga/
+F:	tools/testing/selftests/drivers/fpga/
 
 FPGA SECURITY MANAGER DRIVERS
 M:	Russ Weight <[email protected]>
tools/testing/selftests/Makefile +1 -0
index afbab4aeef3c..aad4763ec348 100644
@@ -9,6 +9,7 @@ TARGETS += core
 TARGETS += cpufreq
 TARGETS += cpu-hotplug
 TARGETS += drivers/dma-buf
+TARGETS += drivers/fpga
 TARGETS += efivarfs
 TARGETS += exec
 TARGETS += filesystems
tools/testing/selftests/drivers/fpga/Makefile new file +7 -0
new file mode 100644
index 000000000000..eba35c405d5b
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+CFLAGS += -I../../../../../usr/include/
+CFLAGS += -I../../../../../include/uapi/
+
+TEST_GEN_PROGS := intr
+
+include ../../lib.mk
tools/testing/selftests/drivers/fpga/config new file +1 -0
new file mode 100644
index 000000000000..e2111b81d8d7
@@ -0,0 +1 @@
+CONFIG_FPGA_DFL_AFU=m
tools/testing/selftests/drivers/fpga/intr.c new file +0 -0
new file mode 100644
index 000000000000..b362fb1f788d

tools/testing/selftests/drivers/fpga/intr.c line 10

Quoted 10 lines
tools/testing/selftests/drivers/fpga/intr.c new file +10 -0
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/fpga-dfl.h>
+
+#include "../../kselftest_harness.h"

Is that how it works with selftests?

tools/testing/selftests/drivers/fpga/intr.c line 16

Quoted 6 lines
tools/testing/selftests/drivers/fpga/intr.c new file +6 -0
+
+TEST(afu_intr)
+{
+	int devfd, status;
+	struct dfl_fpga_port_info port_info;
+	uint32_t irq_num = UINT32_MAX;

Can you order those?

xxxx
xx
x

Quoted 23 lines
tools/testing/selftests/drivers/fpga/intr.c new file +20 -0
+
+	devfd = open("/dev/dfl-port.0", O_RDONLY);
+	if (devfd < 0)
+		SKIP(0, "no fpga afu device 0");
+	/*
+	 * From fpga-dl.h :
+	 * Currently hardware supports up to 1 irq.
+	 * Return: 0 on success, -errno on failure.
+	 */
+	status = ioctl(devfd, DFL_FPGA_PORT_ERR_GET_IRQ_NUM, &irq_num);
+	ASSERT_EQ(0, status) {
+		TH_LOG("ioctl() failed to get the number irqs");
+	}
+	ASSERT_LT(irq_num, 256) {
+		TH_LOG("unexpeced number of irqs");
+	}
+	close(devfd);
+}
+
+TEST_HARNESS_MAIN
Signature · 1 line
2.27.0

Thanks for starting this, I don't know a lot about selftests (yet). So we probably want to get a look at this from corresponding maintainers.

- Moritz

author reviewer
#2 lore raw
Quoted 93 lines · Moritz Fischer

Hi Tom,

Quoted 90 lines · On Sat, Jan 16, 2021 at 11:33:21AM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

Check that the ioctl DFL_FPGA_PORT_ERR_GET_IRQ_NUM returns an expected result.

Tested on vf device 0xbcc1

Sample run with

 # make -C tools/testing/selftests TARGETS=drivers/fpga run_tests
 ...
 TAP version 13
 1..1
 # selftests: drivers/fpga: intr
 # TAP version 13
 # 1..1
 # # Starting 1 tests from 1 test cases.
 # #  RUN           global.afu_intr ...
 # #            OK  global.afu_intr
 # ok 1 global.afu_intr
 # # PASSED: 1 / 1 tests passed.
 # # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
 ok 1 selftests: drivers/fpga: intr

---
v1: Convert to kselftest_harness.h framework

---
 MAINTAINERS                                   |  1 +
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/drivers/fpga/Makefile |  7 ++++
 tools/testing/selftests/drivers/fpga/config   |  1 +
 tools/testing/selftests/drivers/fpga/intr.c   | 36 +++++++++++++++++++
 5 files changed, 46 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/fpga/Makefile
 create mode 100644 tools/testing/selftests/drivers/fpga/config
 create mode 100644 tools/testing/selftests/drivers/fpga/intr.c
MAINTAINERS +1 -0
index de610a06cb5c..7ed3ce58d95e 100644
@@ -6973,6 +6973,7 @@ F:	Documentation/driver-api/fpga/
 F:	Documentation/fpga/
 F:	drivers/fpga/
 F:	include/linux/fpga/
+F:	tools/testing/selftests/drivers/fpga/
 
 FPGA SECURITY MANAGER DRIVERS
 M:	Russ Weight <[email protected]>
tools/testing/selftests/Makefile +1 -0
index afbab4aeef3c..aad4763ec348 100644
@@ -9,6 +9,7 @@ TARGETS += core
 TARGETS += cpufreq
 TARGETS += cpu-hotplug
 TARGETS += drivers/dma-buf
+TARGETS += drivers/fpga
 TARGETS += efivarfs
 TARGETS += exec
 TARGETS += filesystems
tools/testing/selftests/drivers/fpga/Makefile new file +7 -0
new file mode 100644
index 000000000000..eba35c405d5b
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+CFLAGS += -I../../../../../usr/include/
+CFLAGS += -I../../../../../include/uapi/
+
+TEST_GEN_PROGS := intr
+
+include ../../lib.mk
tools/testing/selftests/drivers/fpga/config new file +1 -0
new file mode 100644
index 000000000000..e2111b81d8d7
@@ -0,0 +1 @@
+CONFIG_FPGA_DFL_AFU=m
tools/testing/selftests/drivers/fpga/intr.c new file +3 -0
new file mode 100644
index 000000000000..b362fb1f788d
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdlib.h>
Quoted 8 lines

tools/testing/selftests/drivers/fpga/intr.c line 10

Quoted 7 lines
tools/testing/selftests/drivers/fpga/intr.c new file +7 -0
+#include <stdint.h>
+#include <string.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/fpga-dfl.h>
+
+#include "../../kselftest_harness.h"

Is that how it works with selftests?

I believe so, the big change over v1, is me reading the manual

https://www.kernel.org/doc/html/latest/dev-tools/kselftest.html

Quoted 11 lines

tools/testing/selftests/drivers/fpga/intr.c line 16

Quoted 6 lines
tools/testing/selftests/drivers/fpga/intr.c new file +6 -0
+
+TEST(afu_intr)
+{
+	int devfd, status;
+	struct dfl_fpga_port_info port_info;
+	uint32_t irq_num = UINT32_MAX;

Can you order those?

xxxx
xx
x

yes, v3 is on its way.

Quoted 17 lines
Quoted 17 lines
tools/testing/selftests/drivers/fpga/intr.c new file +17 -0
+
+	devfd = open("/dev/dfl-port.0", O_RDONLY);
+	if (devfd < 0)
+		SKIP(0, "no fpga afu device 0");
+	/*
+	 * From fpga-dl.h :
+	 * Currently hardware supports up to 1 irq.
+	 * Return: 0 on success, -errno on failure.
+	 */
+	status = ioctl(devfd, DFL_FPGA_PORT_ERR_GET_IRQ_NUM, &irq_num);
+	ASSERT_EQ(0, status) {
+		TH_LOG("ioctl() failed to get the number irqs");
+	}
+	ASSERT_LT(irq_num, 256) {
+		TH_LOG("unexpeced number of irqs");
+	}
+	close(devfd);
Quoted 8 lines
Quoted 6 lines
tools/testing/selftests/drivers/fpga/intr.c new file +3 -0
+}
+
+TEST_HARNESS_MAIN
Signature · 1 line
2.27.0

Thanks for starting this, I don't know a lot about selftests (yet). So we probably want to get a look at this from corresponding maintainers.

Me either, that's why I am starting small.

It would be nice to have a set of smoke tests to hook into a c/i.

Tom

Quoted 2 lines

- Moritz