4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #define METHOD_POWEROFF "PowerOff"
21 #define METHOD_POWEROFF_WITH_OPTION "PowerOffWithOption"
23 static bool set_reboot_method(const char *method, GVariant *param)
26 int reply_val, ret_dbus;
29 ret_dbus = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
30 DEVICED_PATH_POWEROFF,
31 DEVICED_INTERFACE_POWEROFF,
36 _E("fail (%s): no reply", method);
40 if (!g_variant_get_safe(reply, "(i)", &reply_val))
41 _E("fail (%s): no message", method);
43 if ((reply_val == -ENOTSUP) || (reply_val == -ENOSYS)) {
44 _I("Not supported feature! (%s): %d", method, reply_val);
46 } else if (reply_val < 0) {
47 _E("fail (%s): returned fail (%d)", method, reply_val);
49 _I("success (%s): %d", method, reply_val);
54 g_variant_unref(reply);
58 static bool set_reboot(char *type)
60 return set_reboot_method(METHOD_POWEROFF, g_variant_new("(s)", type));
63 static bool set_reboot_with_option(char *type, char *option)
65 return set_reboot_method(METHOD_POWEROFF_WITH_OPTION, g_variant_new("(ss)", type, option));
68 static void power_init(void *data)
75 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
78 static void power_exit(void *data)
83 static int power_unit(int argc, char **argv)
91 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
92 } else if (0 == strcmp(argv[3], METHOD_POWEROFF))
94 else if (0 == strcasecmp(argv[3], METHOD_POWEROFF_WITH_OPTION))
95 set_reboot_with_option(argv[4], argv[5]);
97 _E("Unknown test case!!!");
102 static const struct test_ops power_test_ops = {
103 .priority = TEST_PRIORITY_HIGH,
110 TEST_OPS_REGISTER(&power_test_ops)