• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2017 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 #include "config.h"
24 #include "igt.h"
25 #include "igt_sysfs.h"
26 #include <fcntl.h>
27 #include <sys/types.h>
28 #include <dirent.h>
29 
read_and_discard_sysfs_entries(int path_fd,int indent)30 static void read_and_discard_sysfs_entries(int path_fd, int indent)
31 {
32 	struct dirent *dirent;
33 	DIR *dir;
34 	char tabs[8];
35 	int i;
36 
37 	igt_assert(indent < sizeof(tabs) - 1);
38 
39 	for (i = 0; i < indent; i++)
40 		tabs[i] = '\t';
41 	tabs[i] = '\0';
42 
43 	dir = fdopendir(path_fd);
44 	if (!dir)
45 		return;
46 
47 	while ((dirent = readdir(dir))) {
48 		if (!strcmp(dirent->d_name, ".") ||
49 		    !strcmp(dirent->d_name, ".."))
50 			continue;
51 		if (dirent->d_type == DT_DIR) {
52 			int sub_fd = -1;
53 			igt_assert((sub_fd =
54 				    openat(path_fd, dirent->d_name, O_RDONLY |
55 					   O_DIRECTORY)) > 0);
56 			igt_debug("%sEntering subdir %s\n", tabs, dirent->d_name);
57 			read_and_discard_sysfs_entries(sub_fd, indent + 1);
58 			close(sub_fd);
59 		} else {
60 			char buf[512];
61 			int sub_fd;
62 			ssize_t ret;
63 
64 			igt_kmsg(KMSG_DEBUG "Reading file \"%s\"\n", dirent->d_name);
65 			igt_debug("%sReading file \"%s\"\n", tabs, dirent->d_name);
66 			igt_set_timeout(5, "reading sysfs entry");
67 
68 			sub_fd = openat(path_fd, dirent->d_name, O_RDONLY);
69 			if (sub_fd == -1) {
70 				igt_debug("%sCould not open file \"%s\" with error: %m\n",
71 					  tabs, dirent->d_name);
72 				continue;
73 			}
74 
75 			do {
76 				ret = read(sub_fd, buf, sizeof(buf));
77 			} while (ret == sizeof(buf));
78 
79 			if (ret == -1)
80 				igt_debug("%sCould not read file \"%s\" with error: %m\n",
81 					  tabs, dirent->d_name);
82 
83 			igt_reset_timeout();
84 			close(sub_fd);
85 		}
86 	}
87 	closedir(dir);
88 }
89 
kms_tests(int fd,int debugfs)90 static void kms_tests(int fd, int debugfs)
91 {
92 	igt_display_t display;
93 	struct igt_fb fb[IGT_MAX_PIPES];
94 	enum pipe pipe;
95 
96 	igt_fixture
97 		igt_display_require(&display, fd);
98 
99 	igt_subtest("read_all_entries_display_on") {
100 		/* try to light all pipes */
101 		for_each_pipe(&display, pipe) {
102 			igt_output_t *output;
103 
104 			for_each_valid_output_on_pipe(&display, pipe, output) {
105 				igt_plane_t *primary;
106 				drmModeModeInfo *mode;
107 
108 				if (output->pending_pipe != PIPE_NONE)
109 					continue;
110 
111 				igt_output_set_pipe(output, pipe);
112 				primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
113 				mode = igt_output_get_mode(output);
114 				igt_create_pattern_fb(display.drm_fd,
115 						      mode->hdisplay, mode->vdisplay,
116 						      DRM_FORMAT_XRGB8888,
117 						      LOCAL_DRM_FORMAT_MOD_NONE, &fb[pipe]);
118 
119 				/* Set a valid fb as some debugfs like to inspect it on a active pipe */
120 				igt_plane_set_fb(primary, &fb[pipe]);
121 				break;
122 			}
123 		}
124 
125 		igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
126 
127 		read_and_discard_sysfs_entries(debugfs, 0);
128 	}
129 
130 	igt_subtest("read_all_entries_display_off") {
131 		igt_output_t *output;
132 		igt_plane_t *plane;
133 
134 		for_each_connected_output(&display, output)
135 			igt_output_set_pipe(output, PIPE_NONE);
136 
137 		for_each_pipe(&display, pipe)
138 			for_each_plane_on_pipe(&display, pipe, plane)
139 				igt_plane_set_fb(plane, NULL);
140 
141 		igt_display_commit2(&display, display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
142 
143 		read_and_discard_sysfs_entries(debugfs, 0);
144 	}
145 
146 	igt_fixture
147 		igt_display_fini(&display);
148 }
149 
150 igt_main
151 {
152 	int fd = -1, debugfs;
153 
154 	igt_skip_on_simulation();
155 
156 	igt_fixture {
157 		fd = drm_open_driver_master(DRIVER_INTEL);
158 		igt_require_gem(fd);
159 		debugfs = igt_debugfs_dir(fd);
160 
161 		kmstest_set_vt_graphics_mode();
162 	}
163 
164 	igt_subtest("read_all_entries")
165 		read_and_discard_sysfs_entries(debugfs, 0);
166 
167 	igt_subtest_group
168 		kms_tests(fd, debugfs);
169 
170 	igt_fixture {
171 		close(debugfs);
172 		close(fd);
173 	}
174 }
175