File: test_ctypes.py

package info (click to toggle)
mpi4py 2.0.0-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,680 kB
  • sloc: python: 15,291; ansic: 7,099; makefile: 719; f90: 158; sh: 156; cpp: 121
file content (59 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from mpi4py import MPI
import mpiunittest as unittest
try:
    import ctypes
except ImportError:
    ctypes = None

class TestCTYPES(unittest.TestCase):

    objects = [
        MPI.DATATYPE_NULL,
        MPI.INT,
        MPI.DOUBLE,
        MPI.REQUEST_NULL,
        MPI.INFO_NULL,
        MPI.INFO_ENV,
        MPI.ERRHANDLER_NULL,
        MPI.ERRORS_RETURN,
        MPI.ERRORS_ARE_FATAL,
        MPI.GROUP_NULL,
        MPI.GROUP_EMPTY,
        MPI.WIN_NULL,
        MPI.OP_NULL,
        MPI.SUM,
        MPI.MIN,
        MPI.MAX,
        MPI.FILE_NULL,
        MPI.MESSAGE_NULL,
        MPI.MESSAGE_NO_PROC,
        MPI.COMM_NULL,
        MPI.COMM_SELF,
        MPI.COMM_WORLD,
    ]

    def testHandleAdress(self):
        typemap = {ctypes.sizeof(ctypes.c_int): ctypes.c_int,
                   ctypes.sizeof(ctypes.c_void_p): ctypes.c_void_p}
        for obj in self.objects:
            handle_t = typemap[MPI._sizeof(obj)]
            oldobj = obj
            newobj = type(obj)()
            handle_old = handle_t.from_address(MPI._addressof(oldobj))
            handle_new = handle_t.from_address(MPI._addressof(newobj))
            handle_new.value = handle_old.value
            self.assertEqual(obj, newobj)

    def testHandleValue(self):
        typemap = {ctypes.sizeof(ctypes.c_uint32): ctypes.c_uint32,
                   ctypes.sizeof(ctypes.c_uint64): ctypes.c_uint64}
        for obj in self.objects:
            uintptr_t = typemap[MPI._sizeof(obj)]
            handle = uintptr_t.from_address(MPI._addressof(obj))
            self.assertEqual(handle.value, MPI._handleof(obj))

if ctypes is None:
    del TestCTYPES

if __name__ == '__main__':
    unittest.main()