aboutsummaryrefslogtreecommitdiff
path: root/weed/util/mem/slot_pool_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/util/mem/slot_pool_test.go')
-rw-r--r--weed/util/mem/slot_pool_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/weed/util/mem/slot_pool_test.go b/weed/util/mem/slot_pool_test.go
new file mode 100644
index 000000000..114951522
--- /dev/null
+++ b/weed/util/mem/slot_pool_test.go
@@ -0,0 +1,37 @@
+package mem
+
+import (
+ "testing"
+)
+
+func TestAllocateFree(t *testing.T) {
+ buf := Allocate(12)
+ Free(buf)
+ if cap(buf) != min_size {
+ t.Errorf("min size error allocated capacity=%d", cap(buf))
+ }
+ if len(buf) != 12 {
+ t.Errorf("size error")
+ }
+
+ buf = Allocate(4883)
+ Free(buf)
+ if cap(buf) != 1024<<bitCount(4883) {
+ t.Errorf("min size error allocated capacity=%d", cap(buf))
+ }
+ if len(buf) != 4883 {
+ t.Errorf("size error")
+ }
+
+}
+
+func TestBitCount(t *testing.T) {
+ count := bitCount(12)
+ if count != 0 {
+ t.Errorf("bitCount error count=%d", count)
+ }
+ if count != bitCount(min_size) {
+ t.Errorf("bitCount error count=%d", count)
+ }
+
+}