1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 03/2001 - Written by Wayne Boyer 5f08c3bdfSopenharmony_ci * 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Check that setitimer() call fails: 12f08c3bdfSopenharmony_ci * 13f08c3bdfSopenharmony_ci * 1. EFAULT with invalid itimerval pointer 14f08c3bdfSopenharmony_ci * 2. EINVAL when called with an invalid first argument 15f08c3bdfSopenharmony_ci */ 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#include <errno.h> 18f08c3bdfSopenharmony_ci#include <sys/time.h> 19f08c3bdfSopenharmony_ci#include <stdlib.h> 20f08c3bdfSopenharmony_ci#include "tst_test.h" 21f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic struct itimerval *value, *ovalue; 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_cistatic int sys_setitimer(int which, void *new_value, void *old_value) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci return tst_syscall(__NR_setitimer, which, new_value, old_value); 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void verify_setitimer(unsigned int i) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci switch (i) { 33f08c3bdfSopenharmony_ci case 0: 34f08c3bdfSopenharmony_ci TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT); 35f08c3bdfSopenharmony_ci break; 36f08c3bdfSopenharmony_ci case 1: 37f08c3bdfSopenharmony_ci TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT); 38f08c3bdfSopenharmony_ci break; 39f08c3bdfSopenharmony_ci case 2: 40f08c3bdfSopenharmony_ci TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL); 41f08c3bdfSopenharmony_ci break; 42f08c3bdfSopenharmony_ci } 43f08c3bdfSopenharmony_ci} 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_cistatic void setup(void) 46f08c3bdfSopenharmony_ci{ 47f08c3bdfSopenharmony_ci value->it_value.tv_sec = 30; 48f08c3bdfSopenharmony_ci value->it_value.tv_usec = 0; 49f08c3bdfSopenharmony_ci value->it_interval.tv_sec = 0; 50f08c3bdfSopenharmony_ci value->it_interval.tv_usec = 0; 51f08c3bdfSopenharmony_ci} 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_cistatic struct tst_test test = { 54f08c3bdfSopenharmony_ci .tcnt = 3, 55f08c3bdfSopenharmony_ci .test = verify_setitimer, 56f08c3bdfSopenharmony_ci .setup = setup, 57f08c3bdfSopenharmony_ci .bufs = (struct tst_buffers[]) { 58f08c3bdfSopenharmony_ci {&value, .size = sizeof(struct itimerval)}, 59f08c3bdfSopenharmony_ci {&ovalue, .size = sizeof(struct itimerval)}, 60f08c3bdfSopenharmony_ci {} 61f08c3bdfSopenharmony_ci } 62f08c3bdfSopenharmony_ci}; 63