|
8 | 8 | // (0.17.1) a joined command line is refused where programs receive vectors; |
9 | 9 | // (0.18) a file is mapped, the region holds its bytes and zero after its end; |
10 | 10 | // (0.19) the cores are no more than the processors, and a started context |
11 | | -// lowers its claim on the processors where the implementation claims it. |
| 11 | +// lowers its claim on the processors where the implementation claims it; |
| 12 | +// (0.20) a transfer at an offset neither uses nor moves the file's position, |
| 13 | +// this program is told the memory it occupies and its peak, and a region is |
| 14 | +// reserved, backed, written, its backing returned and backed again reading |
| 15 | +// zero, and released. |
12 | 16 | // The terminal is not observed here, |
13 | 17 | // because a test run has none; the implementations observe it on a terminal |
14 | 18 | // they make. |
15 | 19 | #include <openkal/env.h> |
16 | 20 | #include <openkal/fs.h> |
17 | 21 | #include <openkal/map.h> |
| 22 | +#include <openkal/memory.h> |
18 | 23 | #include <openkal/process.h> |
| 24 | +#include <openkal/region.h> |
19 | 25 | #include <openkal/stream.h> |
20 | 26 | #include <openkal/task.h> |
21 | 27 | #include <openkal/version.h> |
@@ -138,6 +144,49 @@ int main() { |
138 | 144 | } |
139 | 145 | } |
140 | 146 |
|
| 147 | + if (kal_fs_preopen_count() > 0 && kal_fs_preopen(0, &root, nullptr, 0, nullptr) == kal_ok) { |
| 148 | + kal_file f{}; |
| 149 | + if (kal_fs_open(root, "okt.p", 5, KAL_OPEN_READ | KAL_OPEN_WRITE | KAL_OPEN_CREATE | KAL_OPEN_TRUNCATE, &f) == kal_ok) { |
| 150 | + kal_stream_write(kal_fs_stream(f), "abcdef", 6); |
| 151 | + check(kal_fs_write_at(f, "XY", 2, 1) == 2, "a write at an offset writes the whole buffer"); |
| 152 | + kal_u64 at = 0; |
| 153 | + check(kal_fs_seek(f, 0, KAL_SEEK_CURRENT, &at) == kal_ok && at == 6, |
| 154 | + "and leaves the position where it was"); |
| 155 | + char b[8] = {}; |
| 156 | + check(kal_fs_read_at(f, b, 6, 0) == 6 && b[0] == 'a' && b[1] == 'X' && b[2] == 'Y' && b[5] == 'f', |
| 157 | + "a read at an offset reads what is there"); |
| 158 | + check(kal_fs_read_at(f, b, 6, 6) == 0, "a read at the end reads nothing"); |
| 159 | + kal_fs_close_file(f); |
| 160 | + } |
| 161 | + kal_fs_remove(root, "okt.p", 5); |
| 162 | + } |
| 163 | + |
| 164 | + { |
| 165 | + kal_process me{}; |
| 166 | + if (kal_process_self(&me) == kal_ok) { |
| 167 | + kal_program_info info{}; |
| 168 | + info.self_size = sizeof info; |
| 169 | + if (kal_process_info(me, KAL_PINFO_MEMORY, &info) == kal_ok && (info.present & KAL_PINFO_MEMORY)) |
| 170 | + check(info.memory_bytes > 0 && info.memory_peak_bytes >= info.memory_bytes, |
| 171 | + "this program is told the memory it occupies, and a peak no smaller"); |
| 172 | + kal_process_close(me); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + if (kal_interfaces() & KAL_IFACE_REGION) { |
| 177 | + const kal_uintptr g = kal_memory_granularity(); |
| 178 | + auto* r = static_cast<unsigned char*>(kal_region_reserve(4 * g, g, 0)); |
| 179 | + check(r != nullptr, "a region is reserved"); |
| 180 | + if (r) { |
| 181 | + check(kal_region_commit(r, g) == kal_ok, "a part of it is backed"); |
| 182 | + r[0] = 7; r[g - 1] = 9; |
| 183 | + check(kal_region_decommit(r, g) == kal_ok && kal_region_commit(r, g) == kal_ok, |
| 184 | + "its backing is returned and it is backed again"); |
| 185 | + check(r[0] == 0 && r[g - 1] == 0, "and it reads as zero"); |
| 186 | + kal_region_release(r, 4 * g); |
| 187 | + } |
| 188 | + } |
| 189 | + |
141 | 190 | if (failures == 0) kal_stream_write(kal_stdout(), "openkal: held\n", 14); |
142 | 191 | return failures == 0 ? 0 : 1; |
143 | 192 | } |
0 commit comments