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#define _GNU_SOURCE 15f08c3bdfSopenharmony_ci#include <unistd.h> 16f08c3bdfSopenharmony_ci#include <stdio.h> 17f08c3bdfSopenharmony_ci#include <stdlib.h> 18f08c3bdfSopenharmony_ci#include <string.h> 19f08c3bdfSopenharmony_ci#include <time.h> 20f08c3bdfSopenharmony_ci#include <linux/unistd.h> 21f08c3bdfSopenharmony_ci#include <linux/kernel.h> 22f08c3bdfSopenharmony_ci#include <linux/types.h> 23f08c3bdfSopenharmony_ci#include <sys/syscall.h> 24f08c3bdfSopenharmony_ci#include <pthread.h> 25f08c3bdfSopenharmony_ci#include <errno.h> 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci#include "test.h" 28f08c3bdfSopenharmony_ci#include "lapi/sched.h" 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cichar *TCID = "sched_getattr01"; 31f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci#define RUNTIME_VAL 10000000 34f08c3bdfSopenharmony_ci#define PERIOD_VAL 30000000 35f08c3bdfSopenharmony_ci#define DEADLINE_VAL 30000000 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_civoid *run_deadline(void *data LTP_ATTRIBUTE_UNUSED) 38f08c3bdfSopenharmony_ci{ 39f08c3bdfSopenharmony_ci struct sched_attr attr, attr_copy; 40f08c3bdfSopenharmony_ci int ret; 41f08c3bdfSopenharmony_ci unsigned int flags = 0; 42f08c3bdfSopenharmony_ci unsigned int size; 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci attr.size = sizeof(attr); 45f08c3bdfSopenharmony_ci attr.sched_flags = 0; 46f08c3bdfSopenharmony_ci attr.sched_nice = 0; 47f08c3bdfSopenharmony_ci attr.sched_priority = 0; 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci /* This creates a 10ms/30ms reservation */ 50f08c3bdfSopenharmony_ci attr.sched_policy = SCHED_DEADLINE; 51f08c3bdfSopenharmony_ci attr.sched_runtime = RUNTIME_VAL; 52f08c3bdfSopenharmony_ci attr.sched_period = PERIOD_VAL; 53f08c3bdfSopenharmony_ci attr.sched_deadline = DEADLINE_VAL; 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci ret = sched_setattr(0, &attr, flags); 56f08c3bdfSopenharmony_ci if (ret < 0) 57f08c3bdfSopenharmony_ci tst_brkm(TFAIL | TERRNO, NULL, "sched_setattr() failed"); 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci size = sizeof(attr_copy); 60f08c3bdfSopenharmony_ci ret = sched_getattr(0, &attr_copy, size, flags); 61f08c3bdfSopenharmony_ci if (ret < 0) 62f08c3bdfSopenharmony_ci tst_brkm(TFAIL | TERRNO, NULL, "sched_getattr() failed"); 63f08c3bdfSopenharmony_ci 64f08c3bdfSopenharmony_ci int fail = 0; 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ci if (attr_copy.sched_runtime != RUNTIME_VAL) { 67f08c3bdfSopenharmony_ci tst_resm(TINFO, "sched_runtime is incorrect (%"PRIu64")," 68f08c3bdfSopenharmony_ci " expected %u", attr.sched_runtime, RUNTIME_VAL); 69f08c3bdfSopenharmony_ci fail++; 70f08c3bdfSopenharmony_ci } 71f08c3bdfSopenharmony_ci if (attr_copy.sched_period != PERIOD_VAL) { 72f08c3bdfSopenharmony_ci tst_resm(TINFO, "sched_period is incorrect (%"PRIu64")," 73f08c3bdfSopenharmony_ci " expected %u", attr.sched_period, PERIOD_VAL); 74f08c3bdfSopenharmony_ci fail++; 75f08c3bdfSopenharmony_ci } 76f08c3bdfSopenharmony_ci if (attr_copy.sched_deadline != DEADLINE_VAL) { 77f08c3bdfSopenharmony_ci tst_resm(TINFO, "sched_deadline is incorrect (%"PRIu64")," 78f08c3bdfSopenharmony_ci " expected %u", attr.sched_deadline, DEADLINE_VAL); 79f08c3bdfSopenharmony_ci fail++; 80f08c3bdfSopenharmony_ci } 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci if (fail) 83f08c3bdfSopenharmony_ci tst_resm(TFAIL, "attributes were read back incorrectly"); 84f08c3bdfSopenharmony_ci else 85f08c3bdfSopenharmony_ci tst_resm(TPASS, "attributes were read back correctly"); 86f08c3bdfSopenharmony_ci 87f08c3bdfSopenharmony_ci return NULL; 88f08c3bdfSopenharmony_ci} 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ciint main(int argc, char **argv) 91f08c3bdfSopenharmony_ci{ 92f08c3bdfSopenharmony_ci pthread_t thread; 93f08c3bdfSopenharmony_ci int lc; 94f08c3bdfSopenharmony_ci 95f08c3bdfSopenharmony_ci tst_parse_opts(argc, argv, NULL, NULL); 96f08c3bdfSopenharmony_ci 97f08c3bdfSopenharmony_ci tst_require_root(); 98f08c3bdfSopenharmony_ci 99f08c3bdfSopenharmony_ci if ((tst_kvercmp(3, 14, 0)) < 0) 100f08c3bdfSopenharmony_ci tst_brkm(TCONF, NULL, "EDF needs kernel 3.14 or higher"); 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 103f08c3bdfSopenharmony_ci pthread_create(&thread, NULL, run_deadline, NULL); 104f08c3bdfSopenharmony_ci pthread_join(thread, NULL); 105f08c3bdfSopenharmony_ci } 106f08c3bdfSopenharmony_ci 107f08c3bdfSopenharmony_ci tst_exit(); 108f08c3bdfSopenharmony_ci} 109