Add EPERM errno test for mlock(2).

Signed-off-by: Zeng Linggang <[email protected]>
---
 testcases/kernel/syscalls/mlock/mlock02.c | 42 +++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/mlock/mlock02.c 
b/testcases/kernel/syscalls/mlock/mlock02.c
index a635d24..1e87777 100644
--- a/testcases/kernel/syscalls/mlock/mlock02.c
+++ b/testcases/kernel/syscalls/mlock/mlock02.c
@@ -20,11 +20,15 @@
  * ALGORITHM
  *     test 1:
  *             Call mlock with a NULL address.  ENOMEM should be returned
+ *     test 2:
+ *             The  caller  was  not  privileged and its RLIMIT_MEMLOCK soft
+ *             resource limit was 0. EPERM should be returned
  */
 
 #include <errno.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <pwd.h>
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
@@ -32,20 +36,26 @@
 char *TCID = "mlock02";
 
 static void *addr1;
+static struct passwd *ltpuser;
 static void setup(void);
 static void mlock_verify(int);
+static void setup2(void);
+static void cleanup2(void);
 static void cleanup(void);
 
 static struct test_case_t {
        void **addr;
        int len;
        int error;
+       void (*setupfunc) ();
+       void (*cleanupfunc) ();
 } TC[] = {
-       {&addr1, 1024, ENOMEM},
+       {&addr1, 1024, ENOMEM, NULL, NULL},
+       {&addr1, 1024, EPERM, setup2, cleanup2},
 };
 
 int TST_TOTAL = ARRAY_SIZE(TC);
-static int exp_enos[] = { ENOMEM, 0 };
+static int exp_enos[] = { ENOMEM, EPERM, 0 };
 
 #if !defined(UCLINUX)
 
@@ -85,6 +95,8 @@ int main(void)
 
 static void setup(void)
 {
+       struct rlimit rl;
+
        TEST_PAUSE;
 
 #ifdef __ia64__
@@ -92,12 +104,28 @@ static void setup(void)
 #else
        addr1 = NULL;
 #endif
+       ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
+
+       rl.rlim_cur = 0;
+
+       if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0) {
+               tst_resm(TWARN,
+                        "setrlimit failed to set the resource for "
+                        "RLIMIT_MEMLOCK to check for mlock()");
+               return;
+       }
 }
 
 static void mlock_verify(int i)
 {
+       if (TC[i].setupfunc != NULL)
+               TC[i].setupfunc();
+
        TEST(mlock(*(TC[i].addr), TC[i].len));
 
+       if (TC[i].cleanupfunc != NULL)
+               TC[i].cleanupfunc();
+
        if (TEST_RETURN != -1) {
                tst_resm(TFAIL, "mlock succeeded unexpectedly");
                return;
@@ -112,6 +140,16 @@ static void mlock_verify(int i)
        }
 }
 
+static void setup2(void)
+{
+       SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+}
+
+static void cleanup2(void)
+{
+       SAFE_SETEUID(cleanup, 0);
+}
+
 static void cleanup(void)
 {
        TEST_CLEANUP;
-- 
1.8.4.2




------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to