Changeset f35749e in mainline for uspace/lib/system
- Timestamp:
- 2025-02-28T23:38:26Z (5 months ago)
- Branches:
- master
- Children:
- 8300c72
- Parents:
- 4285f384
- Location:
- uspace/lib/system
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/system/include/ipc/system.h
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 typedef enum { 46 46 SYSTEM_CALLBACK_CREATE = IPC_FIRST_USER_METHOD, 47 SYSTEM_SHUTDOWN 47 SYSTEM_POWEROFF, 48 SYSTEM_RESTART 48 49 } system_request_t; 49 50 -
uspace/lib/system/include/system.h
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 extern errno_t system_open(const char *, system_cb_t *, void *, system_t **); 44 44 extern void system_close(system_t *); 45 extern errno_t system_shutdown(system_t *); 45 extern errno_t system_poweroff(system_t *); 46 extern errno_t system_restart(system_t *); 46 47 47 48 #endif -
uspace/lib/system/include/system_srv.h
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 49 49 50 50 struct system_ops { 51 errno_t (*shutdown)(void *); 51 errno_t (*poweroff)(void *); 52 errno_t (*restart)(void *); 52 53 }; 53 54 -
uspace/lib/system/src/system.c
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 141 141 } 142 142 143 /** Shut the system down.143 /** Shut down and power the system off. 144 144 * 145 145 * This function is asynchronous. It returns immediately with success … … 151 151 * @return EOK on succes or an error code 152 152 */ 153 errno_t system_ shutdown(system_t *system)153 errno_t system_poweroff(system_t *system) 154 154 { 155 155 async_exch_t *exch = async_exchange_begin(system->sess); 156 errno_t rc = async_req_0_0(exch, SYSTEM_SHUTDOWN); 156 errno_t rc = async_req_0_0(exch, SYSTEM_POWEROFF); 157 async_exchange_end(exch); 158 159 return rc; 160 } 161 162 /** Shut down and restart the system. 163 * 164 * This function is asynchronous. It returns immediately with success 165 * if the system started shutting down. Once shutdown is completed, 166 * the @c shutdown_complete callback is executed. If the shutdown fails, 167 * the @c shutdown_fail callback is executed. 168 * 169 * @param system System control service 170 * @return EOK on succes or an error code 171 */ 172 errno_t system_restart(system_t *system) 173 { 174 async_exch_t *exch = async_exchange_begin(system->sess); 175 errno_t rc = async_req_0_0(exch, SYSTEM_RESTART); 157 176 async_exchange_end(exch); 158 177 -
uspace/lib/system/src/system_srv.c
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 55 55 } 56 56 57 static void system_ shutdown_srv(system_srv_t *srv, ipc_call_t *icall)57 static void system_poweroff_srv(system_srv_t *srv, ipc_call_t *icall) 58 58 { 59 59 errno_t rc; 60 60 61 if (srv->ops-> shutdown== NULL) {61 if (srv->ops->poweroff == NULL) { 62 62 async_answer_0(icall, ENOTSUP); 63 63 return; 64 64 } 65 65 66 rc = srv->ops->shutdown(srv->arg); 66 rc = srv->ops->poweroff(srv->arg); 67 async_answer_0(icall, rc); 68 } 69 70 static void system_restart_srv(system_srv_t *srv, ipc_call_t *icall) 71 { 72 errno_t rc; 73 74 if (srv->ops->restart == NULL) { 75 async_answer_0(icall, ENOTSUP); 76 return; 77 } 78 79 rc = srv->ops->restart(srv->arg); 67 80 async_answer_0(icall, rc); 68 81 } … … 89 102 system_callback_create_srv(srv, &call); 90 103 break; 91 case SYSTEM_SHUTDOWN: 92 system_shutdown_srv(srv, &call); 104 case SYSTEM_POWEROFF: 105 system_poweroff_srv(srv, &call); 106 break; 107 case SYSTEM_RESTART: 108 system_restart_srv(srv, &call); 93 109 break; 94 110 default: -
uspace/lib/system/test/system.c
r4285f384 rf35749e 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 void test_system_conn(ipc_call_t *, void *); 47 47 48 static errno_t test_shutdown(void *); 48 static errno_t test_poweroff(void *); 49 static errno_t test_restart(void *); 49 50 50 51 static void test_sys_shutdown_complete(void *); … … 52 53 53 54 static system_ops_t test_system_srv_ops = { 54 .shutdown = test_shutdown 55 .poweroff = test_poweroff, 56 .restart = test_restart 55 57 }; 56 58 … … 66 68 errno_t rc; 67 69 68 bool shutdown_called; 70 bool poweroff_called; 71 bool restart_called; 69 72 bool shutdown_complete_called; 70 73 bool shutdown_failed_called; … … 103 106 } 104 107 105 /** system_ shutdown() with server returning error response works */106 PCUT_TEST( shutdown_failure)108 /** system_poweroff() with server returning error response works */ 109 PCUT_TEST(poweroff_failure) 107 110 { 108 111 errno_t rc; … … 126 129 127 130 resp.rc = ENOMEM; 128 resp. shutdown_called = false;129 130 rc = system_ shutdown(system);131 PCUT_ASSERT_TRUE(resp. shutdown_called);131 resp.poweroff_called = false; 132 133 rc = system_poweroff(system); 134 PCUT_ASSERT_TRUE(resp.poweroff_called); 132 135 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 133 136 … … 138 141 } 139 142 140 /** system_ shutdown() with server returning success response works */141 PCUT_TEST( shutdown_success)143 /** system_poweroff() with server returning success response works */ 144 PCUT_TEST(poweroff_success) 142 145 { 143 146 errno_t rc; … … 161 164 162 165 resp.rc = EOK; 163 resp.shutdown_called = false; 164 165 rc = system_shutdown(system); 166 PCUT_ASSERT_TRUE(resp.shutdown_called); 166 resp.poweroff_called = false; 167 168 rc = system_poweroff(system); 169 PCUT_ASSERT_TRUE(resp.poweroff_called); 170 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 171 172 system_close(system); 173 rc = loc_service_unregister(srv, sid); 174 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 175 loc_server_unregister(srv); 176 } 177 178 /** system_restart() with server returning error response works */ 179 PCUT_TEST(restart_failure) 180 { 181 errno_t rc; 182 service_id_t sid; 183 system_t *system = NULL; 184 test_response_t resp; 185 loc_srv_t *srv; 186 187 async_set_fallback_port_handler(test_system_conn, &resp); 188 189 // FIXME This causes this test to be non-reentrant! 190 rc = loc_server_register(test_system_server, &srv); 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 193 rc = loc_service_register(srv, test_system_svc, &sid); 194 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 195 196 rc = system_open(test_system_svc, NULL, NULL, &system); 197 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 198 PCUT_ASSERT_NOT_NULL(system); 199 200 resp.rc = ENOMEM; 201 resp.restart_called = false; 202 203 rc = system_restart(system); 204 PCUT_ASSERT_TRUE(resp.restart_called); 205 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 206 207 system_close(system); 208 rc = loc_service_unregister(srv, sid); 209 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 210 loc_server_unregister(srv); 211 } 212 213 /** system_restart() with server returning success response works */ 214 PCUT_TEST(restart_success) 215 { 216 errno_t rc; 217 service_id_t sid; 218 system_t *system = NULL; 219 test_response_t resp; 220 loc_srv_t *srv; 221 222 async_set_fallback_port_handler(test_system_conn, &resp); 223 224 // FIXME This causes this test to be non-reentrant! 225 rc = loc_server_register(test_system_server, &srv); 226 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 227 228 rc = loc_service_register(srv, test_system_svc, &sid); 229 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 230 231 rc = system_open(test_system_svc, NULL, NULL, &system); 232 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 233 PCUT_ASSERT_NOT_NULL(system); 234 235 resp.rc = EOK; 236 resp.restart_called = false; 237 238 rc = system_restart(system); 239 PCUT_ASSERT_TRUE(resp.restart_called); 167 240 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 168 241 … … 279 352 } 280 353 281 /** Test system shutdown.354 /** Test system poweroff. 282 355 * 283 356 * @param arg Argument (test_response_t *) 284 357 */ 285 static errno_t test_ shutdown(void *arg)358 static errno_t test_poweroff(void *arg) 286 359 { 287 360 test_response_t *resp = (test_response_t *)arg; 288 361 289 resp->shutdown_called = true; 362 resp->poweroff_called = true; 363 return resp->rc; 364 } 365 366 /** Test system restart. 367 * 368 * @param arg Argument (test_response_t *) 369 */ 370 static errno_t test_restart(void *arg) 371 { 372 test_response_t *resp = (test_response_t *)arg; 373 374 resp->restart_called = true; 290 375 return resp->rc; 291 376 }
Note:
See TracChangeset
for help on using the changeset viewer.