/* * Copyright (c) 1997 X/Open Company Ltd., A member of The Open Group * * All rights reserved. No part of this source code may be reproduced, * stored in a retrieval system, or transmitted, in any form or by any * means, electronic, mechanical, photocopying, recording or otherwise, * except as stated in the end-user licence agreement, without the prior * permission of the copyright owners. * * Motif, OSF/1 and UNIX are registered trademarks and X/Open, * the "X Device" and The Open Group are trademarks of The Open Group. * * Developed for X/Open by Applied Testing and Technology, Inc. * * Project: VSRT * * File: tset/rt.os/mlock/mlockall/mlockall.c * * Modifications: * $Log: mlockall.c,v $ * Revision 2.0 1997/06/15 19:45:55 andy * Branch point for Release 5.0.0b1 * * Revision 1.1 1997/05/27 18:06:53 andy * Initial revision * */ #ifndef lint #define MAIN #ifdef MAIN static char sccsid[] = "@(#)rt.os/mlock/mlockall - T.mlockall Rel 4.3.1 (05/18/93)"; char *copyright[] = { "(C) Copyright 1997 X/Open Company Limited", "All Rights Reserved." }; #endif /* MAIN */ #endif /* lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NO_TESTS 7 /* number of tests in testset */ #ifdef UNDEF_MACROS #undef mlockall #endif #define WAITTIME (5 * SPEEDFACTOR) extern char *errname(); extern char *execpath(); int no_tests = NO_TESTS; private int tb_mlockall(); private void test1(); private void test2(); private void test3(); private void test4(); private void test5(); private void test6(); private void test7(); private void ch_t1(); private void ch_t2(); private void ch_t3(); private void ch_t4(); private void ch_t5(); int supports_mlockall; int supports_mmap; int supports_msync; extern char **environ; #define test_file "vsrt_mlockall" void atstart(void); void atstart(void) { vsrt_check_support("MLOCKALL", &supports_mlockall); vsrt_check_support("MMAP", &supports_mmap); vsrt_check_support("MSYNC", &supports_msync); } public void (*setfunc) () = atstart; public void (*clnfunc) () = NULL; public struct tet_testlist tet_testlist[] = { test1, 1, test2, 2, test3, 3, test4, 4, test5, 5, test6, 6, test7, 7, NULL, 0 }; /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5: A succesful call to mlockall() when flags contains MCL_CURRENT shall cause all of the pages currently mapped by the address space of a process to be locked and return 0. */ private void test1() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test1"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #ifndef _POSIX_MAPPED_FILES if (!supports_mmap) { in_rpt("mmap not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #if !defined(_POSIX_MAPPED_FILES) || !defined(_POSIX_SYNCHRONIZED_IO) if (!supports_msync) { in_rpt("msync not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif (void) cppair(ch_t1, NULLFN, 4 * WAITTIME, 0); DBUG_VOID_RETURN } private void ch_t1() { int err; char *args[5]; DBUG_ENTER("ch_t1"); args[0] = "mlockall1"; args[1] = NULL; (void) tet_exec(execpath("mlockall1"), args, environ); err = errno; xx_rpt(FAILURE); in_rpt("tet_exec(%s, ...) failed - errno %d (%s)", "mlockall1", err, errname(err)); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5: A succesful call to mlockall() when flags contains MCL_FUTURE shall cause all of the pages mapped by the address space of a process in the future, when those mappings are established, to be locked, and return 0. */ private void test2() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test2"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #ifndef _POSIX_MAPPED_FILES if (!supports_mmap) { in_rpt("mmap not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #if !defined(_POSIX_MAPPED_FILES) || !defined(_POSIX_SYNCHRONIZED_IO) if (!supports_msync) { in_rpt("msync not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif (void) cppair(ch_t2, NULLFN, 4 * WAITTIME, 0); DBUG_VOID_RETURN } private void ch_t2() { int err; char *args[5]; DBUG_ENTER("ch_t2"); args[0] = "mlockall2"; args[1] = NULL; (void) tet_exec(execpath("mlockall2"), args, environ); err = errno; xx_rpt(FAILURE); in_rpt("tet_exec(%s, ...) failed - errno %d (%s)", "mlockall2", err, errname(err)); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5: A succesful call to mlockall() when flags contains MCL_FUTURE and MCL_CURRENT shall cause all of the pages currently mapped by the address space of a pro- cess and those mapped in the future, when those map- pings are established, to be locked, and return 0. */ private void test3() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test3"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #ifndef _POSIX_MAPPED_FILES if (!supports_mmap) { in_rpt("mmap not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif #if !defined(_POSIX_MAPPED_FILES) || !defined(_POSIX_SYNCHRONIZED_IO) if (!supports_msync) { in_rpt("msync not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif (void) cppair(ch_t3, NULLFN, 4 * WAITTIME, 0); DBUG_VOID_RETURN } private void ch_t3() { int err; char *args[5]; DBUG_ENTER("ch_t3"); args[0] = "mlockall3"; args[1] = NULL; (void) tet_exec(execpath("mlockall3"), args, environ); err = errno; xx_rpt(FAILURE); in_rpt("tet_exec(%s, ...) failed - errno %d (%s)", "mlockall3", err, errname(err)); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5: A call to mlockall() when flags is 0 shall return -1 and set errno to EINVAL. */ private void test4() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test4"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif (void) cppair(ch_t4, NULLFN, 4 * WAITTIME, 0); DBUG_VOID_RETURN } private void ch_t4() { int err; char *args[5]; DBUG_ENTER("ch_t4"); args[0] = "mlockall4"; args[1] = NULL; (void) tet_exec(execpath("mlockall4"), args, environ); err = errno; xx_rpt(FAILURE); in_rpt("tet_exec(%s, ...) failed - errno %d (%s)", "mlockall4", err, errname(err)); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5: A call to mlockall() when flags contains unimple- mented flags shall return -1 and set errno to EINVAL. */ private void test5() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test5"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif (void) cppair(ch_t5, NULLFN, 4 * WAITTIME, 0); DBUG_VOID_RETURN } private void ch_t5() { int err; char *args[5]; DBUG_ENTER("ch_t5"); args[0] = "mlockall5"; args[1] = NULL; (void) tet_exec(execpath("mlockall5"), args, environ); err = errno; xx_rpt(FAILURE); in_rpt("tet_exec(%s, ...) failed - errno %d (%s)", "mlockall5", err, errname(err)); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is defined or the implementation sup- ports the mlockall() function as defined in System Interfaces and Headers, Issue 5 and the implementation requires a process to have appropriate privilege to call mlockall(): A call to mlockall() when the calling process does not have the appropriate privilege to perform the requested operation shall return -1 and set errno to EPERM. */ private void test6() { int err; int pathok = 0; DBUG_ENTER("test6"); #ifndef _POSIX_MEMLOCK if (!supports_mlockall) { in_rpt("mlockall not supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } #endif if (tb_mlockall(MCL_FUTURE) != -1) { in_rpt("mlockall() succeeded"); xx_rpt(FAILURE); DBUG_VOID_RETURN } if (errno != EPERM) { vsrt_sysfail("mlockall"); xx_rpt(FAILURE); DBUG_VOID_RETURN } xs_rpt(); DBUG_VOID_RETURN } /* If _POSIX_MEMLOCK is not defined and the implementation codes not support the mlockall() function as defined in System Interfaces and Headers, Issue 5: A call to mlockall() shall return -1 and set errno to ENOSYS. */ private void test7() { int fd; int err; int pathok = 0; int errors = 0; DBUG_ENTER("test7"); #ifdef _POSIX_MEMLOCK in_rpt("_POSIX_MEMLOCK supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN #else if (supports_mlockall) { in_rpt("mlockall supported"); xx_rpt(UNSUPPORTED); DBUG_VOID_RETURN } if (tb_mlockall(MCL_FUTURE) != -1) { in_rpt("mlockall() succeeded"); xx_rpt(FAILURE); DBUG_VOID_RETURN } if (errno != ENOSYS) { vsrt_sysfail("mlockall"); xx_rpt(FAILURE); DBUG_VOID_RETURN } xs_rpt(); DBUG_VOID_RETURN #endif } private int tb_mlockall(flags) int flags; { int retval; retval = mlockall(flags); #ifdef TESTBED errno++; return -1; #else return retval; #endif }