From 1ebf6c0d8d3b4b990d2439c55b37fc0ab0920f1f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 12 Oct 2020 16:52:38 +0200 Subject: [PATCH] tests: break tests if line requests fail In many test-cases we read/set values or try to poll for events after a failed line request. Some tests even segfault because they don't check returned values for NULL etc. Bail out of test cases if a line request failed. Signed-off-by: Bartosz Golaszewski --- tests/tests-event.c | 20 ++++++++++++++++++++ tests/tests-line.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/tests-event.c b/tests/tests-event.c index 6066e45..ad49f70 100644 --- a/tests/tests-event.c +++ b/tests/tests-event.c @@ -31,6 +31,7 @@ GPIOD_TEST_CASE(rising_edge_good, 0, { 8 }) ret = gpiod_line_request_rising_edge_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -63,6 +64,7 @@ GPIOD_TEST_CASE(falling_edge_good, 0, { 8 }) ret = gpiod_line_request_falling_edge_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -94,6 +96,7 @@ GPIOD_TEST_CASE(rising_edge_ignore_falling, 0, { 8 }) ret = gpiod_line_request_rising_edge_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -136,6 +139,7 @@ GPIOD_TEST_CASE(both_edges, 0, { 8 }) ret = gpiod_line_request_both_edges_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -176,6 +180,7 @@ GPIOD_TEST_CASE(both_edges_active_low, 0, { 8 }) ret = gpiod_line_request_both_edges_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -216,6 +221,7 @@ GPIOD_TEST_CASE(both_edges_bias_disable, 0, { 8 }) ret = gpiod_line_request_both_edges_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -256,6 +262,7 @@ GPIOD_TEST_CASE(both_edges_bias_pull_down, 0, { 8 }) ret = gpiod_line_request_both_edges_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -296,6 +303,7 @@ GPIOD_TEST_CASE(both_edges_bias_pull_up, 0, { 8 }) ret = gpiod_line_request_both_edges_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -336,6 +344,7 @@ GPIOD_TEST_CASE(falling_edge_active_low, 0, { 8 }) ret = gpiod_line_request_falling_edge_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 7, 100); @@ -369,6 +378,7 @@ GPIOD_TEST_CASE(get_value, 0, { 8 }) ret = gpiod_line_request_falling_edge_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ret = gpiod_line_get_value(line); g_assert_cmpint(ret, ==, 1); @@ -406,6 +416,7 @@ GPIOD_TEST_CASE(get_value_active_low, 0, { 8 }) ret = gpiod_line_request_falling_edge_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ret = gpiod_line_get_value(line); g_assert_cmpint(ret, ==, 0); @@ -445,6 +456,7 @@ GPIOD_TEST_CASE(get_values, 0, { 8 }) ret = gpiod_line_request_bulk_rising_edge_events(&bulk, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); memset(vals, 0, sizeof(vals)); ret = gpiod_line_get_value_bulk(&bulk, vals); @@ -500,6 +512,7 @@ GPIOD_TEST_CASE(get_values_active_low, 0, { 8 }) ret = gpiod_line_request_bulk_rising_edge_events_flags(&bulk, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); memset(vals, 0, sizeof(vals)); ret = gpiod_line_get_value_bulk(&bulk, vals); @@ -557,6 +570,7 @@ GPIOD_TEST_CASE(wait_multiple, 0, { 8 }) ret = gpiod_line_request_bulk_rising_edge_events(&bulk, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ev_thread = gpiod_test_start_event_thread(0, 4, 100); @@ -588,6 +602,7 @@ GPIOD_TEST_CASE(get_fd_when_values_requested, 0, { 8 }) ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); fd = gpiod_line_event_get_fd(line); g_assert_cmpint(fd, ==, -1); @@ -611,6 +626,7 @@ GPIOD_TEST_CASE(request_bulk_fail, 0, { 8 }) ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); for (i = 0; i < 8; i++) { line = gpiod_chip_get_line(chip, i); @@ -644,6 +660,7 @@ GPIOD_TEST_CASE(invalid_fd, 0, { 8 }) ret = gpiod_line_request_both_edges_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); fd = gpiod_line_event_get_fd(line); close(fd); @@ -683,6 +700,7 @@ GPIOD_TEST_CASE(read_events_individually, 0, { 8 }) ret = gpiod_line_request_both_edges_events_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); /* generate multiple events */ for (i = 0; i < 3; i++) { @@ -744,6 +762,7 @@ GPIOD_TEST_CASE(read_multiple_events, 0, { 8 }) ret = gpiod_line_request_both_edges_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); /* generate multiple events */ for (i = 0; i < 7; i++) { @@ -818,6 +837,7 @@ GPIOD_TEST_CASE(read_multiple_events_fd, 0, { 8 }) ret = gpiod_line_request_both_edges_events(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); /* generate multiple events */ for (i = 0; i < 7; i++) { diff --git a/tests/tests-line.c b/tests/tests-line.c index 334046f..2de9ad2 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -33,6 +33,7 @@ GPIOD_TEST_CASE(request_output, 0, { 8 }) g_assert_cmpint(ret, ==, 0); ret = gpiod_line_request_output(line1, GPIOD_TEST_CONSUMER, 1); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); g_assert_cmpint(gpiod_test_chip_get_value(0, 5), ==, 1); @@ -54,6 +55,7 @@ GPIOD_TEST_CASE(request_already_requested, 0, { 8 }) ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, -1); @@ -100,6 +102,7 @@ GPIOD_TEST_CASE(consumer_long_string, 0, { 8 }) ret = gpiod_line_request_input(line, "consumer string over 32 characters long"); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpstr(gpiod_line_consumer(line), ==, "consumer string over 32 charact"); g_assert_cmpuint(strlen(gpiod_line_consumer(line)), ==, 31); @@ -156,6 +159,7 @@ GPIOD_TEST_CASE(request_bulk_output, 0, { 8, 8 }) ret = gpiod_line_request_bulk_output(&bulkA, GPIOD_TEST_CONSUMER, valA); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); valB[0] = 0; valB[1] = 1; @@ -164,6 +168,7 @@ GPIOD_TEST_CASE(request_bulk_output, 0, { 8, 8 }) ret = gpiod_line_request_bulk_output(&bulkB, GPIOD_TEST_CONSUMER, valB); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 1); g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); @@ -243,6 +248,7 @@ GPIOD_TEST_CASE(request_null_default_vals_for_output, 0, { 8 }) ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, NULL); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 0); @@ -265,6 +271,7 @@ GPIOD_TEST_CASE(set_value, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); ret = gpiod_line_set_value(line, 1); @@ -307,6 +314,7 @@ GPIOD_TEST_CASE(set_value_bulk, 0, { 8 }) ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, values); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 0), ==, 0); g_assert_cmpint(gpiod_test_chip_get_value(0, 1), ==, 1); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); @@ -354,6 +362,7 @@ GPIOD_TEST_CASE(set_config_bulk_null_values, 0, { 8 }) ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_active_state(line0), ==, GPIOD_LINE_ACTIVE_STATE_HIGH); g_assert_cmpint(gpiod_line_active_state(line1), ==, @@ -408,6 +417,7 @@ GPIOD_TEST_CASE(set_flags_active_state, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_active_state(line), ==, GPIOD_LINE_ACTIVE_STATE_HIGH); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); @@ -441,6 +451,7 @@ GPIOD_TEST_CASE(set_flags_bias, 0, { 8 }) ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_bias(line), ==, GPIOD_LINE_BIAS_AS_IS); ret = gpiod_line_set_flags(line, @@ -477,6 +488,7 @@ GPIOD_TEST_CASE(set_flags_drive, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_is_open_drain(line), ==, false); g_assert_cmpint(gpiod_line_is_open_source(line), ==, false); @@ -509,6 +521,7 @@ GPIOD_TEST_CASE(set_direction, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 0); @@ -557,6 +570,7 @@ GPIOD_TEST_CASE(set_direction_bulk, 0, { 8 }) ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, values); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line0), ==, GPIOD_LINE_DIRECTION_OUTPUT); g_assert_cmpint(gpiod_line_direction(line1), ==, @@ -623,6 +637,7 @@ GPIOD_TEST_CASE(output_value_caching, 0, { 8 }) /* check cached by request... */ ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_test_chip_get_value(0, 2), ==, 1); /* ...by checking cached value applied by set_flags */ @@ -715,6 +730,7 @@ GPIOD_TEST_CASE(get_value_different_chips, 0, { 8, 8 }) g_assert_cmpint(ret, ==, 0); ret = gpiod_line_request_bulk_input(&bulkB, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); ret = gpiod_line_get_value_bulk(&bulk, vals); g_assert_cmpint(ret, ==, -1); @@ -789,6 +805,7 @@ GPIOD_TEST_CASE(direction, 0, { 8 }) ret = gpiod_line_request_output(line, GPIOD_TEST_CONSUMER, 1); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); g_assert_cmpint(gpiod_test_chip_get_value(0, 5), ==, 1); @@ -817,6 +834,7 @@ GPIOD_TEST_CASE(active_state, 0, { 8 }) ret = gpiod_line_request_input(line, GPIOD_TEST_CONSUMER); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_active_state(line), ==, GPIOD_LINE_ACTIVE_STATE_HIGH); @@ -826,6 +844,7 @@ GPIOD_TEST_CASE(active_state, 0, { 8 }) ret = gpiod_line_request_input_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_INPUT); @@ -835,6 +854,7 @@ GPIOD_TEST_CASE(active_state, 0, { 8 }) ret = gpiod_line_request_output_flags(line, GPIOD_TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); @@ -845,6 +865,7 @@ GPIOD_TEST_CASE(active_state, 0, { 8 }) ret = gpiod_line_request_output_flags(line, GPIOD_TEST_CONSUMER, 0, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpint(gpiod_line_direction(line), ==, GPIOD_LINE_DIRECTION_OUTPUT); @@ -878,6 +899,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_true(gpiod_line_is_open_drain(line)); @@ -892,6 +914,7 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); @@ -930,6 +953,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_true(gpiod_line_is_open_drain(line)); @@ -947,6 +971,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); @@ -968,6 +993,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); @@ -988,6 +1014,7 @@ GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_true(gpiod_line_is_used(line)); g_assert_false(gpiod_line_is_open_drain(line)); @@ -1118,6 +1145,7 @@ GPIOD_TEST_CASE(release_one_use_another, 0, { 8 }) ret = gpiod_line_request_bulk_output(&bulk, GPIOD_TEST_CONSUMER, vals); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); gpiod_line_release(line0); @@ -1147,6 +1175,7 @@ GPIOD_TEST_CASE(null_consumer, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpstr(gpiod_line_consumer(line), ==, "?"); gpiod_line_release(line); @@ -1183,6 +1212,7 @@ GPIOD_TEST_CASE(empty_consumer, 0, { 8 }) ret = gpiod_line_request(line, &config, 0); g_assert_cmpint(ret, ==, 0); + gpiod_test_return_if_failed(); g_assert_cmpstr(gpiod_line_consumer(line), ==, "?"); gpiod_line_release(line); -- 2.30.2