TEST(spawn, posix_spawnattr_setsschedparam_posix_spawnattr_getsschedparam) { posix_spawnattr_t sa; ASSERT_EQ(0, posix_spawnattr_init(&sa)); sched_param sp; ASSERT_EQ(0, posix_spawnattr_getschedparam(&sa, &sp)); ASSERT_EQ(0, sp.sched_priority); sched_param sp123 = { .sched_priority = 123 }; ASSERT_EQ(0, posix_spawnattr_setschedparam(&sa, &sp123)); ASSERT_EQ(0, posix_spawnattr_getschedparam(&sa, &sp)); ASSERT_EQ(123, sp.sched_priority); ASSERT_EQ(0, posix_spawnattr_destroy(&sa)); } TEST(spawn, posix_spawnattr_setschedpolicy_posix_spawnattr_getschedpolicy) { posix_spawnattr_t sa; ASSERT_EQ(0, posix_spawnattr_init(&sa)); int p; ASSERT_EQ(0, posix_spawnattr_getschedpolicy(&sa, &p)); ASSERT_EQ(0, p); ASSERT_EQ(0, posix_spawnattr_setschedpolicy(&sa, SCHED_FIFO)); ASSERT_EQ(0, posix_spawnattr_getschedpolicy(&sa, &p)); ASSERT_EQ(SCHED_FIFO, p); ASSERT_EQ(0, posix_spawnattr_destroy(&sa)); }
static int l_posix_spawnattr_setschedpolicy(lua_State *L) { int r; posix_spawnattr_t *attr = luaL_checkudata(L, 1, "posix_spawnattr_t"); int schedpolicy = luaL_checkinteger(L, 2); if (0 != (r = posix_spawnattr_setschedpolicy(attr, schedpolicy))) { lua_pushnil(L); lua_pushstring(L, strerror(r)); lua_pushinteger(L, r); return 3; } lua_pushboolean(L, 1); return 1; }
/** * @fn :tc_libc_spawn_posix_spawnattr_dump * @brief :Show the current attributes * @scenario :It dumps the spawn attributes whose address is passed * @API's covered :posix_spawnattr_init,posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy, posix_spawnattr_dump * @Preconditions :posix_spawnattr_init, posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy * @Postconditions :none * @Return :void */ static void tc_libc_spawn_posix_spawnattr_dump(void) { int ret_chk = ERROR; pid_t pid; posix_spawnattr_t st_attr; ret_chk = posix_spawnattr_init(&st_attr); TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK); ret_chk = posix_spawnattr_setschedpolicy(&st_attr, SCHED_RR); TC_ASSERT_EQ("posix_spawnattr_setschedpolicy", ret_chk, OK); ret_chk = task_spawn(&pid, "spawn_dump", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL); sleep(SEC_4); TC_ASSERT_EQ("task_spawn", ret_chk, OK); posix_spawnattr_dump(&st_attr); TC_SUCCESS_RESULT(); }
int exec_builtin(FAR const char *appname, FAR char * const *argv, FAR const char *redirfile, int oflags) { FAR const struct builtin_s *builtin; posix_spawnattr_t attr; posix_spawn_file_actions_t file_actions; struct sched_param param; pid_t pid; int index; int ret; /* Verify that an application with this name exists */ index = builtin_isavail(appname); if (index < 0) { ret = ENOENT; goto errout_with_errno; } /* Get information about the builtin */ builtin = builtin_for_index(index); if (builtin == NULL) { ret = ENOENT; goto errout_with_errno; } /* Initialize attributes for task_spawn(). */ ret = posix_spawnattr_init(&attr); if (ret != 0) { goto errout_with_errno; } ret = posix_spawn_file_actions_init(&file_actions); if (ret != 0) { goto errout_with_attrs; } /* Set the correct task size and priority */ param.sched_priority = builtin->priority; ret = posix_spawnattr_setschedparam(&attr, ¶m); if (ret != 0) { goto errout_with_actions; } ret = task_spawnattr_setstacksize(&attr, builtin->stacksize); if (ret != 0) { goto errout_with_actions; } /* If robin robin scheduling is enabled, then set the scheduling policy * of the new task to SCHED_RR before it has a chance to run. */ #if CONFIG_RR_INTERVAL > 0 ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR); if (ret != 0) { goto errout_with_actions; } ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER); if (ret != 0) { goto errout_with_actions; } #else ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM); if (ret != 0) { goto errout_with_actions; } #endif /* Is output being redirected? */ if (redirfile) { /* Set up to close open redirfile and set to stdout (1) */ ret = posix_spawn_file_actions_addopen(&file_actions, 1, redirfile, O_WRONLY, 0644); if (ret != 0) { sdbg("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); goto errout_with_actions; } } /* Start the built-in */ ret = task_spawn(&pid, builtin->name, builtin->main, &file_actions, &attr, (argv) ? &argv[1] : (FAR char * const *)NULL, (FAR char * const *)NULL); if (ret != 0) { sdbg("ERROR: task_spawn failed: %d\n", ret); goto errout_with_actions; } /* Free attibutes and file actions. Ignoring return values in the case * of an error. */ /* Return the task ID of the new task if the task was sucessfully * started. Otherwise, ret will be ERROR (and the errno value will * be set appropriately). */ (void)posix_spawn_file_actions_destroy(&file_actions); (void)posix_spawnattr_destroy(&attr); return pid; errout_with_actions: (void)posix_spawn_file_actions_destroy(&file_actions); errout_with_attrs: (void)posix_spawnattr_destroy(&attr); errout_with_errno: set_errno(ret); return ERROR; }