static void test_bad_command(data_t *data, const char *cmd) { FILE *ctl; size_t written; ctl = igt_debugfs_fopen("i915_display_crc_ctl", "r+"); written = fwrite(cmd, 1, strlen(cmd), ctl); fflush(ctl); igt_assert_eq(written, strlen(cmd)); igt_assert(ferror(ctl)); igt_assert_eq(errno, EINVAL); fclose(ctl); }
static int get_object_count(void) { FILE *file; int ret, scanned; igt_drop_caches_set(DROP_RETIRE | DROP_ACTIVE); file = igt_debugfs_fopen("i915_gem_objects", "r"); scanned = fscanf(file, "%i objects", &ret); igt_assert_eq(scanned, 1); return ret; }
/** * __igt_debugfs_read: * @filename: file name * @buf: buffer where the contents will be stored, allocated by the caller * @buf_size: size of the buffer * * This function opens the debugfs file, reads it, stores the content in the * provided buffer, then closes the file. Users should make sure that the buffer * provided is big enough to fit the whole file, plus one byte. */ void __igt_debugfs_read(const char *filename, char *buf, int buf_size) { FILE *file; size_t n_read; file = igt_debugfs_fopen(filename, "r"); igt_assert(file); n_read = fread(buf, 1, buf_size - 1, file); igt_assert(n_read > 0); igt_assert(feof(file)); buf[n_read] = '\0'; igt_assert(fclose(file) == 0); }
/** * igt_require_pipe_crc: * * Convenience helper to check whether pipe CRC capturing is supported by the * kernel. Uses igt_skip to automatically skip the test/subtest if this isn't * the case. */ void igt_require_pipe_crc(void) { const char *cmd = "pipe A none"; FILE *ctl; size_t written; int ret; ctl = igt_debugfs_fopen("i915_display_crc_ctl", "r+"); igt_require_f(ctl, "No display_crc_ctl found, kernel too old\n"); written = fwrite(cmd, 1, strlen(cmd), ctl); ret = fflush(ctl); igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV, "CRCs not supported on this platform\n"); fclose(ctl); }
/** * igt_debugfs_search: * @filename: file name * @substring: string to search for in @filename * * Searches each line in @filename for the substring specified in @substring. * * Returns: True if the @substring is found to occur in @filename */ bool igt_debugfs_search(const char *filename, const char *substring) { FILE *file; size_t n = 0; char *line = NULL; bool matched = false; file = igt_debugfs_fopen(filename, "r"); igt_assert(file); while (getline(&line, &n, file) >= 0) { matched = (strstr(line, substring) != NULL); if (matched) break; } free(line); fclose(file); return matched; }