This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacros.cpp
170 lines (135 loc) · 3.25 KB
/
macros.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifdef DEBUG
#include <types.h>
#include <filesystem/ioctl.hpp>
#include <interface/syscalls.h>
#include <memory/macro.hpp>
#include <memory/vma.hpp>
#include <filesystem.hpp>
#include <assert.h>
#include <debug.h>
/* static assert, no constructor needed */
#ifdef a64
#if UINTPTR_MAX != UINT64_MAX
#error "uintptr_t is not 64-bit!"
#endif // UINTPTR_MAX != UINT64_MAX
#endif // a64
#ifdef a32
#if UINTPTR_MAX != UINT32_MAX
#error "uintptr_t is not 32-bit!"
#endif // UINTPTR_MAX != UINT32_MAX
#endif // a32
#ifdef aa64
#if UINTPTR_MAX != UINT64_MAX
#error "uintptr_t is not 64-bit!"
#endif // UINTPTR_MAX != UINT64_MAX
#endif // aa64
#ifndef __fennix__
#error "This compiler is not supported!"
#endif // __fennix__
static_assert(TIOCGPTN == 0x80045430);
static_assert(TIOCSPTLCK == 0x40045431);
__constructor void TestMacros()
{
{
int a = TO_PAGES(4096);
int b = FROM_PAGES(1);
debug("a: 4096 -> %d", a);
debug("b: a -> %d", b);
if (a != 1)
{
error("t1: TO_PAGES is not equal to 1");
inf_loop;
}
if (b != 4096)
{
error("t1: FROM_PAGES is not equal to 4096");
inf_loop;
}
}
{
int a = TO_PAGES(4097);
int b = FROM_PAGES(2);
debug("a: 4097 -> %d", a);
debug("b: a -> %d", b);
if (a != 2)
{
error("t2: TO_PAGES is not equal to 2");
inf_loop;
}
if (b != 8192)
{
error("t2: FROM_PAGES is not equal to 8192");
inf_loop;
}
}
{
int a = 10;
assert(a == 10);
const char *str = "Hello";
assert(str != nullptr && str[0] == 'H');
bool flag = false;
assert(!flag);
}
debug("-------------------------");
{
uint64_t bytes = PAGE_SIZE;
uint64_t pgs = 1;
for (int i = 0; i < 128; i++)
{
uint64_t cnv_to_pgs = TO_PAGES(bytes);
uint64_t cnv_from_pgs = FROM_PAGES(pgs);
if (cnv_to_pgs != pgs)
{
error("TO_PAGES is not equal to %d (pages: %d)", pgs, cnv_to_pgs);
inf_loop;
}
if (cnv_from_pgs != bytes)
{
error("FROM_PAGES is not equal to %d (bytes: %d)", bytes, cnv_from_pgs);
inf_loop;
}
bytes += PAGE_SIZE;
pgs++;
}
}
{
debug("Testing ROUND_UP and ROUND_DOWN");
int x = 0x101;
int y = 0x100;
int result;
result = ROUND_UP(x, y);
if (result != 0x200)
{
error("ERROR: ROUND_UP failed: %d != 0x200", result);
inf_loop;
}
result = ROUND_DOWN(x, y);
if (result != 0x100)
{
error("ERROR: ROUND_DOWN failed: %d != 0x100", result);
inf_loop;
}
}
{
constexpr int x = 5;
constexpr int y = 10;
constexpr int max_result = MAX(x, y);
constexpr int min_result = MIN(x, y);
static_assert(max_result == 10);
static_assert(min_result == 5);
}
}
#endif // DEBUG