1/*
2 *  This program is free software; you can redistribute it and/or modify
3 *  it under the terms of the GNU General Public License version 2.
4 *
5 *  This program is distributed in the hope that it will be useful,
6 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
7 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8 *  GNU General Public License for more details.
9 *
10 * Test that munlock return a value of zero upon successful completion.
11 *
12 */
13#include <sys/mman.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <errno.h>
17#include "posixtest.h"
18
19#define BUFSIZE 8
20
21int main() {
22	int result;
23	void *ptr;
24
25	ptr = malloc(BUFSIZE);
26	if(ptr == NULL) {
27                printf("Can not allocate memory.\n");
28                return PTS_UNRESOLVED;
29        }
30
31	if(mlock(ptr, BUFSIZE) != 0){
32		if(errno == EPERM) {
33			printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n");
34		} else {
35			perror("An error occurs when calling mlock()");
36		}
37		return PTS_UNRESOLVED;
38	}
39
40	result = munlock(ptr, BUFSIZE);
41	if(result == 0 && errno == 0){
42		printf("Test PASSED\n");
43		return PTS_PASS;
44	} else if(errno == 0) {
45		printf("mlock did not return a value of zero\n");
46		return PTS_FAIL;
47	}
48
49	perror("Unexpected error");
50	return PTS_UNRESOLVED;
51}
52
53