tests/pm_backlight: Add backlight test
PATCH 1/1 tests/pm_backlight: Add backlight test
This is a basic sanity test of the backlight sysfs interface.
Issue: VIZ-3377
--- tests/.gitignore | 1 + tests/Makefile.sources | 1 + tests/pm_backlight.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 tests/pm_backlight.c
tests/.gitignore +1 -0
@@ -150,6 +150,7 @@ kms_vblank kms_crtc_background_color kms_plane_scaling kms_panel_fitting +pm_backlight pm_lpsp pm_rc6_residency pm_rpm
tests/Makefile.sources +1 -0
@@ -80,6 +80,7 @@ TESTS_progs_M = \ kms_crtc_background_color \ kms_plane_scaling \ kms_panel_fitting \ + pm_backlight \ pm_lpsp \ pm_rpm \ pm_rps \
tests/pm_backlight.c new file +144 -0
144 lines not on this page · raw message
Signature · 6 lines
1.8.3.2 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 127 lines · Antti Koskipaa
This is a basic sanity test of the backlight sysfs interface.
Issue: VIZ-3377
Signed-off-by Antti Koskipaa <[email protected]>--- tests/.gitignore | 1 + tests/Makefile.sources | 1 + tests/pm_backlight.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 tests/pm_backlight.ctests/.gitignore +1
-0@@ -150,6 +150,7 @@ kms_vblank kms_crtc_background_color kms_plane_scaling kms_panel_fitting +pm_backlight pm_lpsp pm_rc6_residency pm_rpmtests/Makefile.sources +1
-0@@ -80,6 +80,7 @@ TESTS_progs_M = \ kms_crtc_background_color \ kms_plane_scaling \ kms_panel_fitting \ + pm_backlight \ pm_lpsp \ pm_rpm \ pm_rps \tests/pm_backlight.c new file +86
-0@@ -0,0 +1,144 @@ +/* +* Copyright © 2015 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. +* +* Author: +* Antti Koskipaa <[email protected]> +* +*/ + +#include <limits.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> + +#include "igt_core.h" + +#define TOLERANCE 5/* percent */ +#define BACKLIGHT_PATH "/sys/class/backlight/intel_backlight" + +IGT_TEST_DESCRIPTION ("Basic backlight sysfs test" ); + +static int backlight_read (int *result,const char *fname) +{ +int fd; +char full[PATH_MAX ]; +char dst[64 ]; +int r, e; + +igt_assert (snprintf (full,PATH_MAX ,"%s/%s" ,BACKLIGHT_PATH , fname) <PATH_MAX ); + + fd =open (full,O_RDONLY ); +if (fd ==-1 ) +return -errno; + + r =read (fd, dst,sizeof (dst)); + e = errno; +close (fd); + +if (r <0 ) +return -e; + + errno =0 ; + *result =strtol (dst,NULL ,10 ); +return errno; +} + +static int backlight_write (int value,const char *fname) +{ +int fd; +char full[PATH_MAX ]; +char src[64 ]; +int len; + +igt_assert (snprintf (full,PATH_MAX ,"%s/%s" ,BACKLIGHT_PATH , fname) <PATH_MAX ); + fd =open (full,O_WRONLY ); +if (fd ==-1 ) +return -errno; + + len =snprintf (src,sizeof (src),"%i" , value); + len =write (fd, src, len); +close (fd); + +if (len <0 ) +return len; +
tests/pm_backlight.c line 96
Quoted 10 lines
tests/pm_backlight.c new file +10
-0+return 0 ; +} + +static void test_and_verify (int val,int max) +{ +int result; +igt_assert (backlight_write (val,"brightness" ) ==0 ); +igt_assert (backlight_read (&result,"actual_brightness" ) ==0 ); +/* Some rounding may happen depending on hw. Just check that it's close enough. */ +igt_assert (result <= val + val *TOLERANCE /100 && result >= val - val *TOLERANCE /100 );
This could additionally read "brightness" and assert it is equal to what was just written (i.e. without the tolerance check).
There are no guarantees that the result read back from "actual_brightness" would be within the tolerance, in fact it could be changed by ACPI behind our backs, at least on some platforms... But I guess this is good enough.
tests/pm_backlight.c line 104
Quoted 8 lines
tests/pm_backlight.c new file +8
-0+} + +static void test_brightness (int max) +{ +test_and_verify (0 , max); +test_and_verify (max, max); +test_and_verify (max /2 , max); +}
A followup could add a test to fade both ways using a loop; can be a follow-up later on.
BR,
Jani.
Quoted 47 lines
tests/pm_backlight.c new file +40
-0+ +static void test_bad_brightness (int max) +{ +int val; +/* First write some sane value */ +backlight_write (max /2 ,"brightness" ); +/* Writing invalid values should fail and not change the value */ +igt_assert (backlight_write (-1 ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +igt_assert (backlight_write (max +1 ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +igt_assert (backlight_write (INT_MAX ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +} + +igt_main +{ +int max, old; + +igt_skip_on_simulation (); + + igt_fixture { +/* Get the max value and skip the whole test if sysfs interface not available */ +igt_skip_on (backlight_read (&old,"brightness" )); +igt_assert (backlight_read (&max,"max_brightness" ) >-1 ); + } + + igt_subtest("brightness") +test_brightness (max); + igt_subtest("bad-brightness") +test_bad_brightness (max); + + igt_fixture { +/* Restore old brightness */ +backlight_write (old,"brightness" ); + } +}Signature · 6 lines
1.8.3.2 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 133 lines · Jani Nikula
Quoted 132 lines · Antti Koskipaa
This is a basic sanity test of the backlight sysfs interface.
Issue: VIZ-3377
Signed-off-by Antti Koskipaa <[email protected]>--- tests/.gitignore | 1 + tests/Makefile.sources | 1 + tests/pm_backlight.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 tests/pm_backlight.ctests/.gitignore +1
-0@@ -150,6 +150,7 @@ kms_vblank kms_crtc_background_color kms_plane_scaling kms_panel_fitting +pm_backlight pm_lpsp pm_rc6_residency pm_rpmtests/Makefile.sources +1
-0@@ -80,6 +80,7 @@ TESTS_progs_M = \ kms_crtc_background_color \ kms_plane_scaling \ kms_panel_fitting \ + pm_backlight \ pm_lpsp \ pm_rpm \ pm_rps \tests/pm_backlight.c new file +91
-0@@ -0,0 +1,144 @@ +/* +* Copyright © 2015 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. +* +* Author: +* Antti Koskipaa <[email protected]> +* +*/ + +#include <limits.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> + +#include "igt_core.h" + +#define TOLERANCE 5/* percent */ +#define BACKLIGHT_PATH "/sys/class/backlight/intel_backlight" + +IGT_TEST_DESCRIPTION ("Basic backlight sysfs test" ); + +static int backlight_read (int *result,const char *fname) +{ +int fd; +char full[PATH_MAX ]; +char dst[64 ]; +int r, e; + +igt_assert (snprintf (full,PATH_MAX ,"%s/%s" ,BACKLIGHT_PATH , fname) <PATH_MAX ); + + fd =open (full,O_RDONLY ); +if (fd ==-1 ) +return -errno; + + r =read (fd, dst,sizeof (dst)); + e = errno; +close (fd); + +if (r <0 ) +return -e; + + errno =0 ; + *result =strtol (dst,NULL ,10 ); +return errno; +} + +static int backlight_write (int value,const char *fname) +{ +int fd; +char full[PATH_MAX ]; +char src[64 ]; +int len; + +igt_assert (snprintf (full,PATH_MAX ,"%s/%s" ,BACKLIGHT_PATH , fname) <PATH_MAX ); + fd =open (full,O_WRONLY ); +if (fd ==-1 ) +return -errno; + + len =snprintf (src,sizeof (src),"%i" , value); + len =write (fd, src, len); +close (fd); + +if (len <0 ) +return len; + +return 0 ; +} + +static void test_and_verify (int val,int max) +{
Quoted 8 lines
tests/pm_backlight.c line 96
Quoted 5 lines
tests/pm_backlight.c new file +5
-0+int result; +igt_assert (backlight_write (val,"brightness" ) ==0 ); +igt_assert (backlight_read (&result,"actual_brightness" ) ==0 ); +/* Some rounding may happen depending on hw. Just check that it's close enough. */ +igt_assert (result <= val + val *TOLERANCE /100 && result >= val - val *TOLERANCE /100 );This could additionally read "brightness" and assert it is equal to what was just written (i.e. without the tolerance check).
v2 coming soon.
Quoted 4 lines
There are no guarantees that the result read back from "
actual_brightness" would be within the tolerance, in fact it could be changed by ACPI behind our backs, at least on some platforms... But I guess this is good enough.
It should be, unless the tester does something stupid like slam the lid shut in the middle of the test or something.
Quoted 11 lines
tests/pm_backlight.c line 104
Quoted 8 lines
tests/pm_backlight.c new file +8
-0+} + +static void test_brightness (int max) +{ +test_and_verify (0 , max); +test_and_verify (max, max); +test_and_verify (max /2 , max); +}A followup could add a test to fade both ways using a loop; can be a follow-up later on.
Will implement in v2, if the backlight responds sensibly.
Quoted 50 lines
Reviewed-by Jani Nikula <[email protected]>BR,
Jani.Quoted 43 lines
tests/pm_backlight.c new file +40
-0+ +static void test_bad_brightness (int max) +{ +int val; +/* First write some sane value */ +backlight_write (max /2 ,"brightness" ); +/* Writing invalid values should fail and not change the value */ +igt_assert (backlight_write (-1 ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +igt_assert (backlight_write (max +1 ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +igt_assert (backlight_write (INT_MAX ,"brightness" ) <0 ); +backlight_read (&val,"brightness" ); +igt_assert (val == max /2 ); +} + +igt_main +{ +int max, old; + +igt_skip_on_simulation (); + + igt_fixture { +/* Get the max value and skip the whole test if sysfs interface not available */ +igt_skip_on (backlight_read (&old,"brightness" )); +igt_assert (backlight_read (&max,"max_brightness" ) >-1 ); + } + + igt_subtest("brightness") +test_brightness (max); + igt_subtest("bad-brightness") +test_bad_brightness (max); + + igt_fixture { +/* Restore old brightness */ +backlight_write (old,"brightness" ); + } +}Signature · 1 line
1.8.3.2
Quoted 5 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx