This is meant to test the sysfs entry for showing rc6 residency in milliseconds. Remember, sysfs is a permanent interface. Signed-off-by: Ben Widawsky <ben at bwidawsk.net> --- tests/Makefile.am | 1 + tests/rc6_residency.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/rc6_residency.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 6544ec7..a8eed88 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,6 +56,7 @@ TESTS_progs = \ drm_vma_limiter_cpu \ drm_vma_limiter_gtt \ drm_vma_limiter_cached \ + rc6_residency \ $(NULL) # IMPORTANT: The ZZ_ tests need to be run last! diff --git a/tests/rc6_residency.c b/tests/rc6_residency.c new file mode 100644 index 0000000..8ae6aa4 --- /dev/null +++ b/tests/rc6_residency.c @@ -0,0 +1,80 @@ +/* + * Copyright ? 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Ben Widawsky <ben at bwidawsk.net> + * + */ + +#include <stdlib.h> +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "drmtest.h" + +static unsigned int readit(const char *path) +{ + unsigned int ret; + + FILE *file; + file = fopen(path, "r"); + if (file == NULL) { + fprintf(stderr, "Couldn't open %s (%d)\n", path, errno); + abort(); + } + fscanf(file, "%u", &ret); + fclose(file); + + return ret; +} + +int main(int argc, char *argv[]) +{ + /* TODO: don't always assume 0 */ + const int device = 0; + char *path; + int fd, ret; + unsigned int value, value2; + + /* Use drm_open_any to verify device existence */ + fd = drm_open_any(); + close(fd); + + ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6", device); + if (ret == -1 || ret < strlen("/sys/class/drm/card0/power/rc6")) + abort(); + + value = readit(path); + + // Sleep for 3 seconds and compare + sleep(3); + value2 = readit(path); + free(path); + + /* Plenty of fudge */ + if (((value2 - value) > 3900) || + ((value2 - value) < 2100)) + exit(EXIT_FAILURE); + + exit(EXIT_SUCCESS); +} -- 1.7.9.4