lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / pm_psr.c
1 /*
2  * Copyright (c) 2013 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  *    Rodrigo Vivi <rodrigo.vivi@intel.com>
25  */
26
27 #define _GNU_SOURCE
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <errno.h>
33
34 #include "drmtest.h"
35
36 #define SLEEP_DURATION 5000 // in milliseconds
37
38 static int get_perf(const char *path)
39 {
40         int ret, perf;
41         FILE *file;
42         char str[4];
43
44         file = fopen(path, "r");
45         igt_assert(file);
46
47         ret = fscanf(file, "Sink_Support: %s\n", str);
48         igt_skip_on_f(ret == 0,
49                       "i915_edp_psr_status format not supported by this test case\n");
50         igt_require(strcmp(str, "yes") == 0);
51         ret = fscanf(file, "Source_OK: %s\n", str);
52         igt_assert(ret != 0);
53
54         igt_require(strcmp(str, "yes") == 0);
55
56         ret = fscanf(file, "Enabled: %s\n", str);
57         igt_assert(ret != 0);
58         igt_assert(strcmp(str, "yes") == 0);
59
60         ret = fscanf(file, "Performance_Counter: %i", &perf);
61         igt_assert(ret != 0);
62
63         igt_assert(perf);
64
65         fclose(file);
66         return perf;
67 }
68
69 igt_simple_main
70 {
71         int ret, perf1, perf2;
72         int device = drm_get_card();
73         char *path;
74
75         igt_skip_on_simulation();
76
77         ret = asprintf(&path, "/sys/kernel/debug/dri/%d/i915_edp_psr_status", device);
78         igt_assert(ret != -1);
79
80         perf1 = get_perf(path);
81         sleep(SLEEP_DURATION / 1000);
82         perf2 = get_perf(path);
83
84         igt_assert_f(perf1 != perf2,
85                      "Unable to enter PSR state again\n");
86 }