1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR: Nirmala Devi Dhanasekar <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * Test munlock with various valid addresses and lengths.
11*49cdfc7eSAndroid Build Coastguard Worker */
12*49cdfc7eSAndroid Build Coastguard Worker
13*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
15*49cdfc7eSAndroid Build Coastguard Worker
16*49cdfc7eSAndroid Build Coastguard Worker static void *addr;
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
19*49cdfc7eSAndroid Build Coastguard Worker char *msg;
20*49cdfc7eSAndroid Build Coastguard Worker int len;
21*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
22*49cdfc7eSAndroid Build Coastguard Worker {"munlock 1 byte", 1},
23*49cdfc7eSAndroid Build Coastguard Worker {"munlock 1024 bytes", 1024},
24*49cdfc7eSAndroid Build Coastguard Worker {"munlock 1024 * 1024 bytes", 1024 * 1024},
25*49cdfc7eSAndroid Build Coastguard Worker {"munlock 1024 * 1024 * 10 bytes", 1024 * 1024 * 10}
26*49cdfc7eSAndroid Build Coastguard Worker };
27*49cdfc7eSAndroid Build Coastguard Worker
verify_munlock(unsigned int i)28*49cdfc7eSAndroid Build Coastguard Worker static void verify_munlock(unsigned int i)
29*49cdfc7eSAndroid Build Coastguard Worker {
30*49cdfc7eSAndroid Build Coastguard Worker struct tcase *tc = &tcases[i];
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker tst_res(TINFO, "%s", tc->msg);
33*49cdfc7eSAndroid Build Coastguard Worker addr = SAFE_MALLOC(tc->len);
34*49cdfc7eSAndroid Build Coastguard Worker SAFE_MLOCK(addr, tc->len);
35*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS(munlock(addr, tc->len), "munlock(%p, %d)", addr, tc->len);
36*49cdfc7eSAndroid Build Coastguard Worker free(addr);
37*49cdfc7eSAndroid Build Coastguard Worker addr = NULL;
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)40*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
41*49cdfc7eSAndroid Build Coastguard Worker {
42*49cdfc7eSAndroid Build Coastguard Worker if (addr)
43*49cdfc7eSAndroid Build Coastguard Worker free(addr);
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
48*49cdfc7eSAndroid Build Coastguard Worker .test = verify_munlock,
49*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
50*49cdfc7eSAndroid Build Coastguard Worker .cleanup = cleanup,
51*49cdfc7eSAndroid Build Coastguard Worker };
52