Skip to content

Commit

Permalink
Fix race condition in tests
Browse files Browse the repository at this point in the history
Fix race condition in tests and minor changes
  • Loading branch information
mrogowski authored Apr 11, 2023
1 parent 4ffe723 commit 903a743
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
uses: actions/checkout@v3
- uses: jpribyl/[email protected]
with:
key: ${{ matrix.shmem }}-2-{hash}
key: ${{ matrix.shmem }}-3-{hash}
restore-keys: |
${{ matrix.shmem }}-2-
${{ matrix.shmem }}-3-
- name: Build Docker container
run: docker build -t local docker/${{ matrix.shmem }}/
- name: run shmem4py test-1
Expand Down
2 changes: 1 addition & 1 deletion test/test_buf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def testGetBuffer(self):
self.assertTrue(isinstance(cdata, shmem.ffi.CData))
self.assertEqual(csize, 4)
self.assertEqual(ctype, 'double')

def testReadOnly(self):
a = np.zeros(1)
a.flags.writeable = False
Expand Down
18 changes: 12 additions & 6 deletions test/test_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ def testPtrMemory(self):
for t in types:
sym = shmem.new_array(1, t)
sym[0] = npes
shmem.barrier_all()
shmem.sync_all()

nloc = shmem.ptr(sym, nxpe)
if nloc is not None:
self.assertTrue(isinstance(nloc, np.ndarray))
self.assertEqual(nloc.dtype, sym.dtype)
self.assertEqual(nloc[0], npes)
nloc[0] = nxpe
shmem.barrier_all()
shmem.sync_all()
self.assertEqual(sym[0], mype)

shmem.sync_all()

ploc = shmem.ptr(sym, pvpe)
if ploc is not None:
self.assertTrue(isinstance(ploc, np.ndarray))
self.assertEqual(ploc.dtype, sym.dtype)
self.assertEqual(ploc[0], pvpe)
ploc[0] = mype
shmem.barrier_all()
shmem.sync_all()
self.assertEqual(sym[0], nxpe)

shmem.free(sym)
Expand All @@ -54,7 +56,7 @@ def testPtrArray(self):
for d in (0, 1, 2, 3):
for order in ('C', 'F'):
sym = shmem.full((3,)*d, npes, dtype=t, order=order)
shmem.barrier_all()

loc = shmem.ptr(sym, nxpe)
if loc is not None:
self.assertTrue(isinstance(loc, np.ndarray))
Expand All @@ -63,8 +65,11 @@ def testPtrArray(self):
self.assertEqual(loc.strides, sym.strides)
self.assertTrue(np.all(loc == npes))
loc[...] = nxpe
shmem.barrier_all()
shmem.sync_all()
self.assertTrue(np.all(sym == mype))

shmem.sync_all()

loc = shmem.ptr(sym, pvpe)
if loc is not None:
self.assertTrue(isinstance(loc, np.ndarray))
Expand All @@ -73,8 +78,9 @@ def testPtrArray(self):
self.assertEqual(loc.strides, sym.strides)
self.assertTrue(np.all(loc == pvpe))
loc[...] = mype
shmem.barrier_all()
shmem.sync_all()
self.assertTrue(np.all(sym == nxpe))

shmem.free(sym)


Expand Down
6 changes: 3 additions & 3 deletions test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def testQueryThread(self):
)
)

def testPEAccesible(self):
def testPEAccessible(self):
flag = shmem.pe_accessible(shmem.my_pe())
self.assertTrue(flag)

def testAddrAccesibleCData(self):
def testAddrAccessibleCData(self):
addr = shmem.new_array(1, 'i')
flag = shmem.addr_accessible(addr, shmem.my_pe())
shmem.free(addr)
self.assertTrue(flag)

def testAddrAccesibleNumPy(self):
def testAddrAccessibleNumPy(self):
addr = shmem.empty(1, dtype='i')
flag = shmem.addr_accessible(addr, shmem.my_pe())
shmem.free(addr)
Expand Down

0 comments on commit 903a743

Please sign in to comment.