This commit is contained in:
Chris Jones 2010-04-16 00:29:17 -05:00
Родитель 0bd95dade4
Коммит e81c79ae2f
5 изменённых файлов: 167 добавлений и 0 удалений

Просмотреть файл

@ -78,6 +78,10 @@ IPDLTESTS = \
TestSyncWakeup \
$(NULL)
ifeq ($(OS_ARCH),Linux)
IPDLTESTS += TestSysVShmem
endif
IPDLTESTSRCS = $(addsuffix .cpp,$(IPDLTESTS))
IPDLTESTHDRS = $(addprefix $(srcdir)/,$(addsuffix .h,$(IPDLTESTS)))

Просмотреть файл

@ -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__;
};
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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)