* [igt-dev] [PATCH i-g-t 1/2] lib/igt_vgem: Use UAPI header
2023-03-09 13:39 [igt-dev] [PATCH i-g-t 0/2] Add negative tests to VGEM Maíra Canal
@ 2023-03-09 13:39 ` Maíra Canal
2023-03-09 13:39 ` [igt-dev] [PATCH i-g-t 2/2] tests/vgem_basic: Add negative tests Maíra Canal
2023-03-09 13:43 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Add negative tests to VGEM Patchwork
2 siblings, 0 replies; 4+ messages in thread
From: Maíra Canal @ 2023-03-09 13:39 UTC (permalink / raw)
To: Melissa Wen, Daniel Vetter, Petri Latvala, Kamil Konieczny; +Cc: igt-dev
Currently, VGEM copies the UAPI header contents to source file. So,
delete the copy from the source file and use the UAPI header directly.
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
lib/igt_vgem.c | 36 +++++++++---------------------------
lib/igt_vgem.h | 4 +---
2 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/lib/igt_vgem.c b/lib/igt_vgem.c
index 468383c7..93c8398e 100644
--- a/lib/igt_vgem.c
+++ b/lib/igt_vgem.c
@@ -94,41 +94,23 @@ void *vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot)
return ptr;
}
-#define LOCAL_VGEM_FENCE_ATTACH 0x1
-#define LOCAL_VGEM_FENCE_SIGNAL 0x2
-
-#define LOCAL_IOCTL_VGEM_FENCE_ATTACH DRM_IOWR( DRM_COMMAND_BASE + LOCAL_VGEM_FENCE_ATTACH, struct local_vgem_fence_attach)
-#define LOCAL_IOCTL_VGEM_FENCE_SIGNAL DRM_IOW( DRM_COMMAND_BASE + LOCAL_VGEM_FENCE_SIGNAL, struct local_vgem_fence_signal)
-
-struct local_vgem_fence_attach {
- uint32_t handle;
- uint32_t flags;
- uint32_t out_fence;
- uint32_t pad;
-};
-
-struct local_vgem_fence_signal {
- uint32_t fence;
- uint32_t flags;
-};
-
bool vgem_has_fences(int fd)
{
- struct local_vgem_fence_signal arg;
+ struct drm_vgem_fence_signal arg;
int err;
err = 0;
memset(&arg, 0, sizeof(arg));
- if (drmIoctl(fd, LOCAL_IOCTL_VGEM_FENCE_SIGNAL, &arg))
+ if (drmIoctl(fd, DRM_IOCTL_VGEM_FENCE_SIGNAL, &arg))
err = -errno;
errno = 0;
return err == -ENOENT;
}
-static int __vgem_fence_attach(int fd, struct local_vgem_fence_attach *arg)
+static int __vgem_fence_attach(int fd, struct drm_vgem_fence_attach *arg)
{
int err = 0;
- if (igt_ioctl(fd, LOCAL_IOCTL_VGEM_FENCE_ATTACH, arg))
+ if (igt_ioctl(fd, DRM_IOCTL_VGEM_FENCE_ATTACH, arg))
err = -errno;
errno = 0;
return err;
@@ -136,7 +118,7 @@ static int __vgem_fence_attach(int fd, struct local_vgem_fence_attach *arg)
bool vgem_fence_has_flag(int fd, unsigned flags)
{
- struct local_vgem_fence_attach arg;
+ struct drm_vgem_fence_attach arg;
struct vgem_bo bo;
bool ret = false;
@@ -160,7 +142,7 @@ bool vgem_fence_has_flag(int fd, unsigned flags)
uint32_t vgem_fence_attach(int fd, struct vgem_bo *bo, unsigned flags)
{
- struct local_vgem_fence_attach arg;
+ struct drm_vgem_fence_attach arg;
memset(&arg, 0, sizeof(arg));
arg.handle = bo->handle;
@@ -169,10 +151,10 @@ uint32_t vgem_fence_attach(int fd, struct vgem_bo *bo, unsigned flags)
return arg.out_fence;
}
-static int ioctl_vgem_fence_signal(int fd, struct local_vgem_fence_signal *arg)
+static int ioctl_vgem_fence_signal(int fd, struct drm_vgem_fence_signal *arg)
{
int err = 0;
- if (igt_ioctl(fd, LOCAL_IOCTL_VGEM_FENCE_SIGNAL, arg))
+ if (igt_ioctl(fd, DRM_IOCTL_VGEM_FENCE_SIGNAL, arg))
err = -errno;
errno = 0;
return err;
@@ -180,7 +162,7 @@ static int ioctl_vgem_fence_signal(int fd, struct local_vgem_fence_signal *arg)
int __vgem_fence_signal(int fd, uint32_t fence)
{
- struct local_vgem_fence_signal arg;
+ struct drm_vgem_fence_signal arg;
memset(&arg, 0, sizeof(arg));
arg.fence = fence;
diff --git a/lib/igt_vgem.h b/lib/igt_vgem.h
index 92045f0e..a9220df7 100644
--- a/lib/igt_vgem.h
+++ b/lib/igt_vgem.h
@@ -24,8 +24,7 @@
#ifndef IGT_VGEM_H
#define IGT_VGEM_H
-#include <stdint.h>
-#include <stdbool.h>
+#include "vgem_drm.h"
struct vgem_bo {
uint32_t handle;
@@ -43,7 +42,6 @@ void *vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot);
bool vgem_has_fences(int fd);
bool vgem_fence_has_flag(int fd, unsigned flags);
uint32_t vgem_fence_attach(int fd, struct vgem_bo *bo, unsigned flags);
-#define VGEM_FENCE_WRITE 0x1
#define WIP_VGEM_FENCE_NOTIMEOUT 0x2
int __vgem_fence_signal(int fd, uint32_t fence);
void vgem_fence_signal(int fd, uint32_t fence);
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [igt-dev] [PATCH i-g-t 2/2] tests/vgem_basic: Add negative tests
2023-03-09 13:39 [igt-dev] [PATCH i-g-t 0/2] Add negative tests to VGEM Maíra Canal
2023-03-09 13:39 ` [igt-dev] [PATCH i-g-t 1/2] lib/igt_vgem: Use UAPI header Maíra Canal
@ 2023-03-09 13:39 ` Maíra Canal
2023-03-09 13:43 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Add negative tests to VGEM Patchwork
2 siblings, 0 replies; 4+ messages in thread
From: Maíra Canal @ 2023-03-09 13:39 UTC (permalink / raw)
To: Melissa Wen, Daniel Vetter, Petri Latvala, Kamil Konieczny; +Cc: igt-dev
Currently, the vgem_basic tests don't cover any negative tests. So, add
tests covering possible error paths of the driver by inputting invalid
arguments and checking if the driver is returning the correct values.
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
tests/vgem_basic.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/tests/vgem_basic.c b/tests/vgem_basic.c
index 2a2900f8..4f371b3d 100644
--- a/tests/vgem_basic.c
+++ b/tests/vgem_basic.c
@@ -152,6 +152,27 @@ static void test_dmabuf_export(int fd)
close(other);
}
+static void test_busy_fence(int fd)
+{
+ struct drm_vgem_fence_attach arg = {};
+ struct vgem_bo bo;
+
+ bo.width = 1024;
+ bo.height = 1;
+ bo.bpp = 32;
+ vgem_create(fd, &bo);
+
+ /* Attach a fence for reading */
+ vgem_fence_attach(fd, &bo, 0);
+
+ /* Attach a fence for writing, so it should be an exclusive fence */
+ arg.handle = bo.handle;
+ arg.flags = VGEM_FENCE_WRITE;
+
+ /* As the fence is not exclusive, return -EBUSY, indicating a conflicting fence */
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_ATTACH, &arg, EBUSY);
+}
+
static void test_dmabuf_mmap(int fd)
{
struct vgem_bo bo;
@@ -434,6 +455,48 @@ igt_main
igt_subtest_f("mmap")
test_mmap(fd);
+ igt_describe("Make sure a fence cannot be attached and signaled with invalid flags.");
+ igt_subtest("bad-flag") {
+ struct drm_vgem_fence_attach attach = {
+ .flags = 0xff,
+ };
+
+ struct drm_vgem_fence_signal signal = {
+ .flags = 0xff,
+ };
+
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_ATTACH, &attach, EINVAL);
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_SIGNAL, &signal, EINVAL);
+ }
+
+ igt_describe("Make sure the pad is zero.");
+ igt_subtest("bad-pad") {
+ struct drm_vgem_fence_attach arg = {
+ .pad = 0x01,
+ };
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_ATTACH, &arg, EINVAL);
+ }
+
+ igt_describe("Make sure a fence cannot be attached to a invalid handle.");
+ igt_subtest("bad-handle") {
+ struct drm_vgem_fence_attach arg = {
+ .handle = 0xff,
+ };
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_ATTACH, &arg, ENOENT);
+ }
+
+ igt_describe("Make sure a non-existent fence cannot be signaled.");
+ igt_subtest("bad-fence") {
+ struct drm_vgem_fence_signal arg = {
+ .fence = 0xff,
+ };
+ do_ioctl_err(fd, DRM_IOCTL_VGEM_FENCE_SIGNAL, &arg, ENOENT);
+ }
+
+ igt_describe("Make sure a conflicting fence cannot be attached.");
+ igt_subtest("busy-fence")
+ test_busy_fence(fd);
+
igt_subtest_group {
igt_fixture {
igt_require(has_prime_export(fd));
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread