mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 548437: Test SysV shmem.
This commit is contained in:
parent
0bd95dade4
commit
e81c79ae2f
@ -78,6 +78,10 @@ IPDLTESTS = \
|
||||
TestSyncWakeup \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
IPDLTESTS += TestSysVShmem
|
||||
endif
|
||||
|
||||
IPDLTESTSRCS = $(addsuffix .cpp,$(IPDLTESTS))
|
||||
IPDLTESTHDRS = $(addprefix $(srcdir)/,$(addsuffix .h,$(IPDLTESTS)))
|
||||
|
||||
|
22
ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
Normal file
22
ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
Normal file
@ -0,0 +1,22 @@
|
||||
namespace mozilla {
|
||||
namespace _ipdltest {
|
||||
|
||||
protocol PTestSysVShmem {
|
||||
child:
|
||||
Give(Shmem mem, size_t expectedSize);
|
||||
|
||||
parent:
|
||||
Take(Shmem mem, size_t expectedSize);
|
||||
__delete__();
|
||||
|
||||
|
||||
state GIVING:
|
||||
send Give goto TAKING;
|
||||
|
||||
state TAKING:
|
||||
recv Take goto TAKING;
|
||||
recv __delete__;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
75
ipc/ipdl/test/cxx/TestSysVShmem.cpp
Normal file
75
ipc/ipdl/test/cxx/TestSysVShmem.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include "TestSysVShmem.h"
|
||||
|
||||
#include "IPDLUnitTests.h" // fail etc.
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace _ipdltest {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parent
|
||||
|
||||
void
|
||||
TestSysVShmemParent::Main()
|
||||
{
|
||||
Shmem mem;
|
||||
size_t size = 12345;
|
||||
if (!AllocShmem(size, SharedMemory::TYPE_SYSV, &mem))
|
||||
fail("can't alloc shmem");
|
||||
|
||||
if (mem.Size<char>() != size)
|
||||
fail("shmem is wrong size: expected %lu, got %lu",
|
||||
size, mem.Size<char>());
|
||||
|
||||
char* ptr = mem.get<char>();
|
||||
memcpy(ptr, "Hello!", sizeof("Hello!"));
|
||||
if (!SendGive(mem, size))
|
||||
fail("can't send Give()");
|
||||
|
||||
// uncomment the following line for a (nondeterministic) surprise!
|
||||
//char c1 = *ptr; (void)c1;
|
||||
|
||||
// uncomment the following line for a deterministic surprise!
|
||||
//char c2 = *mem.get<char>(); (void)c2;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TestSysVShmemParent::RecvTake(Shmem& mem, const size_t& expectedSize)
|
||||
{
|
||||
if (mem.Size<char>() != expectedSize)
|
||||
fail("expected shmem size %lu, but it has size %lu",
|
||||
expectedSize, mem.Size<char>());
|
||||
|
||||
if (strcmp(mem.get<char>(), "And yourself!"))
|
||||
fail("expected message was not written");
|
||||
|
||||
Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Child
|
||||
|
||||
bool
|
||||
TestSysVShmemChild::RecvGive(Shmem& mem, const size_t& expectedSize)
|
||||
{
|
||||
if (mem.Size<char>() != expectedSize)
|
||||
fail("expected shmem size %lu, but it has size %lu",
|
||||
expectedSize, mem.Size<char>());
|
||||
|
||||
if (strcmp(mem.get<char>(), "Hello!"))
|
||||
fail("expected message was not written");
|
||||
|
||||
memcpy(mem.get<char>(), "And yourself!", sizeof("And yourself!"));
|
||||
|
||||
if (!SendTake(mem, expectedSize))
|
||||
fail("can't send Take()");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace _ipdltest
|
||||
} // namespace mozilla
|
65
ipc/ipdl/test/cxx/TestSysVShmem.h
Normal file
65
ipc/ipdl/test/cxx/TestSysVShmem.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef mozilla__ipdltest_TestSysVShmem_h
|
||||
#define mozilla__ipdltest_TestSysVShmem_h
|
||||
|
||||
#include "mozilla/_ipdltest/IPDLUnitTests.h"
|
||||
|
||||
#include "mozilla/_ipdltest/PTestSysVShmemParent.h"
|
||||
#include "mozilla/_ipdltest/PTestSysVShmemChild.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace _ipdltest {
|
||||
|
||||
|
||||
class TestSysVShmemParent :
|
||||
public PTestSysVShmemParent
|
||||
{
|
||||
public:
|
||||
TestSysVShmemParent() { }
|
||||
virtual ~TestSysVShmemParent() { }
|
||||
|
||||
void Main();
|
||||
|
||||
protected:
|
||||
NS_OVERRIDE
|
||||
virtual bool RecvTake(
|
||||
Shmem& mem,
|
||||
const size_t& expectedSize);
|
||||
|
||||
NS_OVERRIDE
|
||||
virtual void ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
if (NormalShutdown != why)
|
||||
fail("unexpected destruction!");
|
||||
passed("ok");
|
||||
QuitParent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TestSysVShmemChild :
|
||||
public PTestSysVShmemChild
|
||||
{
|
||||
public:
|
||||
TestSysVShmemChild() { }
|
||||
virtual ~TestSysVShmemChild() { }
|
||||
|
||||
protected:
|
||||
NS_OVERRIDE
|
||||
virtual bool RecvGive(
|
||||
Shmem& mem,
|
||||
const size_t& expectedSize);
|
||||
|
||||
NS_OVERRIDE
|
||||
virtual void ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
if (NormalShutdown != why)
|
||||
fail("unexpected destruction!");
|
||||
QuitChild();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace _ipdltest
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // ifndef mozilla__ipdltest_TestSysVShmem_h
|
@ -26,4 +26,5 @@ IPDLSRCS = \
|
||||
PTestShutdownSubsub.ipdl \
|
||||
PTestStackHooks.ipdl \
|
||||
PTestSyncWakeup.ipdl \
|
||||
PTestSysVShmem.ipdl \
|
||||
$(NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user