code: def testCompareAndSwap(self):
      typemap = MPI._typedict
      group = self.WIN.Get_group()
      size = group.Get_size()
      rank = group.Get_rank()
      group.Free()
      self.WIN.Fence()
      obuf = MPI.Alloc_mem(1)
      memzero(obuf)
      cbuf = MPI.Alloc_mem(1)
      memzero(cbuf)
      rbuf = MPI.Alloc_mem(1)
      memzero(rbuf)
      try:
          try:
              self.WIN.Compare_and_swap(
                  [obuf, 1, MPI.BYTE],
                  [cbuf, 1, MPI.BYTE],
                  [rbuf, 1, MPI.BYTE],
                  rank,
                  0,
              )
              self.WIN.Fence()
          finally:
              MPI.Free_mem(obuf)
              MPI.Free_mem(cbuf)
              MPI.Free_mem(rbuf)
      except NotImplementedError:
          self.skipTest("mpi-win-compare_and_swap")
      self.WIN.Fence()
      for array, typecode in arrayimpl.loop():
          with arrayimpl.test(self):
              if unittest.is_mpi_gpu("openmpi", array):
                  continue
              if unittest.is_mpi_gpu("mvapich2", array):
                  continue
              if typecode in "fdg":
                  continue
              if typecode in "FDG":
                  continue
              obuf = array(+1, typecode)
              cbuf = array(0, typecode)
              rbuf = array(-1, typecode, 2)
              datatype = typemap[typecode]
              for rank in range(size):
                  for disp in range(3):
                      with self.subTest(disp=disp, rank=rank):
                          with win_lock(self.WIN, rank):
                              self.WIN.Compare_and_swap(
                                  obuf.as_mpi(),
                                  cbuf.as_mpi(),
                                  rbuf.as_mpi_c(1),
                                  rank,
                                  disp * datatype.size,
                              )
                          self.assertEqual(rbuf[1], scalar(-1))
      big = bytearray(MPI.INT.Get_size())
      buf1 = bytearray(1)
      buf2 = bytearray(1)
      buf3 = bytearray(1)
      with win_lock(self.WIN, rank):
          self.WIN.Compare_and_swap(buf1, buf2, buf3, rank)
      with self.assertRaises(ValueError):
          with win_lock(self.WIN, rank):
              self.WIN.Compare_and_swap(big, buf2, buf3, rank)
      with self.assertRaises(ValueError):
          with win_lock(self.WIN, rank):
              self.WIN.Compare_and_swap(buf1, big, buf3, rank)
      with self.assertRaises(ValueError):
          with win_lock(self.WIN, rank):
              self.WIN.Compare_and_swap(buf1, buf2, big, rank)
      with self.assertRaises(ValueError):
          with win_lock(self.WIN, rank):
              self.WIN.Compare_and_swap(
                  buf1, [big, MPI.INT], buf3, rank
              )
      with self.assertRaises(ValueError):
          with win_lock(self.WIN, rank):
              self.WIN.Compare_and_swap(
                  buf1, buf2, [big, MPI.INT], rank
              )
  
imports: from mpi4py import MPI
  import mpiunittest
  import contextlib
  import arrayimpl
  import sys
label_desc: Use image node_id 7 for calling the BaseTestRMA obj's underlying member method code with example usage: obj.testCompareAndSwap() without return types