Damien Lespiau | 15f6021 | 2015-05-14 14:49:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 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 | * Authors: |
| 24 | * Damien Lespiau <damien.lespiau@intel.com> |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <unistd.h> |
| 31 | |
| 32 | #include "igt_core.h" |
| 33 | #include "igt_debugfs.h" |
| 34 | #include "igt_kms.h" |
| 35 | |
| 36 | typedef struct { |
| 37 | int fd; |
| 38 | int pipe; |
| 39 | int n_crcs; |
| 40 | } display_crc_t; |
| 41 | |
| 42 | static int pipe_from_str(const char *str) |
| 43 | { |
| 44 | unsigned char c; |
| 45 | |
| 46 | if (!str || strlen(str) != 1) |
| 47 | return -1; |
| 48 | |
| 49 | c = str[0]; |
| 50 | |
| 51 | if (c >= 'A' && c <= 'C') |
| 52 | return c - 'A'; |
| 53 | |
| 54 | if (c >= 'a' && c <= 'c') |
| 55 | return c - 'a'; |
| 56 | |
| 57 | if (c >= '0' && c <= '3') |
| 58 | return c - '0'; |
| 59 | |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | static void print_crcs(display_crc_t *ctx) |
| 64 | { |
| 65 | igt_pipe_crc_t *pipe_crc; |
| 66 | igt_crc_t crc; |
| 67 | char *crc_str; |
| 68 | int i; |
| 69 | |
| 70 | pipe_crc = igt_pipe_crc_new(ctx->pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
| 71 | |
| 72 | for (i = 0; i < ctx->n_crcs; i++) { |
| 73 | igt_pipe_crc_collect_crc(pipe_crc, &crc); |
| 74 | |
| 75 | crc_str = igt_crc_to_string(&crc); |
| 76 | printf("CRC on pipe %s: %s\n", kmstest_pipe_name(ctx->pipe), |
| 77 | crc_str); |
| 78 | free(crc_str); |
| 79 | } |
| 80 | |
| 81 | igt_pipe_crc_free(pipe_crc); |
| 82 | } |
| 83 | |
| 84 | static display_crc_t ctx; |
| 85 | |
| 86 | int main(int argc, char **argv) |
| 87 | { |
| 88 | int opt; |
| 89 | |
| 90 | ctx.n_crcs = 1; |
| 91 | |
| 92 | while ((opt = getopt(argc, argv, "p:n:")) != -1) { |
| 93 | switch (opt) { |
| 94 | case 'p': |
| 95 | ctx.pipe = pipe_from_str(optarg); |
| 96 | if (ctx.pipe == -1) { |
| 97 | fprintf(stderr, "Unknown pipe %s\n", optarg); |
| 98 | exit(1); |
| 99 | } |
| 100 | break; |
| 101 | case 'n': |
| 102 | ctx.n_crcs = atoi(optarg); |
| 103 | break; |
| 104 | default: |
| 105 | igt_assert(0); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | print_crcs(&ctx); |
| 110 | } |