source: mainline/uspace/app/tester/mm/pager1.c@ 9c4cf0d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9c4cf0d was 9c4cf0d, checked in by Jakub Jermar <jakub@…>, 8 years ago

Rename close() to vfs_put()

This is motivated mainly by the fact that a file handle does not
necessarily correspond to an open file and close() was no longer the
the opposite operation to open().

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2016 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <vfs/vfs.h>
31#include <stdlib.h>
32#include <malloc.h>
33#include <as.h>
34#include <ns.h>
35#include <async.h>
36#include <errno.h>
37#include "../tester.h"
38
39#define TEST_FILE "/tmp/testfile"
40
41const char text[] = "Hello world!";
42
43int fd;
44
45static void *create_paged_area(size_t size)
46{
47 TPRINTF("Creating temporary file...\n");
48
49 fd = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE,
50 MODE_READ | MODE_WRITE);
51 if (fd < 0)
52 return NULL;
53 (void) vfs_unlink_path(TEST_FILE);
54
55 if (write(fd, (aoff64_t []) {0}, text, sizeof(text)) != sizeof(text)) {
56 vfs_put(fd);
57 return NULL;
58 }
59
60 async_sess_t *vfs_pager_sess;
61
62 TPRINTF("Connecting to VFS pager...\n");
63
64 vfs_pager_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_PAGER, 0);
65
66 if (!vfs_pager_sess) {
67 vfs_put(fd);
68 return NULL;
69 }
70
71 TPRINTF("Creating AS area...\n");
72
73 void *result = async_as_area_create(AS_AREA_ANY, size,
74 AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0);
75 if (result == AS_MAP_FAILED) {
76 vfs_put(fd);
77 return NULL;
78 }
79
80 return result;
81}
82
83static void touch_area(void *area, size_t size)
84{
85 TPRINTF("Touching (faulting-in) AS area...\n");
86
87 volatile char *ptr = (char *) area;
88
89 char ch;
90 while ((ch = *ptr++))
91 putchar(ch);
92}
93
94const char *test_pager1(void)
95{
96 size_t buffer_len = PAGE_SIZE;
97 void *buffer = create_paged_area(buffer_len);
98 if (!buffer)
99 return "Cannot allocate memory";
100
101 touch_area(buffer, buffer_len);
102
103 as_area_destroy(buffer);
104 vfs_put(fd);
105
106 return NULL;
107}
Note: See TracBrowser for help on using the repository browser.