| author | |
| committer | |
| log | 3d7c5cf64a3bbe55dfa943133d1a5a7a34fe388c |
| tree | 5a712e05fa67142922ad9ca5f1368e61d0433857 |
| parent | 51c4ffa410d2cf51b7b45dab4dfd033db2190b7e |
2 files changed, 9 insertions(+), 47 deletions(-)
lib/std/heap.zig+9-2| ... | @@ -481,7 +481,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { | ... | @@ -481,7 +481,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 481 | }; | 481 | }; |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | test "c_allocator" { | 484 | test c_allocator { |
| 485 | if (builtin.link_libc) { | 485 | if (builtin.link_libc) { |
| 486 | try testAllocator(c_allocator); | 486 | try testAllocator(c_allocator); |
| 487 | try testAllocatorAligned(c_allocator); | 487 | try testAllocatorAligned(c_allocator); |
| ... | @@ -490,12 +490,19 @@ test "c_allocator" { | ... | @@ -490,12 +490,19 @@ test "c_allocator" { |
| 490 | } | 490 | } |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | test "raw_c_allocator" { | 493 | test raw_c_allocator { |
| 494 | if (builtin.link_libc) { | 494 | if (builtin.link_libc) { |
| 495 | try testAllocator(raw_c_allocator); | 495 | try testAllocator(raw_c_allocator); |
| 496 | } | 496 | } |
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | test smp_allocator { | ||
| 500 | try testAllocator(smp_allocator); | ||
| 501 | try testAllocatorAligned(smp_allocator); | ||
| 502 | try testAllocatorLargeAlignment(smp_allocator); | ||
| 503 | try testAllocatorAlignedShrink(smp_allocator); | ||
| 504 | } | ||
| 505 | |||
| 499 | test PageAllocator { | 506 | test PageAllocator { |
| 500 | const allocator = page_allocator; | 507 | const allocator = page_allocator; |
| 501 | try testAllocator(allocator); | 508 | try testAllocator(allocator); |
lib/std/heap/SmpAllocator.zig-45| ... | @@ -241,48 +241,3 @@ fn slotSize(class: usize) usize { | ... | @@ -241,48 +241,3 @@ fn slotSize(class: usize) usize { |
| 241 | const Log2USize = std.math.Log2Int(usize); | 241 | const Log2USize = std.math.Log2Int(usize); |
| 242 | return @as(usize, 1) << @as(Log2USize, @intCast(class)); | 242 | return @as(usize, 1) << @as(Log2USize, @intCast(class)); |
| 243 | } | 243 | } |
| 244 | |||
| 245 | test "large alloc, resize, remap, free" { | ||
| 246 | const gpa = std.heap.smp_allocator; | ||
| 247 | |||
| 248 | const ptr1 = try gpa.alloc(u64, 42768); | ||
| 249 | const ptr2 = try gpa.alloc(u64, 52768); | ||
| 250 | gpa.free(ptr1); | ||
| 251 | const ptr3 = try gpa.alloc(u64, 62768); | ||
| 252 | gpa.free(ptr3); | ||
| 253 | gpa.free(ptr2); | ||
| 254 | } | ||
| 255 | |||
| 256 | test "small allocations - free in same order" { | ||
| 257 | const gpa = std.heap.smp_allocator; | ||
| 258 | |||
| 259 | var list = std.ArrayList(*u64).init(std.testing.allocator); | ||
| 260 | defer list.deinit(); | ||
| 261 | |||
| 262 | var i: usize = 0; | ||
| 263 | while (i < 513) : (i += 1) { | ||
| 264 | const ptr = try gpa.create(u64); | ||
| 265 | try list.append(ptr); | ||
| 266 | } | ||
| 267 | |||
| 268 | for (list.items) |ptr| { | ||
| 269 | gpa.destroy(ptr); | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | test "small allocations - free in reverse order" { | ||
| 274 | const gpa = std.heap.smp_allocator; | ||
| 275 | |||
| 276 | var list = std.ArrayList(*u64).init(std.testing.allocator); | ||
| 277 | defer list.deinit(); | ||
| 278 | |||
| 279 | var i: usize = 0; | ||
| 280 | while (i < 513) : (i += 1) { | ||
| 281 | const ptr = try gpa.create(u64); | ||
| 282 | try list.append(ptr); | ||
| 283 | } | ||
| 284 | |||
| 285 | while (list.popOrNull()) |ptr| { | ||
| 286 | gpa.destroy(ptr); | ||
| 287 | } | ||
| 288 | } |