10 #define CMD_INTERVAL_SEC 1 /* second */
11 #define CMD_LONG_INTERVAL_SEC 3 /* second */
13 #define print_command(command) \
15 printf("%12s | ", command); \
17 sleep(CMD_INTERVAL_SEC); \
20 extern void battery_scenario(char *unit, int status);
22 static bool tc_success;
23 static int success, fail;
25 static void start_udev(void)
27 dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
29 DEVICED_INTERFACE_SYSNOTI,
31 g_variant_new("(sis)", "udev", 1, "start"),
35 static void stop_udev(void)
37 dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
39 DEVICED_INTERFACE_SYSNOTI,
41 g_variant_new("(sis)", "udev", 1, "stop"),
45 static int call_display_method_sync(const char *method, GVariant *param)
48 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
50 DEVICED_INTERFACE_DISPLAY,
53 _E("Failed to %s.", method);
60 static void check_result(int expect_default, int expect_current)
69 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
71 DEVICED_INTERFACE_DISPLAY,
72 "GetBrightnessInfo", NULL, &msg);
74 _E("Failed to GetBrightnessInfo.");
78 if (!g_variant_get_safe(msg, "(ii)", &result_default, &result_current)) {
79 _D("Return type mismatching from GetBrightnessInfo.");
83 match_default = expect_default == result_default;
84 match_current = expect_current == result_current;
86 printf("%6d %6d %c | %6d %6d %c\n",
87 expect_default, result_default, match_default ? ' ' : 'X',
88 expect_current, result_current, match_current ? ' ' : 'X');
90 tc_success &= (match_default && match_current);
93 static void hbm_on(int expect_default, int expect_current)
95 print_command("HBM ON");
97 call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 120));
98 check_result(expect_default, expect_current);
99 sleep(CMD_INTERVAL_SEC);
102 static void hbm_off(int expect_default, int expect_current)
104 print_command("HBM OFF");
106 call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 0));
107 check_result(expect_default, expect_current);
108 sleep(CMD_INTERVAL_SEC);
111 static void lbm_on(int expect_default, int expect_current)
113 print_command("LBM ON");
115 call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 110));
116 check_result(expect_default, expect_current);
117 sleep(CMD_INTERVAL_SEC);
120 static void lbm_off(int expect_default, int expect_current)
122 print_command("LBM OFF");
124 call_display_method_sync("AutoBrightnessChanged", g_variant_new("(i)", 0));
125 check_result(expect_default, expect_current);
126 sleep(CMD_INTERVAL_SEC);
129 static void hold(int hold, int expect_default, int expect_current)
133 snprintf(command, sizeof(command), "HOLD %d", hold);
134 print_command(command);
136 call_display_method_sync("HoldBrightness", g_variant_new("(i)", hold));
137 check_result(expect_default, expect_current);
138 sleep(CMD_INTERVAL_SEC);
141 static void release(int expect_default, int expect_current)
143 print_command("RELEASE");
145 call_display_method_sync("ReleaseBrightness", NULL);
146 check_result(expect_default, expect_current);
147 sleep(CMD_INTERVAL_SEC);
150 static void lowdim_on(int expect_default, int expect_current)
152 print_command("LOWDIM ON");
154 battery_scenario("bat3", 1);
156 check_result(expect_default, expect_current);
157 sleep(CMD_LONG_INTERVAL_SEC);
160 static void lowdim_off(int expect_default, int expect_current)
162 print_command("LOWDIM OFF");
164 battery_scenario("bat3", 0);
166 check_result(expect_default, expect_current);
167 sleep(CMD_LONG_INTERVAL_SEC);
170 static void set(int brightness, int expect_default, int expect_current)
174 snprintf(command, sizeof(command), "SET %d", brightness);
175 print_command(command);
177 call_display_method_sync("SetBrightness", g_variant_new("(ii)", 0, brightness));
178 sleep(CMD_INTERVAL_SEC);
179 check_result(expect_default, expect_current);
182 static void abnormal_health_on(int expect_default, int expect_current)
184 print_command("ABNORMAL ON");
186 battery_scenario("heat1", 1);
188 check_result(expect_default, expect_current);
189 sleep(CMD_LONG_INTERVAL_SEC);
192 static void abnormal_health_off(int expect_default, int expect_current)
194 print_command("ABNORMAL OFF");
196 battery_scenario("heat1", 0);
198 check_result(expect_default, expect_current);
199 sleep(CMD_LONG_INTERVAL_SEC);
202 static void initialize_test_env(int brightness, const char *fname)
204 printf("[%s]\n", fname);
208 call_display_method_sync("ChangeState", g_variant_new("(s)", "lcdoff"));
209 sleep(CMD_INTERVAL_SEC);
210 call_display_method_sync("ChangeState", g_variant_new("(s)", "lcdon"));
211 sleep(CMD_LONG_INTERVAL_SEC);
212 printf(" Init brightness: %3d\n", brightness);
213 call_display_method_sync("SetBrightness", g_variant_new("(ii)", 0, brightness));
214 sleep(CMD_INTERVAL_SEC);
215 call_display_method_sync("lockstate", g_variant_new("(sssi)", "lcdon", "staycurstate", "NULL", 0));
216 sleep(CMD_INTERVAL_SEC);
218 printf(" | default | current\n");
219 printf(" Command | expect result | expect result\n");
220 sleep(CMD_INTERVAL_SEC);
222 #define initialize(brightness) initialize_test_env(brightness, __func__)
224 #define DEFINE_TC(tcname) static void tc_##tcname(void)
237 /* BrtTable=1,20,40,50,60,70,80,90,95,100
239 * It lowers brightness 4 level down */
274 lowdim_off(100, 100);
277 DEFINE_TC(abnormal_health)
281 abnormal_health_on(100, 0);
282 abnormal_health_off(100, 100);
297 #define TESTCASE(tc_function) {.tcname = #tc_function, .tc = tc_##tc_function }
302 /* default testcase */
308 TESTCASE(abnormal_health),
310 /* custom testcase */
314 #define array_len(arr) (sizeof(arr) / sizeof((arr)[0]))
315 static void do_test(const char *tcname)
321 ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, &timeout);
323 if (vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, 300) < 0)
324 printf("Failed to set LCDNORMAL timeout, %d.\n", vconf_get_ext_errno());
330 for (i = 0; i < array_len(tc); ++i) {
331 if (strcmp(tcname, tc[i].tcname))
338 printf("--------------------------------------------------\n");
341 for (i = 0; i < array_len(tc); ++i) {
347 printf("--------------------------------------------------\n");
350 printf("Success: %d, Fail: %d\n", success, fail);
354 if (vconf_set_int(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, timeout) < 0)
355 printf("Failed to restore LCDNORMAL timeout, %d.\n", vconf_get_ext_errno());
359 static void brightness_init(void *data)
364 static int brightness_unit(int argc, char **argv)
374 static void brightness_exit(void *data)
376 _I("End brightness test.");
379 static const struct test_ops brightness_test_ops = {
380 .priority = TEST_PRIORITY_NORMAL,
381 .name = "brightness",
382 .init = brightness_init,
383 .exit = brightness_exit,
384 .unit = brightness_unit,
387 TEST_OPS_REGISTER(&brightness_test_ops)