tests: use igt_assert_lte to verify pm_backlight test results
PATCH 1/3 tests: use igt_assert_lte to verify pm_backlight test results
Gives out better diagnostics than just igt_asssert.
Signed-off-by Jani Nikula <[email protected]>
--- tests/pm_backlight.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/pm_backlight.c +3 -1
@@ -94,6 +94,7 @@ static int backlight_write(int value, const char *fname)static void test_and_verify (int val) {int result; +int tolerance = val *TOLERANCE /100 ;igt_assert_eq (backlight_write (val,"brightness" ),0 );igt_assert_eq (backlight_read (&result,"brightness" ),0 );
@@ -102,7 +103,8 @@ static void test_and_verify(int val)igt_assert_eq (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 ); +igt_assert_lte (result, val + tolerance); +igt_assert_lte (val - tolerance, result); }static void test_brightness (int max)
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/3 tests: add context param to pm_backlight tests
We'll be adding more context for the subtests than just the max brightness.
Signed-off-by Jani Nikula <[email protected]>
--- tests/pm_backlight.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-)
tests/pm_backlight.c +22 -17
@@ -35,6 +35,10 @@#include <unistd.h> #include <time.h> +struct context { +int max; +}; +#define TOLERANCE 5/* percent */ #define BACKLIGHT_PATH "/sys/class/backlight/intel_backlight"
@@ -107,41 +111,41 @@ static void test_and_verify(int val)igt_assert_lte (val - tolerance, result); } -static void test_brightness (int max) +static void test_brightness (struct context *context) {test_and_verify (0 ); -test_and_verify (max); -test_and_verify (max /2 ); +test_and_verify (context->max); +test_and_verify (context->max /2 ); } -static void test_bad_brightness (int max) +static void test_bad_brightness (struct context *context) {int val;/* First write some sane value */ -backlight_write (max /2 ,"brightness" ); +backlight_write (context->max /2 ,"brightness" );/* Writing invalid values should fail and not change the value */ igt_assert_lt (backlight_write (-1 ,"brightness" ),0 );backlight_read (&val,"brightness" ); -igt_assert_eq (val, max /2 ); -igt_assert_lt (backlight_write (max +1 ,"brightness" ),0 ); +igt_assert_eq (val, context->max /2 ); +igt_assert_lt (backlight_write (context->max +1 ,"brightness" ),0 );backlight_read (&val,"brightness" ); -igt_assert_eq (val, max /2 ); +igt_assert_eq (val, context->max /2 );igt_assert_lt (backlight_write (INT_MAX ,"brightness" ),0 );backlight_read (&val,"brightness" ); -igt_assert_eq (val, max /2 ); +igt_assert_eq (val, context->max /2 ); } -static void test_fade (int max) +static void test_fade (struct context *context) {int i;static const struct timespec ts = { .tv_sec =0 , .tv_nsec =FADESPEED *1000000 };/* Fade out, then in */ -for (i = max; i >0 ; i -= max /FADESTEPS ) { +for (i = context->max; i >0 ; i -= context->max /FADESTEPS ) {test_and_verify (i);nanosleep (&ts,NULL ); } -for (i =0 ; i <= max; i += max /FADESTEPS ) { +for (i =0 ; i <= context->max; i += context->max /FADESTEPS ) {test_and_verify (i);nanosleep (&ts,NULL ); }
@@ -149,22 +153,23 @@ static void test_fade(int max) igt_main { -int max, old; +struct context context = {0 }; +int 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_assert (backlight_read (&context.max,"max_brightness" ) >-1 ); } igt_subtest("basic-brightness") -test_brightness (max); +test_brightness (&context); igt_subtest("bad-brightness") -test_bad_brightness (max); +test_bad_brightness (&context); igt_subtest("fade") -test_fade (max); +test_fade (&context); igt_fixture {/* Restore old brightness */
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/3 tests: limit pm_backlight actual brightness tolerance between 0 and max
In reply to Jani NikulaSigned-off-by Jani Nikula <[email protected]>
--- tests/pm_backlight.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tests/pm_backlight.c +8 -8
@@ -95,7 +95,7 @@ static int backlight_write(int value, const char *fname)return 0 ; } -static void test_and_verify (int val) +static void test_and_verify (struct context *context,int val) {int result;int tolerance = val *TOLERANCE /100 ;
@@ -107,15 +107,15 @@ static void test_and_verify(int val)igt_assert_eq (backlight_read (&result,"actual_brightness" ),0 );/* Some rounding may happen depending on hw. Just check that it's close enough. */ -igt_assert_lte (result, val + tolerance); -igt_assert_lte (val - tolerance, result); +igt_assert_lte (result,min (context->max, val + tolerance)); +igt_assert_lte (max (0 , val - tolerance), result); }static void test_brightness (struct context *context) { -test_and_verify (0 ); -test_and_verify (context->max); -test_and_verify (context->max /2 ); +test_and_verify (context,0 ); +test_and_verify (context, context->max); +test_and_verify (context, context->max /2 ); }static void test_bad_brightness (struct context *context)
@@ -142,11 +142,11 @@ static void test_fade(struct context *context)/* Fade out, then in */ for (i = context->max; i >0 ; i -= context->max /FADESTEPS ) { -test_and_verify (i); +test_and_verify (context, i);nanosleep (&ts,NULL ); }for (i =0 ; i <= context->max; i += context->max /FADESTEPS ) { -test_and_verify (i); +test_and_verify (context, i);nanosleep (&ts,NULL ); } }
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx