Commit 3d7c5cf64a

Andrew Kelley <andrew@ziglang.org>
2025-02-06 23:14:12
std.heap: test smp_allocator
1 parent 51c4ffa
Changed files (2)
lib/std/heap/SmpAllocator.zig
@@ -241,48 +241,3 @@ fn slotSize(class: usize) usize {
     const Log2USize = std.math.Log2Int(usize);
     return @as(usize, 1) << @as(Log2USize, @intCast(class));
 }
-
-test "large alloc, resize, remap, free" {
-    const gpa = std.heap.smp_allocator;
-
-    const ptr1 = try gpa.alloc(u64, 42768);
-    const ptr2 = try gpa.alloc(u64, 52768);
-    gpa.free(ptr1);
-    const ptr3 = try gpa.alloc(u64, 62768);
-    gpa.free(ptr3);
-    gpa.free(ptr2);
-}
-
-test "small allocations - free in same order" {
-    const gpa = std.heap.smp_allocator;
-
-    var list = std.ArrayList(*u64).init(std.testing.allocator);
-    defer list.deinit();
-
-    var i: usize = 0;
-    while (i < 513) : (i += 1) {
-        const ptr = try gpa.create(u64);
-        try list.append(ptr);
-    }
-
-    for (list.items) |ptr| {
-        gpa.destroy(ptr);
-    }
-}
-
-test "small allocations - free in reverse order" {
-    const gpa = std.heap.smp_allocator;
-
-    var list = std.ArrayList(*u64).init(std.testing.allocator);
-    defer list.deinit();
-
-    var i: usize = 0;
-    while (i < 513) : (i += 1) {
-        const ptr = try gpa.create(u64);
-        try list.append(ptr);
-    }
-
-    while (list.popOrNull()) |ptr| {
-        gpa.destroy(ptr);
-    }
-}
lib/std/heap.zig
@@ -481,7 +481,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
     };
 }
 
-test "c_allocator" {
+test c_allocator {
     if (builtin.link_libc) {
         try testAllocator(c_allocator);
         try testAllocatorAligned(c_allocator);
@@ -490,12 +490,19 @@ test "c_allocator" {
     }
 }
 
-test "raw_c_allocator" {
+test raw_c_allocator {
     if (builtin.link_libc) {
         try testAllocator(raw_c_allocator);
     }
 }
 
+test smp_allocator {
+    try testAllocator(smp_allocator);
+    try testAllocatorAligned(smp_allocator);
+    try testAllocatorLargeAlignment(smp_allocator);
+    try testAllocatorAlignedShrink(smp_allocator);
+}
+
 test PageAllocator {
     const allocator = page_allocator;
     try testAllocator(allocator);