1 /*
2 V4L2 API compliance debug ioctl tests.
3
4 Copyright (C) 2008, 2010 Hans Verkuil <hverkuil@xs4all.nl>
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 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
19 */
20
21 #include <map>
22 #include <set>
23
24 #include <sys/types.h>
25
26 #include "v4l2-compliance.h"
27
testRegister(struct node * node)28 int testRegister(struct node *node)
29 {
30 struct v4l2_dbg_register reg;
31 struct v4l2_dbg_chip_info chip = {};
32 int ret;
33 int uid = getuid();
34
35 reg.match.type = V4L2_CHIP_MATCH_BRIDGE;
36 reg.match.addr = 0;
37 reg.reg = 0;
38 ret = doioctl(node, VIDIOC_DBG_G_REGISTER, ®);
39 if (ret == ENOTTY)
40 return ret;
41 // Not allowed to call VIDIOC_DBG_G_REGISTER unless root
42 fail_on_test(uid && ret != EPERM);
43 fail_on_test(uid == 0 && ret && ret != EINVAL);
44 fail_on_test(uid == 0 && !ret && reg.size == 0);
45 chip.match.type = V4L2_CHIP_MATCH_BRIDGE;
46 chip.match.addr = 0;
47 fail_on_test(doioctl(node, VIDIOC_DBG_G_CHIP_INFO, &chip));
48 if (uid) {
49 // Don't test S_REGISTER as root, don't want to risk
50 // messing with registers in the compliance test.
51 reg.reg = reg.val = 0;
52 ret = doioctl(node, VIDIOC_DBG_S_REGISTER, ®);
53 fail_on_test(ret != ENOTTY && ret != EINVAL && ret != EPERM);
54 }
55 return 0;
56 }
57
testLogStatus(struct node * node)58 int testLogStatus(struct node *node)
59 {
60 return doioctl(node, VIDIOC_LOG_STATUS, nullptr);
61 }
62