1 /* 2 * Copyright © 2016 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 "igt.h" 24 25 #include <dirent.h> 26 #include <fcntl.h> 27 #include <sys/stat.h> 28 29 #define THRESHOLD_PER_CONNECTOR 10 30 #define THRESHOLD_TOTAL 50 31 #define CHECK_TIMES 15 32 33 IGT_TEST_DESCRIPTION("This check the time we take to read the content of all " 34 "the possible connectors. Without the edid -ENXIO patch " 35 "(http://permalink.gmane.org/gmane.comp.video.dri.devel/62083), " 36 "we sometimes take a *really* long time. " 37 "So let's just check for some reasonable timing here"); 38 39 40 igt_simple_main 41 { 42 DIR *dirp; 43 struct dirent *de; 44 45 dirp = opendir("/sys/class/drm"); 46 igt_assert(dirp != NULL); 47 48 while ((de = readdir(dirp))) { 49 struct igt_mean mean = {}; 50 struct stat st; 51 char path[PATH_MAX]; 52 int i; 53 54 if (*de->d_name == '.') 55 continue;; 56 57 snprintf(path, sizeof(path), "/sys/class/drm/%s/status", 58 de->d_name); 59 60 if (stat(path, &st)) 61 continue; 62 63 igt_mean_init(&mean); 64 for (i = 0; i < CHECK_TIMES; i++) { 65 struct timespec ts = {}; 66 int fd; 67 68 if ((fd = open(path, O_WRONLY)) < 0) 69 continue; 70 71 igt_nsec_elapsed(&ts); 72 igt_ignore_warn(write(fd, "detect\n", 7)); 73 igt_mean_add(&mean, igt_nsec_elapsed(&ts)); 74 75 close(fd); 76 } 77 78 igt_debug("%s: mean.max %.2fns, %.2fus, %.2fms, " 79 "mean.avg %.2fns, %.2fus, %.2fms\n", 80 de->d_name, 81 mean.max, mean.max / 1e3, mean.max / 1e6, 82 mean.mean, mean.mean / 1e3, mean.mean / 1e6); 83 84 if (mean.max > (THRESHOLD_PER_CONNECTOR * 1e6)) { 85 igt_warn("%s: probe time exceed 10ms, " 86 "max=%.2fms, avg=%.2fms\n", de->d_name, 87 mean.max / 1e6, mean.mean / 1e6); 88 } 89 igt_assert_f(mean.mean < (THRESHOLD_TOTAL * 1e6), 90 "%s: average probe time exceeded 50ms, " 91 "max=%.2fms, avg=%.2fms\n", de->d_name, 92 mean.max / 1e6, mean.mean / 1e6); 93 94 } 95 closedir(dirp); 96 97 } 98