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 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6f08c3bdfSopenharmony_ci */
7f08c3bdfSopenharmony_ci
8f08c3bdfSopenharmony_ci/*\
9f08c3bdfSopenharmony_ci * [Description]
10f08c3bdfSopenharmony_ci *
11f08c3bdfSopenharmony_ci * Check that getitimer() 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 <stdlib.h>
18f08c3bdfSopenharmony_ci#include <errno.h>
19f08c3bdfSopenharmony_ci#include <sys/time.h>
20f08c3bdfSopenharmony_ci#include "tst_test.h"
21f08c3bdfSopenharmony_ci#include "lapi/syscalls.h"
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_cistatic struct itimerval *value;
24f08c3bdfSopenharmony_cistatic struct itimerval *invalid;
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_cistatic struct tcase {
27f08c3bdfSopenharmony_ci       int which;
28f08c3bdfSopenharmony_ci       struct itimerval **val;
29f08c3bdfSopenharmony_ci       int exp_errno;
30f08c3bdfSopenharmony_ci} tcases[] = {
31f08c3bdfSopenharmony_ci       {ITIMER_REAL,    &invalid, EFAULT},
32f08c3bdfSopenharmony_ci       {ITIMER_VIRTUAL, &invalid, EFAULT},
33f08c3bdfSopenharmony_ci       {-ITIMER_PROF,   &value,   EINVAL},
34f08c3bdfSopenharmony_ci};
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_cistatic int sys_getitimer(int which, void *curr_value)
37f08c3bdfSopenharmony_ci{
38f08c3bdfSopenharmony_ci        return tst_syscall(__NR_getitimer, which, curr_value);
39f08c3bdfSopenharmony_ci}
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_cistatic void setup(void)
42f08c3bdfSopenharmony_ci{
43f08c3bdfSopenharmony_ci        value = SAFE_MALLOC(sizeof(struct itimerval));
44f08c3bdfSopenharmony_ci        invalid = (struct itimerval *)-1;
45f08c3bdfSopenharmony_ci}
46f08c3bdfSopenharmony_ci
47f08c3bdfSopenharmony_cistatic void verify_getitimer(unsigned int i)
48f08c3bdfSopenharmony_ci{
49f08c3bdfSopenharmony_ci        struct tcase *tc = &tcases[i];
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci        TST_EXP_FAIL(sys_getitimer(tc->which, *(tc->val)), tc->exp_errno);
52f08c3bdfSopenharmony_ci}
53f08c3bdfSopenharmony_ci
54f08c3bdfSopenharmony_cistatic void cleanup(void)
55f08c3bdfSopenharmony_ci{
56f08c3bdfSopenharmony_ci        free(value);
57f08c3bdfSopenharmony_ci        value = NULL;
58f08c3bdfSopenharmony_ci}
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_cistatic struct tst_test test = {
61f08c3bdfSopenharmony_ci        .tcnt = ARRAY_SIZE(tcases),
62f08c3bdfSopenharmony_ci        .test = verify_getitimer,
63f08c3bdfSopenharmony_ci        .setup = setup,
64f08c3bdfSopenharmony_ci        .cleanup = cleanup,
65f08c3bdfSopenharmony_ci};
66