1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
4 * AUTHOR: Suresh Babu V. <suresh.babu@wipro.com>
5 */
6
7/*\
8 * [Description]
9 *
10 * Test for checking error conditions for getrlimit(2)
11 *   1) getrlimit(2) returns -1 and sets errno to EFAULT if an invalid
12 *	address is given for address parameter.
13 *   2) getrlimit(2) returns -1 and sets errno to EINVAL if an invalid
14 *	resource type (RLIM_NLIMITS is a out of range resource type) is
15 *	passed.
16 */
17
18#include <sys/resource.h>
19#include "tst_test.h"
20
21#define INVALID_RES_TYPE 1000
22
23static struct rlimit rlim;
24
25static struct tcase {
26	int exp_errno;
27	char *desc;
28	struct rlimit *rlim;
29	int res_type;
30} tcases[] = {
31	{EFAULT, "invalid address", (void *)-1, RLIMIT_CORE},
32	{EINVAL, "invalid resource type", &rlim, INVALID_RES_TYPE}
33};
34
35static void verify_getrlimit(unsigned int i)
36{
37	struct tcase *tc = &tcases[i];
38
39	TST_EXP_FAIL(getrlimit(tc->res_type, tc->rlim),
40				tc->exp_errno,
41				"getrlimit() with %s",
42				tc->desc);
43}
44
45static struct tst_test test = {
46	.tcnt = ARRAY_SIZE(tcases),
47	.test = verify_getrlimit,
48};
49