| 1 |
/* |
| 2 |
V4L2 API compliance time32/time64 ioctl tests. |
| 3 |
|
| 4 |
Copyright (C) 2021 Hans Verkuil <[email protected]> |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <sys/types.h> |
| 18 |
|
| 19 |
#include "v4l2-compliance.h" |
| 20 |
|
| 21 |
typedef __s32 old_time32_t; |
| 22 |
|
| 23 |
struct old_timespec32 { |
| 24 |
old_time32_t tv_sec; |
| 25 |
__s32 tv_nsec; |
| 26 |
}; |
| 27 |
|
| 28 |
struct old_timeval32 { |
| 29 |
old_time32_t tv_sec; |
| 30 |
__s32 tv_usec; |
| 31 |
}; |
| 32 |
|
| 33 |
/* |
| 34 |
* The user space interpretation of the 'v4l2_event' differs |
| 35 |
* based on the 'time_t' definition on 32-bit architectures, so |
| 36 |
* the kernel has to handle both. |
| 37 |
* This is the old version for 32-bit architectures. |
| 38 |
*/ |
| 39 |
struct v4l2_event_time32 { |
| 40 |
__u32 type; |
| 41 |
union { |
| 42 |
struct v4l2_event_vsync vsync; |
| 43 |
struct v4l2_event_ctrl ctrl; |
| 44 |
struct v4l2_event_frame_sync frame_sync; |
| 45 |
struct v4l2_event_src_change src_change; |
| 46 |
struct v4l2_event_motion_det motion_det; |
| 47 |
__u8 data[64]; |
| 48 |
} u; |
| 49 |
__u32 pending; |
| 50 |
__u32 sequence; |
| 51 |
struct old_timespec32 timestamp; |
| 52 |
__u32 id; |
| 53 |
__u32 reserved[8]; |
| 54 |
}; |
| 55 |
|
| 56 |
#define VIDIOC_DQEVENT_TIME32 _IOR('V', 89, struct v4l2_event_time32) |
| 57 |
|
| 58 |
typedef __s64 new_time64_t; |
| 59 |
|
| 60 |
struct new_timespec64 { |
| 61 |
new_time64_t tv_sec; |
| 62 |
__s64 tv_nsec; |
| 63 |
}; |
| 64 |
|
| 65 |
struct new_timeval64 { |
| 66 |
new_time64_t tv_sec; |
| 67 |
__s64 tv_usec; |
| 68 |
}; |
| 69 |
|
| 70 |
struct v4l2_event_time64 { |
| 71 |
__u32 type; |
| 72 |
union { |
| 73 |
struct v4l2_event_vsync vsync; |
| 74 |
struct v4l2_event_ctrl ctrl; |
| 75 |
struct v4l2_event_frame_sync frame_sync; |
| 76 |
struct v4l2_event_src_change src_change; |
| 77 |
struct v4l2_event_motion_det motion_det; |
| 78 |
__u8 data[64]; |
| 79 |
} u; |
| 80 |
__u32 pending; |
| 81 |
__u32 sequence; |
| 82 |
struct new_timespec64 timestamp; |
| 83 |
__u32 id; |
| 84 |
__u32 reserved[8]; |
| 85 |
}; |
| 86 |
|
| 87 |
#define VIDIOC_DQEVENT_TIME64 _IOR('V', 89, struct v4l2_event_time64) |
| 88 |
|
| 89 |
struct v4l2_buffer_time32 { |
| 90 |
__u32 index; |
| 91 |
__u32 type; |
| 92 |
__u32 bytesused; |
| 93 |
__u32 flags; |
| 94 |
__u32 field; |
| 95 |
struct old_timeval32 timestamp; |
| 96 |
struct v4l2_timecode timecode; |
| 97 |
__u32 sequence; |
| 98 |
|
| 99 |
/* memory location */ |
| 100 |
__u32 memory; |
| 101 |
union { |
| 102 |
__u32 offset; |
| 103 |
unsigned long userptr; |
| 104 |
struct v4l2_plane *planes; |
| 105 |
__s32 fd; |
| 106 |
} m; |
| 107 |
__u32 length; |
| 108 |
__u32 reserved2; |
| 109 |
union { |
| 110 |
__s32 request_fd; |
| 111 |
__u32 reserved; |
| 112 |
}; |
| 113 |
}; |
| 114 |
#define VIDIOC_QUERYBUF_TIME32 _IOWR('V', 9, struct v4l2_buffer_time32) |
| 115 |
#define VIDIOC_QBUF_TIME32 _IOWR('V', 15, struct v4l2_buffer_time32) |
| 116 |
#define VIDIOC_DQBUF_TIME32 _IOWR('V', 17, struct v4l2_buffer_time32) |
| 117 |
#define VIDIOC_PREPARE_BUF_TIME32 _IOWR('V', 93, struct v4l2_buffer_time32) |
| 118 |
|
| 119 |
int testTime32_64(struct node *node) |
| 120 |
{ |
| 121 |
struct v4l2_event_subscription sub = { 0 }; |
| 122 |
struct v4l2_event_time32 ev32; |
| 123 |
struct v4l2_event_time64 ev64; |
| 124 |
struct v4l2_event ev; |
| 125 |
|
| 126 |
if (node->controls.empty()) |
| 127 |
return 0; |
| 128 |
|
| 129 |
fail_on_test(VIDIOC_DQEVENT != VIDIOC_DQEVENT_TIME32 && |
| 130 |
VIDIOC_DQEVENT != VIDIOC_DQEVENT_TIME64); |
| 131 |
|
| 132 |
for (const auto &control : node->controls) { |
| 133 |
const test_query_ext_ctrl &qctrl = control.second; |
| 134 |
if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) |
| 135 |
continue; |
| 136 |
|
| 137 |
info("checking control event '%s' (0x%08x)\n", qctrl.name, qctrl.id); |
| 138 |
sub.type = V4L2_EVENT_CTRL; |
| 139 |
sub.id = qctrl.id; |
| 140 |
sub.flags = V4L2_EVENT_SUB_FL_SEND_INITIAL; |
| 141 |
fail_on_test(doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub)); |
| 142 |
fail_on_test(doioctl(node, VIDIOC_DQEVENT, &ev)); |
| 143 |
fail_on_test(doioctl(node, VIDIOC_UNSUBSCRIBE_EVENT, &sub)); |
| 144 |
|
| 145 |
fail_on_test(doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub)); |
| 146 |
int ret32 = doioctl(node, VIDIOC_DQEVENT_TIME32, &ev32); |
| 147 |
fail_on_test(doioctl(node, VIDIOC_UNSUBSCRIBE_EVENT, &sub)); |
| 148 |
|
| 149 |
fail_on_test(doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub)); |
| 150 |
int ret64 = doioctl(node, VIDIOC_DQEVENT_TIME64, &ev64); |
| 151 |
fail_on_test(doioctl(node, VIDIOC_UNSUBSCRIBE_EVENT, &sub)); |
| 152 |
|
| 153 |
__u64 ev_ts = ev.timestamp.tv_sec * 1000000000ULL + ev.timestamp.tv_nsec; |
| 154 |
|
| 155 |
if (ret32 != ENOTTY) { |
| 156 |
fail_on_test(ret32); |
| 157 |
fail_on_test(ev.type != ev32.type); |
| 158 |
fail_on_test(ev.id != ev32.id); |
| 159 |
fail_on_test(check_0(ev32.reserved, sizeof(ev32.reserved))); |
| 160 |
__u64 ev32_ts = ev32.timestamp.tv_sec * 1000000000ULL + ev32.timestamp.tv_nsec; |
| 161 |
__s64 delta_ms = (ev32_ts - ev_ts) / 1000000; |
| 162 |
fail_on_test_val(delta_ms > 500, (int)delta_ms); |
| 163 |
info("VIDIOC_DQEVENT 32-bit timespec: %lld ms\n", delta_ms); |
| 164 |
} |
| 165 |
|
| 166 |
if (ret64 != ENOTTY) { |
| 167 |
fail_on_test(ret64); |
| 168 |
fail_on_test(ev.type != ev64.type); |
| 169 |
fail_on_test(ev.id != ev64.id); |
| 170 |
fail_on_test(check_0(ev64.reserved, sizeof(ev64.reserved))); |
| 171 |
__u64 ev64_ts = ev64.timestamp.tv_sec * 1000000000ULL + ev64.timestamp.tv_nsec; |
| 172 |
__s64 delta_ms = (ev64_ts - ev_ts) / 1000000; |
| 173 |
fail_on_test_val(delta_ms > 500, (int)delta_ms); |
| 174 |
info("VIDIOC_DQEVENT 64-bit timespec: %lld ms\n", delta_ms); |
| 175 |
} |
| 176 |
|
| 177 |
break; |
| 178 |
} |
| 179 |
return 0; |
| 180 |
} |