1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Kunit test for drm_modes functions
4 */
5
6 #include <drm/drm_connector.h>
7
8 #include <kunit/test.h>
9
10 struct drm_get_tv_mode_from_name_test {
11 const char *name;
12 enum drm_connector_tv_mode expected_mode;
13 };
14
15 #define TV_MODE_NAME(_name, _mode) \
16 { \
17 .name = _name, \
18 .expected_mode = _mode, \
19 }
20
drm_test_get_tv_mode_from_name_valid(struct kunit * test)21 static void drm_test_get_tv_mode_from_name_valid(struct kunit *test)
22 {
23 const struct drm_get_tv_mode_from_name_test *params = test->param_value;
24
25 KUNIT_EXPECT_EQ(test,
26 drm_get_tv_mode_from_name(params->name, strlen(params->name)),
27 params->expected_mode);
28 }
29
30 static const
31 struct drm_get_tv_mode_from_name_test drm_get_tv_mode_from_name_valid_tests[] = {
32 TV_MODE_NAME("NTSC", DRM_MODE_TV_MODE_NTSC),
33 TV_MODE_NAME("NTSC-443", DRM_MODE_TV_MODE_NTSC_443),
34 TV_MODE_NAME("NTSC-J", DRM_MODE_TV_MODE_NTSC_J),
35 TV_MODE_NAME("PAL", DRM_MODE_TV_MODE_PAL),
36 TV_MODE_NAME("PAL-M", DRM_MODE_TV_MODE_PAL_M),
37 TV_MODE_NAME("PAL-N", DRM_MODE_TV_MODE_PAL_N),
38 TV_MODE_NAME("SECAM", DRM_MODE_TV_MODE_SECAM),
39 };
40
41 static void
drm_get_tv_mode_from_name_valid_desc(const struct drm_get_tv_mode_from_name_test * t,char * desc)42 drm_get_tv_mode_from_name_valid_desc(const struct drm_get_tv_mode_from_name_test *t,
43 char *desc)
44 {
45 sprintf(desc, "%s", t->name);
46 }
47
48 KUNIT_ARRAY_PARAM(drm_get_tv_mode_from_name_valid,
49 drm_get_tv_mode_from_name_valid_tests,
50 drm_get_tv_mode_from_name_valid_desc);
51
drm_test_get_tv_mode_from_name_truncated(struct kunit * test)52 static void drm_test_get_tv_mode_from_name_truncated(struct kunit *test)
53 {
54 const char *name = "NTS";
55 int ret;
56
57 ret = drm_get_tv_mode_from_name(name, strlen(name));
58 KUNIT_EXPECT_LT(test, ret, 0);
59 };
60
61 static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
62 KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
63 drm_get_tv_mode_from_name_valid_gen_params),
64 KUNIT_CASE(drm_test_get_tv_mode_from_name_truncated),
65 { }
66 };
67
68 static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
69 .name = "drm_get_tv_mode_from_name",
70 .test_cases = drm_get_tv_mode_from_name_tests,
71 };
72
73 kunit_test_suite(drm_get_tv_mode_from_name_test_suite);
74
75 MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
76 MODULE_LICENSE("GPL");
77