From 52d95f50729b40628ae77d667d262c5235e50cb8 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 7 Aug 2018 11:11:40 -0400 Subject: Propogate error codes from SHM lock creation and open Also add a few more unit tests Signed-off-by: Matthew Heon --- libpod/lock/locks_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'libpod/lock/locks_test.go') diff --git a/libpod/lock/locks_test.go b/libpod/lock/locks_test.go index ce4882643..62a36c5da 100644 --- a/libpod/lock/locks_test.go +++ b/libpod/lock/locks_test.go @@ -80,6 +80,42 @@ func TestCreateNewSHMBadSize(t *testing.T) { assert.Error(t, err) } +// Test that creating an SHM with 0 size fails +func TestCreateNewSHMZeroSize(t *testing.T) { + _, err := CreateSHMLock(0) + assert.Error(t, err) +} + +// Test that deallocating an unallocated lock errors +func TestDeallocateUnallocatedLockErrors(t *testing.T) { + runLockTest(t, func(t *testing.T, locks *SHMLocks) { + err := locks.DeallocateSemaphore(0) + assert.Error(t, err) + }) +} + +// Test that unlocking an unlocked lock fails +func TestUnlockingUnlockedLockFails(t *testing.T) { + runLockTest(t, func(t *testing.T, locks *SHMLocks) { + err := locks.UnlockSemaphore(0) + assert.Error(t, err) + }) +} + +// Test that locking and double-unlocking fails +func TestDoubleUnlockFails(t *testing.T) { + runLockTest(t, func(t *testing.T, locks *SHMLocks) { + err := locks.LockSemaphore(0) + assert.NoError(t, err) + + err = locks.UnlockSemaphore(0) + assert.NoError(t, err) + + err = locks.UnlockSemaphore(0) + assert.Error(t, err) + }) +} + // Test allocating - lock - unlock - deallocate cycle, single lock func TestLockLifecycleSingleLock(t *testing.T) { runLockTest(t, func(t *testing.T, locks *SHMLocks) { -- cgit v1.2.3-54-g00ecf