Merge "Add some <sched.h> tests."

am: 26c59f7082

Change-Id: I5423c0d614e7fee238f0f2980956878111604efe
This commit is contained in:
Elliott Hughes 2017-08-02 19:43:58 +00:00 committed by android-build-merger
commit bc6d5e9288
2 changed files with 43 additions and 11 deletions

View file

@ -25,6 +25,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _SCHED_H_
#define _SCHED_H_
@ -41,22 +42,22 @@ struct sched_param {
int sched_priority;
};
int sched_setscheduler(pid_t, int, const struct sched_param*);
int sched_getscheduler(pid_t);
int sched_setscheduler(pid_t pid, int policy, const struct sched_param* param);
int sched_getscheduler(pid_t pid);
int sched_yield(void);
int sched_get_priority_max(int);
int sched_get_priority_min(int);
int sched_setparam(pid_t, const struct sched_param*);
int sched_getparam(pid_t, struct sched_param*);
int sched_rr_get_interval(pid_t, struct timespec*);
int sched_get_priority_max(int policy);
int sched_get_priority_min(int policy);
int sched_setparam(pid_t pid, const struct sched_param* param);
int sched_getparam(pid_t pid, struct sched_param* param);
int sched_rr_get_interval(pid_t pid, struct timespec* quantum);
#if defined(__USE_GNU)
int clone(int (*)(void*), void*, int, void*, ...) __INTRODUCED_IN_ARM(9)
__INTRODUCED_IN_MIPS(12) __INTRODUCED_IN_X86(17);
int unshare(int) __INTRODUCED_IN(17);
int clone(int (*fn)(void*), void* child_stack, int flags, void* arg, ...)
__INTRODUCED_IN_ARM(9) __INTRODUCED_IN_MIPS(12) __INTRODUCED_IN_X86(17);
int unshare(int flags) __INTRODUCED_IN(17);
int sched_getcpu(void) __INTRODUCED_IN(12);
int setns(int, int) __INTRODUCED_IN(21);
int setns(int fd, int ns_type) __INTRODUCED_IN(21);
#ifdef __LP64__
#define CPU_SETSIZE 1024

View file

@ -270,3 +270,34 @@ TEST(sched, cpu_equal_s) {
CPU_FREE(set1);
CPU_FREE(set2);
}
TEST(sched, sched_get_priority_min_sched_get_priority_max) {
EXPECT_LE(sched_get_priority_min(SCHED_BATCH), sched_get_priority_max(SCHED_BATCH));
EXPECT_LE(sched_get_priority_min(SCHED_FIFO), sched_get_priority_max(SCHED_FIFO));
EXPECT_LE(sched_get_priority_min(SCHED_IDLE), sched_get_priority_max(SCHED_IDLE));
EXPECT_LE(sched_get_priority_min(SCHED_OTHER), sched_get_priority_max(SCHED_OTHER));
EXPECT_LE(sched_get_priority_min(SCHED_RR), sched_get_priority_max(SCHED_RR));
}
TEST(sched, sched_getscheduler_sched_setscheduler) {
// POSIX: "If pid is zero, the scheduling policy shall be returned for the
// calling process".
ASSERT_EQ(sched_getscheduler(getpid()), sched_getscheduler(0));
const int original_policy = sched_getscheduler(getpid());
sched_param p = {};
p.sched_priority = sched_get_priority_min(original_policy);
errno = 0;
ASSERT_EQ(-1, sched_setscheduler(getpid(), INT_MAX, &p));
ASSERT_EQ(EINVAL, errno);
ASSERT_EQ(0, sched_getparam(getpid(), &p));
ASSERT_EQ(original_policy, sched_setscheduler(getpid(), SCHED_BATCH, &p));
// POSIX says this should return the previous policy (here SCHED_BATCH),
// but the Linux system call doesn't, and the glibc wrapper doesn't correct
// this (the "returns 0" behavior is even documented on the man page in
// the BUGS section). This was our historical behavior too, so in the
// absence of reasons to break compatibility with ourselves and glibc, we
// don't behave as POSIX specifies. http://b/26203902.
ASSERT_EQ(0, sched_setscheduler(getpid(), original_policy, &p));
}