source: mainline/uspace/app/tester/mm/mapping1.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[b93d637]1/*
2 * Copyright (c) 2011 Vojtech Horky
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 <stdlib.h>
[582a0b8]31#include <stddef.h>
[c1694b6b]32#include <str_error.h>
[b93d637]33#include <as.h>
34#include <errno.h>
35#include "../tester.h"
36
[fbcdeb8]37#define BUFFER1_PAGES 4
38#define BUFFER2_PAGES 2
[b93d637]39
40static void *create_as_area(size_t size)
41{
42 TPRINTF("Creating AS area...\n");
[a35b458]43
[faba839]44 void *result = as_area_create(AS_AREA_ANY, size,
[6aeca0d]45 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
[faba839]46 if (result == AS_MAP_FAILED)
[b93d637]47 return NULL;
[a35b458]48
[b93d637]49 return result;
50}
51
52static void touch_area(void *area, size_t size)
53{
54 TPRINTF("Touching (faulting-in) AS area...\n");
[a35b458]55
[b93d637]56 char *ptr = (char *)area;
[a35b458]57
[b93d637]58 while (size > 0) {
59 *ptr = 0;
60 size--;
61 ptr++;
62 }
63}
64
65#define VERIFY_MAPPING(area, page_count, expected_rc) \
66 verify_mapping((area), (page_count), (expected_rc), #expected_rc)
67
[b7fd2a0]68static bool verify_mapping(void *area, int page_count, errno_t expected_rc,
[b93d637]69 const char *expected_rc_str)
70{
71 TPRINTF("Verifying mapping (expected: %s).\n", expected_rc_str);
72 int i;
73 for (i = 0; i < page_count; i++) {
[c8751452]74 void *page_start = ((char *) area) + PAGE_SIZE * i;
[b7fd2a0]75 errno_t rc = as_get_physical_mapping(page_start, NULL);
[b93d637]76 if (rc != expected_rc) {
[c1694b6b]77 TPRINTF("as_get_physical_mapping() = %s != %s\n",
78 str_error_name(rc), str_error_name(expected_rc));
[b93d637]79 return false;
80 }
81 }
82 return true;
83}
84
85const char *test_mapping1(void)
86{
[b7fd2a0]87 errno_t rc;
[a35b458]88
[b93d637]89 size_t buffer1_len = BUFFER1_PAGES * PAGE_SIZE;
90 size_t buffer2_len = BUFFER2_PAGES * PAGE_SIZE;
91 void *buffer1 = create_as_area(buffer1_len);
92 void *buffer2 = create_as_area(buffer2_len);
93 if (!buffer1 || !buffer2) {
94 return "Cannot allocate memory";
95 }
[a35b458]96
[b93d637]97 touch_area(buffer1, buffer1_len);
98 touch_area(buffer2, buffer2_len);
[a35b458]99
[b93d637]100 /* Now verify that mapping to physical frames exist. */
101 if (!VERIFY_MAPPING(buffer1, BUFFER1_PAGES, EOK)) {
102 return "Failed to find mapping (buffer1)";
103 }
104 if (!VERIFY_MAPPING(buffer2, BUFFER2_PAGES, EOK)) {
105 return "Failed to find mapping (buffer2)";
106 }
[a35b458]107
[b93d637]108 /* Let's destroy the buffer1 area and access it again. */
109 rc = as_area_destroy(buffer1);
110 if (rc != EOK) {
111 return "Failed to destroy AS area";
112 }
113 if (!VERIFY_MAPPING(buffer1, BUFFER1_PAGES, ENOENT)) {
114 return "Mapping of destroyed area still exists";
115 }
[a35b458]116
[b93d637]117 /* clean-up */
118 rc = as_area_destroy(buffer2);
119 if (rc != EOK) {
120 return "Failed to destroy AS area";
121 }
[a35b458]122
[b93d637]123 return NULL;
124}
Note: See TracBrowser for help on using the repository browser.