Changeset e755b3f in mainline


Ignore:
Timestamp:
2016-09-02T16:10:39Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b1956e3
Parents:
ae6021d
Message:

Modify pager1 test to map a temporary file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/mm/pager1.c

    rae6021d re755b3f  
    2929#include <stdio.h>
    3030#include <unistd.h>
     31#include <fcntl.h>
    3132#include <stdlib.h>
    3233#include <malloc.h>
     
    3738#include "../tester.h"
    3839
     40#define TEST_FILE       "/tmp/testfile"
     41
     42const char text[] = "Hello world!";
     43
     44int fd;
     45
    3946static void *create_paged_area(size_t size)
    4047{
     48        TPRINTF("Creating temporary file...\n");
     49
     50        fd = open(TEST_FILE, O_CREAT);
     51        if (fd < 0)
     52                return NULL;
     53        (void) unlink(TEST_FILE);
     54        if (write(fd, text, sizeof(text)) != sizeof(text)) {
     55                close(fd);
     56                return NULL;
     57        }
     58
    4159        async_sess_t *vfs_pager_sess;
    4260
     
    4563        vfs_pager_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_PAGER, 0);
    4664
    47         if (!vfs_pager_sess)
     65        if (!vfs_pager_sess) {
     66                close(fd);
    4867                return NULL;
     68        }
    4969       
    5070        TPRINTF("Creating AS area...\n");
    5171       
    5272        void *result = async_as_area_create(AS_AREA_ANY, size,
    53             AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, 0, 0, 0);
    54         if (result == AS_MAP_FAILED)
     73            AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0);
     74        if (result == AS_MAP_FAILED) {
     75                close(fd);
    5576                return NULL;
     77        }
    5678       
    5779        return result;
     
    7395        size_t buffer_len = PAGE_SIZE;
    7496        void *buffer = create_paged_area(buffer_len);
    75         if (!buffer) {
     97        if (!buffer)
    7698                return "Cannot allocate memory";
    77         }
    7899       
    79100        touch_area(buffer, buffer_len);
     101
     102        as_area_destroy(buffer);       
     103        close(fd);
    80104       
    81105        return NULL;
Note: See TracChangeset for help on using the changeset viewer.