Array of strings sys_dirs must be NULL-terminated
[helenos.git] / uspace / app / tester / mm / pager1.c
blob639e88f8f940fe9f946c489905265445a94b2908
1 /*
2 * Copyright (c) 2016 Jakub Jermar
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
29 #include <stdio.h>
30 #include <vfs/vfs.h>
31 #include <stdlib.h>
32 #include <as.h>
33 #include <ns.h>
34 #include <async.h>
35 #include <errno.h>
36 #include "../tester.h"
38 #define TEST_FILE "/tmp/testfile"
40 const char text[] = "Hello world!";
42 int fd;
44 static void *create_paged_area(size_t size)
46 size_t nwr;
47 errno_t rc;
49 TPRINTF("Creating temporary file...\n");
51 rc = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE,
52 MODE_READ | MODE_WRITE, &fd);
53 if (rc != EOK)
54 return NULL;
55 (void) vfs_unlink_path(TEST_FILE);
57 rc = vfs_write(fd, (aoff64_t []) { 0 }, text, sizeof(text), &nwr);
58 if (rc != EOK) {
59 vfs_put(fd);
60 return NULL;
63 async_sess_t *vfs_pager_sess;
65 TPRINTF("Connecting to VFS pager...\n");
67 vfs_pager_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_PAGER,
68 0, NULL);
70 if (!vfs_pager_sess) {
71 vfs_put(fd);
72 return NULL;
75 TPRINTF("Creating AS area...\n");
77 void *result = async_as_area_create(AS_AREA_ANY, size,
78 AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0);
79 if (result == AS_MAP_FAILED) {
80 vfs_put(fd);
81 return NULL;
84 return result;
87 static void touch_area(void *area, size_t size)
89 TPRINTF("Touching (faulting-in) AS area...\n");
91 volatile char *ptr = (char *) area;
93 char ch;
94 while ((ch = *ptr++))
95 putchar(ch);
98 const char *test_pager1(void)
100 size_t buffer_len = PAGE_SIZE;
101 void *buffer = create_paged_area(buffer_len);
102 if (!buffer)
103 return "Cannot allocate memory";
105 touch_area(buffer, buffer_len);
107 as_area_destroy(buffer);
108 vfs_put(fd);
110 return NULL;