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