blob: 9cc6c0c0e9e4664b63d16cf54a1d9d811d3d6c7e [file] [log] [blame]
Braden Kell51eda942020-06-01 11:15:44 -07001#!/usr/bin/env python3
2#
3# Copyright (C) 2020 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17import os
18import time
19import uuid
20
21from acts import asserts, signals
22from acts.base_test import BaseTestClass
23from acts.libs.proc.job import Error
Xianyuan Jia63751fb2020-11-17 00:07:40 +000024from acts_contrib.test_utils.tel.tel_test_utils import setup_droid_properties
Braden Kell51eda942020-06-01 11:15:44 -070025
26BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS = 2
27
28ONE_QUARTER_BRIGHTNESS = 0.25
29HALF_BRIGHTNESS = 0.5
30THREE_QUARTERS_BRIGHTNESS = 0.75
31FULL_BRIGHTNESS = 1.0
32
33
34def float_near(a, b):
35 return abs(a - b) < 0.001
36
37
38class BacklightTest(BaseTestClass):
39 def setup_class(self):
40 super().setup_class()
41 self.fd = self.fuchsia_devices[0]
42
43 def setup_test(self):
44 # Save the state and scale so that they can be restored after the test. Set a known initial
45 # brightness so that the test effects are consistent.
46 self.initial_state = self.fd.backlight_lib.getStateNormalized(
47 )['result']
48 self.initial_scale = self.fd.backlight_lib.getNormalizedBrightnessScale(
49 )['result']
50
51 self.fd.backlight_lib.setStateNormalized(True, HALF_BRIGHTNESS)
52
53 def teardown_test(self):
54 self.fd.backlight_lib.setNormalizedBrightnessScale(self.initial_scale)
55
56 backlight_on = self.initial_state['backlight_on']
57 brightness = self.initial_state['brightness']
58 self.fd.backlight_lib.setStateNormalized(backlight_on,
59 brightness * HALF_BRIGHTNESS)
60 self.fd.backlight_lib.setStateNormalized(backlight_on, brightness)
61
62 def test_brightness(self):
63 """Test SetStateNormalized and GetStateNormalized FIDL calls.
64
65 The display brightness should decrease, increase, turn off, then turn back on again. This
66 test will only run if the device config has a 'backlight_tests' entry.
67 """
68 asserts.skip_if('backlight_tests' not in self.user_params,
69 'backlight_tests not specified in the config')
70
71 # Pause to make backlight brightness changes clearly visible.
72 time.sleep(BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS)
73
74 result = self.fd.backlight_lib.setStateNormalized(
75 True, ONE_QUARTER_BRIGHTNESS)
76 asserts.assert_true(result['error'] is None,
77 'SetStateNormalized failed')
78
79 result = self.fd.backlight_lib.getStateNormalized()
80 asserts.assert_true(result['error'] is None,
81 'GetStateNormalized failed')
82
83 asserts.assert_true(result['result']['backlight_on'],
84 'Got unexpected device state')
85 asserts.assert_true(
86 float_near(result['result']['brightness'], ONE_QUARTER_BRIGHTNESS),
87 'Got unexpected brightness value')
88
89 time.sleep(BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS)
90
91 # Brightness should increase
92 result = self.fd.backlight_lib.setStateNormalized(
93 True, THREE_QUARTERS_BRIGHTNESS)
94 asserts.assert_true(result['error'] is None,
95 'SetStateNormalized failed')
96
97 result = self.fd.backlight_lib.getStateNormalized()
98 asserts.assert_true(result['error'] is None,
99 'GetStateNormalized failed')
100
101 asserts.assert_true(result['result']['backlight_on'],
102 'Got unexpected device state')
103 asserts.assert_true(
104 float_near(result['result']['brightness'],
105 THREE_QUARTERS_BRIGHTNESS),
106 'Got unexpected brightness value')
107
108 time.sleep(BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS)
109
110 # Backlight should turn off
111 result = self.fd.backlight_lib.setStateNormalized(
112 False, FULL_BRIGHTNESS)
113 asserts.assert_true(result['error'] is None,
114 'SetStateNormalized failed')
115
116 result = self.fd.backlight_lib.getStateNormalized()
117 asserts.assert_true(result['error'] is None,
118 'GetStateNormalized failed')
119
120 asserts.assert_false(result['result']['backlight_on'],
121 'Got unexpected device state')
122 asserts.assert_true(
123 float_near(result['result']['brightness'], FULL_BRIGHTNESS),
124 'Got unexpected brightness value')
125
126 def test_brightness_scale(self):
127 """Test SetNormalizedBrightnessScale and SetNormalizedBrightnessScale FIDL calls.
128
129 The display brightness should decrease then increase. This test will only run if the device
130 config has a 'backlight_tests' entry.
131 """
132 asserts.skip_if('backlight_tests' not in self.user_params,
133 'backlight_tests not specified in the config')
134
135 time.sleep(BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS)
136
137 # Brightness should decrease
138 result = self.fd.backlight_lib.setNormalizedBrightnessScale(
139 self.initial_scale * ONE_QUARTER_BRIGHTNESS)
140 asserts.assert_true(result['error'] is None,
141 'SetNormalizedBrightnessScale failed')
142
143 result = self.fd.backlight_lib.getNormalizedBrightnessScale()
144 asserts.assert_true(result['error'] is None,
145 'GetNormalizedBrightnessScale failed')
146
147 asserts.assert_true(
148 float_near(result['result'],
149 self.initial_scale * ONE_QUARTER_BRIGHTNESS),
150 'Got unexpected brightness scale value')
151
152 # Toggle the brightness to force an update. This works around a hardware limitation.
153 self.fd.backlight_lib.setStateNormalized(True, ONE_QUARTER_BRIGHTNESS)
154 self.fd.backlight_lib.setStateNormalized(True, HALF_BRIGHTNESS)
155
156 time.sleep(BRIGHTNESS_CHANGE_SLEEP_TIME_SECONDS)
157
158 # Brightness should increase
159 result = self.fd.backlight_lib.setNormalizedBrightnessScale(
160 self.initial_scale)
161 asserts.assert_true(result['error'] is None,
162 'SetNormalizedBrightnessScale failed')
163
164 result = self.fd.backlight_lib.getNormalizedBrightnessScale()
165 asserts.assert_true(result['error'] is None,
166 'GetNormalizedBrightnessScale failed')
167
168 asserts.assert_true(float_near(result['result'], self.initial_scale),
169 'Got unexpected brightness scale value')
170
171 self.fd.backlight_lib.setStateNormalized(True, ONE_QUARTER_BRIGHTNESS)
172 self.fd.backlight_lib.setStateNormalized(True, HALF_BRIGHTNESS)