1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) International Business Machines  Corp., 2001
4 *               03/2001 - Written by Wayne Boyer
5 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6 */
7
8/*\
9 * [Description]
10 *
11 * Check that getitimer() call fails:
12 *
13 * 1. EFAULT with invalid itimerval pointer
14 * 2. EINVAL when called with an invalid first argument
15 */
16
17#include <stdlib.h>
18#include <errno.h>
19#include <sys/time.h>
20#include "tst_test.h"
21#include "lapi/syscalls.h"
22
23static struct itimerval *value;
24static struct itimerval *invalid;
25
26static struct tcase {
27       int which;
28       struct itimerval **val;
29       int exp_errno;
30} tcases[] = {
31       {ITIMER_REAL,    &invalid, EFAULT},
32       {ITIMER_VIRTUAL, &invalid, EFAULT},
33       {-ITIMER_PROF,   &value,   EINVAL},
34};
35
36static int sys_getitimer(int which, void *curr_value)
37{
38        return tst_syscall(__NR_getitimer, which, curr_value);
39}
40
41static void setup(void)
42{
43        value = SAFE_MALLOC(sizeof(struct itimerval));
44        invalid = (struct itimerval *)-1;
45}
46
47static void verify_getitimer(unsigned int i)
48{
49        struct tcase *tc = &tcases[i];
50
51        TST_EXP_FAIL(sys_getitimer(tc->which, *(tc->val)), tc->exp_errno);
52}
53
54static void cleanup(void)
55{
56        free(value);
57        value = NULL;
58}
59
60static struct tst_test test = {
61        .tcnt = ARRAY_SIZE(tcases),
62        .test = verify_getitimer,
63        .setup = setup,
64        .cleanup = cleanup,
65};
66