aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:03:18 (GMT)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2019-02-04 13:03:18 (GMT)
commit09dfe99e13a71a09e2c353b4339106fa7540451c (patch)
treeaccde0586acc5066cbff14df44deb55798f12535
parent48d28562ffcd9f63276a636d64e90ca875e3a98e (diff)
cec-compliance: add -D and -a support
With these options you can uniquely identify a CEC device without having to know the device node name. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/cec-compliance/cec-compliance.1.in10
-rw-r--r--utils/cec-compliance/cec-compliance.cpp44
2 files changed, 45 insertions, 9 deletions
diff --git a/utils/cec-compliance/cec-compliance.1.in b/utils/cec-compliance/cec-compliance.1.in
index 4138ad5..205561f 100644
--- a/utils/cec-compliance/cec-compliance.1.in
+++ b/utils/cec-compliance/cec-compliance.1.in
@@ -74,6 +74,16 @@ tests they depend on failed, and they will not be shown in the test listing.
\fB\-d\fR, \fB\-\-device\fR \fI<dev>\fR
Use device <dev> as the CEC device. If <dev> is a number, then /dev/cec<dev> is used.
.TP
+\fB\-D\fR, \fB\-\-driver\fR \fI<drv>\fR
+Use a cec device that has driver name \fI<drv>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-a\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
+\fB\-a\fR, \fB\-\-adapter\fR \fI<adap-name>\fR
+Use a cec device that has adapter name \fI<adap-name>\fR, as returned by the CEC_ADAP_G_CAPS ioctl.
+This option can be combined with \fB\-D\fR to uniquely identify a CEC device without
+having to rely on the device node number.
+.TP
\fB\-E\fR, \fB\-\-exit\-on\-fail\fR
Exit this application when the first failure occurs instead of continuing
with a possible inconsistent state.
diff --git a/utils/cec-compliance/cec-compliance.cpp b/utils/cec-compliance/cec-compliance.cpp
index e846880..1f70ade 100644
--- a/utils/cec-compliance/cec-compliance.cpp
+++ b/utils/cec-compliance/cec-compliance.cpp
@@ -34,8 +34,10 @@
In general the lower case is used to set something and the upper
case is used to retrieve a setting. */
enum Option {
+ OptSetAdapter = 'a',
OptTestAdapter = 'A',
OptSetDevice = 'd',
+ OptSetDriver = 'D',
OptExitOnFail = 'E',
OptHelp = 'h',
OptInteractive = 'i',
@@ -108,6 +110,8 @@ time_t long_timeout = 60;
static struct option long_options[] = {
{"device", required_argument, 0, OptSetDevice},
+ {"adapter", required_argument, 0, OptSetAdapter},
+ {"driver", required_argument, 0, OptSetDriver},
{"help", no_argument, 0, OptHelp},
{"no-warnings", no_argument, 0, OptNoWarnings},
{"exit-on-fail", no_argument, 0, OptExitOnFail},
@@ -170,6 +174,8 @@ static void usage(void)
printf("Usage:\n"
" -d, --device <dev> Use device <dev> instead of /dev/cec0\n"
" If <dev> starts with a digit, then /dev/cec<dev> is used.\n"
+ " -D, --driver <driver> Use a cec device with this driver name\n"
+ " -a, --adapter <adapter> Use a cec device with this adapter name\n"
" -r, --remote [<la>] As initiator test the remote logical address or all LAs if no LA was given\n"
" -R, --reply-threshold <timeout>\n"
" Warn if replies take longer than this threshold (default 1000ms)\n"
@@ -1039,7 +1045,9 @@ static void topology_probe_device(struct node *node, unsigned i, unsigned la)
int main(int argc, char **argv)
{
- const char *device = "/dev/cec0"; /* -d device */
+ std::string device;
+ const char *driver = NULL;
+ const char *adapter = NULL;
char short_options[26 * 2 * 2 + 1];
int remote_la = -1;
bool test_remote = false;
@@ -1088,13 +1096,19 @@ int main(int argc, char **argv)
return 0;
case OptSetDevice:
device = optarg;
- if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) {
+ if (device[0] >= '0' && device[0] <= '9' && device.length() <= 3) {
static char newdev[20];
- sprintf(newdev, "/dev/cec%s", device);
+ sprintf(newdev, "/dev/cec%s", optarg);
device = newdev;
}
break;
+ case OptSetDriver:
+ driver = optarg;
+ break;
+ case OptSetAdapter:
+ adapter = optarg;
+ break;
case OptReplyThreshold:
reply_threshold = strtoul(optarg, NULL, 0);
break;
@@ -1146,8 +1160,19 @@ int main(int argc, char **argv)
return 1;
}
- if ((fd = open(device, O_RDWR)) < 0) {
- fprintf(stderr, "Failed to open %s: %s\n", device,
+ if (device.empty() && (driver || adapter)) {
+ device = cec_device_find(driver, adapter);
+ if (device.empty()) {
+ fprintf(stderr,
+ "Could not find a CEC device for the given driver/adapter combination\n");
+ exit(1);
+ }
+ }
+ if (device.empty())
+ device = "/dev/cec0";
+
+ if ((fd = open(device.c_str(), O_RDWR)) < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n", device.c_str(),
strerror(errno));
exit(1);
}
@@ -1156,7 +1181,7 @@ int main(int argc, char **argv)
struct cec_caps caps = { };
node.fd = fd;
- node.device = device;
+ node.device = device.c_str();
doioctl(&node, CEC_ADAP_G_CAPS, &caps);
node.caps = caps.capabilities;
node.available_log_addrs = caps.available_log_addrs;
@@ -1308,7 +1333,8 @@ int main(int argc, char **argv)
exit(-1);
if (!options[OptSkipInfo]) {
- printf("\nCompliance test for %s device %s:\n\n", caps.driver, device);
+ printf("\nCompliance test for %s device %s:\n\n",
+ caps.driver, device.c_str());
printf(" The test results mean the following:\n"
" OK Supported correctly by the device.\n"
" OK (Not Supported) Not supported and not mandatory for the device.\n"
@@ -1332,7 +1358,7 @@ int main(int argc, char **argv)
}
if (options[OptTestAdapter])
- testAdapter(node, laddrs, device);
+ testAdapter(node, laddrs, device.c_str());
printf("\n");
printf("Network topology:\n");
@@ -1363,7 +1389,7 @@ int main(int argc, char **argv)
close(fd);
printf("Total for %s device %s: %d, Succeeded: %d, Failed: %d, Warnings: %d\n",
- caps.driver, device,
+ caps.driver, device.c_str(),
tests_total, tests_ok, tests_total - tests_ok, warnings);
exit(app_result);
}

Privacy Policy