aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2020-03-19 13:01:23 +0100
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2020-03-19 13:01:23 +0100
commitfa0e9cde7e847601b550868e535965ea058b68ab (patch)
tree3de42619e736d7276f663e92cd35549867aee7e2
parent51d148f97e241806f6c6985077012937c7b7d1c0 (diff)
cec-ctl: introduce and use transmit_msg_retry()
Some transmits should be retried if ENONET is returned or EINVAL and the initiator was Unregistered. Add a new function for that and use that in the stress tests. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/cec-ctl/cec-ctl.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index 9a6f15d0..29e2b481 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -1100,6 +1100,23 @@ static bool wait_for_pwr_state(struct node &node, unsigned from, bool on)
return pwr == (on ? CEC_OP_POWER_STATUS_ON : CEC_OP_POWER_STATUS_STANDBY);
}
+static int transmit_msg_retry(struct node &node, struct cec_msg &msg)
+{
+ bool from_unreg = cec_msg_initiator(&msg) == CEC_LOG_ADDR_UNREGISTERED;
+ unsigned cnt = 0;
+ bool repeat;
+ int ret;
+
+ // Can happen if wakeup_la == 15 and CEC just started configuring
+ do {
+ ret = doioctl(&node, CEC_TRANSMIT, &msg);
+ repeat = ret == ENONET || (ret == EINVAL && from_unreg);
+ if (repeat)
+ usleep(100000);
+ } while (repeat && cnt++ < 10);
+ return ret;
+}
+
static int init_power_cycle_test(struct node &node, unsigned repeats, unsigned max_tries)
{
struct cec_msg msg;
@@ -1162,7 +1179,7 @@ static int init_power_cycle_test(struct node &node, unsigned repeats, unsigned m
fflush(stdout);
cec_msg_init(&msg, from, CEC_LOG_ADDR_TV);
cec_msg_active_source(&msg, pa);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
+ ret = transmit_msg_retry(node, msg);
if (ret) {
printf("FAIL: %s\n", strerror(ret));
exit(1);
@@ -1180,7 +1197,7 @@ static int init_power_cycle_test(struct node &node, unsigned repeats, unsigned m
if (laddrs.log_addr[0] == CEC_LOG_ADDR_INVALID)
break;
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
+ ret = transmit_msg_retry(node, msg);
if (ret) {
printf("FAIL: %s\n", strerror(ret));
exit(1);
@@ -1250,13 +1267,8 @@ static void test_power_cycle(struct node &node, unsigned int max_tries,
fflush(stdout);
cec_msg_init(&msg, wakeup_la, CEC_LOG_ADDR_TV);
cec_msg_image_view_on(&msg);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(ENONET) ");
- } else if (ret == EINVAL && wakeup_la == CEC_LOG_ADDR_UNREGISTERED) {
- // Can happen if wakeup_la == 15 and CEC just started configuring
- printf("(EINVAL) ");
- } else if (ret) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret) {
printf("FAIL: %s\n", strerror(ret));
exit(1);
}
@@ -1345,19 +1357,15 @@ static void test_power_cycle(struct node &node, unsigned int max_tries,
*/
cec_msg_init(&msg, from, CEC_LOG_ADDR_TV);
cec_msg_active_source(&msg, pa);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(Active Source: ENONET) ");
- } else if (ret) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret) {
printf("FAIL: Active Source Transmit failed: %s\n", strerror(ret));
exit(1);
}
cec_msg_init(&msg, from, CEC_LOG_ADDR_TV);
cec_msg_standby(&msg);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(Standby: ENONET) ");
- } else if (ret) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret) {
printf("FAIL: %s\n", strerror(ret));
exit(1);
}
@@ -1468,10 +1476,8 @@ static void stress_test_power_cycle(struct node &node,
tries = 0;
cec_msg_init(&msg, wakeup_la, CEC_LOG_ADDR_TV);
cec_msg_image_view_on(&msg);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(ENONET) ");
- } else if (ret == EINVAL && wakeup_la == CEC_LOG_ADDR_UNREGISTERED) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret == EINVAL && wakeup_la == CEC_LOG_ADDR_UNREGISTERED) {
// Can happen if wakeup_la == 15 and CEC just started configuring
printf("(EINVAL) ");
} else if (ret) {
@@ -1539,18 +1545,14 @@ static void stress_test_power_cycle(struct node &node,
* So make us the Active Source before sending Standby.
*/
cec_msg_active_source(&msg, pa);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(Active Source: ENONET) ");
- } else if (ret) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret) {
printf("FAIL: Active Source Transmit failed: %s\n", strerror(ret));
exit(1);
}
cec_msg_standby(&msg);
- ret = doioctl(&node, CEC_TRANSMIT, &msg);
- if (ret == ENONET) {
- printf("(Standby: ENONET) ");
- } else if (ret) {
+ ret = transmit_msg_retry(node, msg);
+ if (ret) {
printf("FAIL: %s\n", strerror(ret));
exit(1);
}

Privacy Policy