OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [test0/] [src/] [mmaptest.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Test mmap/munmap posix calls.
3
 *
4
 * Copyright (C) 2007, 2008 Bahadir Balban
5
 */
6
#include <sys/ipc.h>
7
#include <sys/shm.h>
8
#include <sys/types.h>
9
#include <sys/mman.h>
10
#include <sys/types.h>
11
#include <sys/stat.h>
12
#include <fcntl.h>
13
#include <stdio.h>
14
#include <unistd.h>
15
#include <tests.h>
16
#include <errno.h>
17
 
18
int mmaptest(void)
19
{
20
        int fd;
21
        void *base;
22
        int x = 0x1000;
23
 
24
        if ((fd = open("./mmapfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
25
                goto out_err;
26
 
27
        /* Extend the file */
28
        if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
29
                goto out_err;
30
 
31
        if (write(fd, &x, sizeof(x)) < 0)
32
                goto out_err;
33
 
34
        if (IS_ERR(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)))
35
                goto out_err;
36
 
37
        *(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
38
        if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
39
                goto out_err;
40
 
41
        if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
42
                goto out_err;
43
 
44
        *(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
45
        *(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
46
 
47
        printf("MMAP TEST           -- PASSED --\n");
48
        return 0;
49
 
50
out_err:
51
        printf("MMAP TEST           -- FAILED --\n");
52
        return 0;
53
}
54
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.