1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd., 2015 3f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 4f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 5f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 6f08c3bdfSopenharmony_ci * (at your option) any later version. 7f08c3bdfSopenharmony_ci * 8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 9f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 11f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci /* Description: 15f08c3bdfSopenharmony_ci * Verify that: 16f08c3bdfSopenharmony_ci * 1) sched_getattr fails with unused pid 17f08c3bdfSopenharmony_ci * 2) sched_getattr fails with invalid address 18f08c3bdfSopenharmony_ci * 3) sched_getattr fails with invalid value 19f08c3bdfSopenharmony_ci * 4) sched_getattr fails with invalid flag 20f08c3bdfSopenharmony_ci */ 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci#define _GNU_SOURCE 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci#include <unistd.h> 25f08c3bdfSopenharmony_ci#include <stdio.h> 26f08c3bdfSopenharmony_ci#include <stdlib.h> 27f08c3bdfSopenharmony_ci#include <string.h> 28f08c3bdfSopenharmony_ci#include <time.h> 29f08c3bdfSopenharmony_ci#include <linux/unistd.h> 30f08c3bdfSopenharmony_ci#include <linux/kernel.h> 31f08c3bdfSopenharmony_ci#include <linux/types.h> 32f08c3bdfSopenharmony_ci#include <sys/syscall.h> 33f08c3bdfSopenharmony_ci#include <pthread.h> 34f08c3bdfSopenharmony_ci#include <errno.h> 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci#include "test.h" 37f08c3bdfSopenharmony_ci#include "lapi/sched.h" 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_cichar *TCID = "sched_getattr02"; 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic pid_t pid; 42f08c3bdfSopenharmony_cistatic pid_t unused_pid; 43f08c3bdfSopenharmony_cistruct sched_attr attr_copy; 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_cistatic struct test_case { 46f08c3bdfSopenharmony_ci pid_t *pid; 47f08c3bdfSopenharmony_ci struct sched_attr *a; 48f08c3bdfSopenharmony_ci unsigned int size; 49f08c3bdfSopenharmony_ci unsigned int flags; 50f08c3bdfSopenharmony_ci int exp_errno; 51f08c3bdfSopenharmony_ci} test_cases[] = { 52f08c3bdfSopenharmony_ci {&unused_pid, &attr_copy, sizeof(struct sched_attr), 0, ESRCH}, 53f08c3bdfSopenharmony_ci {&pid, NULL, sizeof(struct sched_attr), 0, EINVAL}, 54f08c3bdfSopenharmony_ci {&pid, &attr_copy, sizeof(struct sched_attr) - 1, 0, EINVAL}, 55f08c3bdfSopenharmony_ci {&pid, &attr_copy, sizeof(struct sched_attr), 1000, EINVAL} 56f08c3bdfSopenharmony_ci}; 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_cistatic void setup(void); 59f08c3bdfSopenharmony_cistatic void sched_getattr_verify(const struct test_case *test); 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ciint TST_TOTAL = ARRAY_SIZE(test_cases); 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_cistatic void sched_getattr_verify(const struct test_case *test) 64f08c3bdfSopenharmony_ci{ 65f08c3bdfSopenharmony_ci TEST(sched_getattr(*(test->pid), test->a, test->size, 66f08c3bdfSopenharmony_ci test->flags)); 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_ci if (TEST_RETURN != -1) { 69f08c3bdfSopenharmony_ci tst_resm(TFAIL, "sched_getattr() succeeded unexpectedly."); 70f08c3bdfSopenharmony_ci return; 71f08c3bdfSopenharmony_ci } 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci if (TEST_ERRNO == test->exp_errno) { 74f08c3bdfSopenharmony_ci tst_resm(TPASS | TTERRNO, 75f08c3bdfSopenharmony_ci "sched_getattr() failed expectedly"); 76f08c3bdfSopenharmony_ci return; 77f08c3bdfSopenharmony_ci } 78f08c3bdfSopenharmony_ci 79f08c3bdfSopenharmony_ci tst_resm(TFAIL | TTERRNO, "sched_getattr() failed unexpectedly " 80f08c3bdfSopenharmony_ci ": expected: %d - %s", 81f08c3bdfSopenharmony_ci test->exp_errno, tst_strerrno(test->exp_errno)); 82f08c3bdfSopenharmony_ci} 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ciint main(int argc, char **argv) 85f08c3bdfSopenharmony_ci{ 86f08c3bdfSopenharmony_ci int lc, i; 87f08c3bdfSopenharmony_ci 88f08c3bdfSopenharmony_ci tst_parse_opts(argc, argv, NULL, NULL); 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ci setup(); 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 93f08c3bdfSopenharmony_ci for (i = 0; i < TST_TOTAL; i++) 94f08c3bdfSopenharmony_ci sched_getattr_verify(&test_cases[i]); 95f08c3bdfSopenharmony_ci } 96f08c3bdfSopenharmony_ci 97f08c3bdfSopenharmony_ci tst_exit(); 98f08c3bdfSopenharmony_ci} 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_civoid setup(void) 101f08c3bdfSopenharmony_ci{ 102f08c3bdfSopenharmony_ci unused_pid = tst_get_unused_pid(setup); 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_ci if ((tst_kvercmp(3, 14, 0)) < 0) 105f08c3bdfSopenharmony_ci tst_brkm(TCONF, NULL, "EDF needs kernel 3.14 or higher"); 106f08c3bdfSopenharmony_ci 107f08c3bdfSopenharmony_ci TEST_PAUSE; 108f08c3bdfSopenharmony_ci} 109