github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/device_allocator_test.go (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package query 16 17 import ( 18 "github.com/onsi/ginkgo" 19 . "github.com/onsi/gomega" 20 ) 21 22 var _ = ginkgo.Describe("Device Allocator", func() { 23 24 ginkgo.It("deviceAllocate and deviceFree should work", func() { 25 deviceAllocator := getDeviceAllocator() 26 dp := deviceAllocator.deviceAllocate(12, 0) 27 Ω(dp.bytes).Should(BeEquivalentTo(12)) 28 Ω(dp.device).Should(BeEquivalentTo(0)) 29 Ω(dp.allocated).Should(BeTrue()) 30 Ω(deviceAllocator.getAllocatedMemory(0)).Should(BeEquivalentTo(12)) 31 32 dp2 := deviceAllocator.deviceAllocate(24, 0) 33 Ω(dp2.bytes).Should(BeEquivalentTo(24)) 34 Ω(dp2.device).Should(BeEquivalentTo(0)) 35 Ω(dp2.allocated).Should(BeTrue()) 36 Ω(deviceAllocator.getAllocatedMemory(0)).Should(BeEquivalentTo(36)) 37 38 deviceAllocator.deviceFree(dp) 39 Ω(deviceAllocator.getAllocatedMemory(0)).Should(BeEquivalentTo(24)) 40 41 deviceAllocator.deviceFree(dp2) 42 Ω(deviceAllocator.getAllocatedMemory(0)).Should(BeEquivalentTo(0)) 43 }) 44 45 ginkgo.It("deviceFreeAndSetNil should work", func() { 46 dp := deviceAllocate(12, 0) 47 Ω(dp.bytes).Should(BeEquivalentTo(12)) 48 Ω(dp.device).Should(BeEquivalentTo(0)) 49 Ω(dp.allocated).Should(BeTrue()) 50 da := getDeviceAllocator() 51 Ω(da.getAllocatedMemory(0)).Should(BeNumerically(">", 0)) 52 53 deviceFreeAndSetNil(&dp) 54 Ω(da.getAllocatedMemory(0)).Should(BeEquivalentTo(0)) 55 }) 56 57 ginkgo.It("reportAllocatedMemory should work", func() { 58 dp := deviceAllocate(12, 0) 59 da := getDeviceAllocator() 60 Ω(da.getAllocatedMemory(0)).Should(BeNumerically(">", 0)) 61 Ω(func() { reportAllocatedMemory(0, da) }).ShouldNot(Panic()) 62 da.deviceFree(dp) 63 }) 64 })