X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=drm-lease-manager%2Ftest%2Flease-manager-test.c;h=b32cd05291cb31b64bf5d2728f39076bd7e4c6fc;hb=refs%2Fchanges%2F81%2F27381%2F3;hp=5d19992070883ebdedb3ec3c2a753cb01921b326;hpb=e39cb4f5d10e162bc7a5a5a173581c1924d475ea;p=src%2Fdrm-lease-manager.git diff --git a/drm-lease-manager/test/lease-manager-test.c b/drm-lease-manager/test/lease-manager-test.c index 5d19992..b32cd05 100644 --- a/drm-lease-manager/test/lease-manager-test.c +++ b/drm-lease-manager/test/lease-manager-test.c @@ -25,6 +25,8 @@ #include "test-drm-device.h" #include "test-helpers.h" +#define INVALID_OBJECT_ID (0) + /* CHECK_LEASE_OBJECTS * * Checks the list of objects associated with a given lease_index. @@ -358,6 +360,47 @@ START_TEST(create_and_revoke_lease) } END_TEST +/* Test lease names */ +/* Test details: Create some leases and verify that they have the correct names + * Expected results: lease names should match the expected values + */ +START_TEST(verify_lease_names) +{ + int lease_cnt = 3; + bool res = setup_drm_test_device(lease_cnt, lease_cnt, lease_cnt, 0); + ck_assert_int_eq(res, true); + + drmModeConnector connectors[] = { + CONNECTOR_FULL(CONNECTOR_ID(0), ENCODER_ID(0), &ENCODER_ID(0), 1, + DRM_MODE_CONNECTOR_HDMIA, 1), + CONNECTOR_FULL(CONNECTOR_ID(1), ENCODER_ID(1), &ENCODER_ID(1), 1, + DRM_MODE_CONNECTOR_LVDS, 3), + CONNECTOR_FULL(CONNECTOR_ID(2), ENCODER_ID(2), &ENCODER_ID(2), 1, + DRM_MODE_CONNECTOR_eDP, 6), + }; + + drmModeEncoder encoders[] = { + ENCODER(ENCODER_ID(0), CRTC_ID(0), 0x7), + ENCODER(ENCODER_ID(1), CRTC_ID(1), 0x7), + ENCODER(ENCODER_ID(2), CRTC_ID(2), 0x7), + }; + + setup_test_device_layout(connectors, encoders, NULL); + + const char *expected_names[] = { + "card3-HDMI-A-1", + "card3-LVDS-3", + "card3-eDP-6", + }; + + struct lease_handle **handles = create_leases(lease_cnt, NULL); + + for (int i = 0; i < lease_cnt; i++) { + ck_assert_str_eq(handles[i]->name, expected_names[i]); + } +} +END_TEST + static void add_lease_management_tests(Suite *s) { TCase *tc = tcase_create("Lease management"); @@ -365,6 +408,131 @@ static void add_lease_management_tests(Suite *s) tcase_add_checked_fixture(tc, test_setup, test_shutdown); tcase_add_test(tc, create_and_revoke_lease); + tcase_add_test(tc, verify_lease_names); + suite_add_tcase(s, tc); +} + +/***************** Lease Configuration Tests *************/ + +/* multiple_connector_lease */ +/* Test details: Create a lease with multipe connectors + * Expected results: a lease is created with the CRTC and connector ID for both + * connectors. + */ +START_TEST(multiple_connector_lease) +{ + int out_cnt = 2, plane_cnt = 0, lease_cnt = 1; + + setup_layout_simple_test_device(out_cnt, plane_cnt); + + struct lease_config lconfig = { + .lease_name = "Lease Config Test 1", + .ncids = 2, + .connector_ids = (uint32_t[]){CONNECTOR_ID(0), CONNECTOR_ID(1)}, + }; + + struct lease_handle **handles = create_leases(lease_cnt, &lconfig); + + CHECK_LEASE_OBJECTS(handles[0], CRTC_ID(0), CONNECTOR_ID(0), CRTC_ID(1), + CONNECTOR_ID(1)); +} +END_TEST + +/* single_failed_lease */ +/* Test details: Create 2 lease configs. One with valid data, one without. + * Expected results: A handle is created for the single valid lease. + */ +START_TEST(single_failed_lease) +{ + int out_cnt = 3, plane_cnt = 0, success_lease_cnt = 1; + + setup_layout_simple_test_device(out_cnt, plane_cnt); + + struct lease_config lconfigs[2] = { + [0] = + { + .lease_name = "Lease Config Test 1", + .ncids = 1, + .connector_ids = (uint32_t[]){INVALID_OBJECT_ID}, + }, + [1] = + { + .lease_name = "Lease Config Test 2", + .ncids = 2, + .connector_ids = + (uint32_t[]){CONNECTOR_ID(0), CONNECTOR_ID(1)}, + }, + }; + + /* Expect fewer leases than configurations supplied, so explicitly + * create and check leases. */ + g_lm = lm_create_with_config(TEST_DRM_DEVICE, ARRAY_LEN(lconfigs), + lconfigs); + ck_assert_ptr_ne(g_lm, NULL); + + struct lease_handle **handles; + ck_assert_int_eq(success_lease_cnt, + lm_get_lease_handles(g_lm, &handles)); + ck_assert_ptr_ne(handles, NULL); + + CHECK_LEASE_OBJECTS(handles[0], CRTC_ID(0), CONNECTOR_ID(0), CRTC_ID(1), + CONNECTOR_ID(1)); +} +END_TEST + +/* named_connector_config */ +/* Test details: Test specifying connectors by name in config + * Expected results: A handle is created for each named connector + */ + +START_TEST(named_connector_config) +{ + int out_cnt = 2, plane_cnt = 0, lease_cnt = 1; + + ck_assert_int_eq( + setup_drm_test_device(out_cnt, out_cnt, out_cnt, plane_cnt), true); + + drmModeConnector connectors[] = { + CONNECTOR_FULL(CONNECTOR_ID(0), ENCODER_ID(0), &ENCODER_ID(0), 1, + DRM_MODE_CONNECTOR_HDMIA, 1), + CONNECTOR_FULL(CONNECTOR_ID(1), ENCODER_ID(1), &ENCODER_ID(1), 1, + DRM_MODE_CONNECTOR_VGA, 3), + }; + + drmModeEncoder encoders[] = { + ENCODER(ENCODER_ID(0), CRTC_ID(0), 0x1), + ENCODER(ENCODER_ID(1), CRTC_ID(1), 0x2), + }; + + setup_test_device_layout(connectors, encoders, NULL); + + struct lease_config lconfig = { + .lease_name = "Lease Config Test 1", + .nconnectors = 2, + .connectors = + (struct connector_config[]){ + {.name = "HDMI-A-1"}, + {.name = "VGA-3"}, + }, + }; + + struct lease_handle **handles = create_leases(lease_cnt, &lconfig); + + ck_assert_str_eq(handles[0]->name, lconfig.lease_name); + CHECK_LEASE_OBJECTS(handles[0], CRTC_ID(0), CONNECTOR_ID(0), CRTC_ID(1), + CONNECTOR_ID(1)); +} +END_TEST + +static void add_lease_config_tests(Suite *s) +{ + TCase *tc = tcase_create("Lease configuration"); + + tcase_add_checked_fixture(tc, test_setup, test_shutdown); + + tcase_add_test(tc, multiple_connector_lease); + tcase_add_test(tc, single_failed_lease); + tcase_add_test(tc, named_connector_config); suite_add_tcase(s, tc); } @@ -378,6 +546,7 @@ int main(void) add_connector_enum_tests(s); add_lease_management_tests(s); + add_lease_config_tests(s); sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL);