1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2002 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * HISTORY 6f08c3bdfSopenharmony_ci * 06/2002 Written by Paul Larson 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/*\ 10f08c3bdfSopenharmony_ci * [Description] 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Test mlock with various valid addresses and lengths. 13f08c3bdfSopenharmony_ci */ 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci#include <stdlib.h> 16f08c3bdfSopenharmony_ci#include "tst_test.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic void *addr; 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic struct tcase { 21f08c3bdfSopenharmony_ci char *msg; 22f08c3bdfSopenharmony_ci int len; 23f08c3bdfSopenharmony_ci} tcases[] = { 24f08c3bdfSopenharmony_ci {"mlock 1 byte", 1}, 25f08c3bdfSopenharmony_ci {"mlock 1024 bytes", 1024}, 26f08c3bdfSopenharmony_ci {"mlock 1024 * 1024 bytes", 1024 * 1024}, 27f08c3bdfSopenharmony_ci {"mlock 1024 * 1024 * 10 bytes", 1024 * 1024 * 10} 28f08c3bdfSopenharmony_ci}; 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_cistatic void do_mlock(unsigned int i) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci struct tcase *tc = &tcases[i]; 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci tst_res(TINFO, "%s", tc->msg); 35f08c3bdfSopenharmony_ci addr = SAFE_MALLOC(tc->len); 36f08c3bdfSopenharmony_ci TST_EXP_PASS(mlock(addr, tc->len), "mlock(%p, %d)", addr, tc->len); 37f08c3bdfSopenharmony_ci free(addr); 38f08c3bdfSopenharmony_ci addr = NULL; 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic void cleanup(void) 42f08c3bdfSopenharmony_ci{ 43f08c3bdfSopenharmony_ci if (addr) 44f08c3bdfSopenharmony_ci free(addr); 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cistatic struct tst_test test = { 48f08c3bdfSopenharmony_ci .needs_root = 1, 49f08c3bdfSopenharmony_ci .test = do_mlock, 50f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(tcases), 51f08c3bdfSopenharmony_ci .cleanup = cleanup, 52f08c3bdfSopenharmony_ci}; 53