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