This commit is contained in:
Chris Jones 2010-11-05 02:17:07 -05:00
Родитель b0b35f730f
Коммит 9286b149fe
6 изменённых файлов: 92 добавлений и 12 удалений

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

@ -3,10 +3,10 @@ namespace _ipdltest {
protocol PTestShmem {
child:
Give(Shmem mem, size_t expectedSize);
Give(Shmem mem, Shmem unsafe, size_t expectedSize);
parent:
Take(Shmem mem, size_t expectedSize);
Take(Shmem mem, Shmem unsafe, size_t expectedSize);
__delete__();

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

@ -3,10 +3,10 @@ namespace _ipdltest {
protocol PTestSysVShmem {
child:
Give(Shmem mem, size_t expectedSize);
Give(Shmem mem, Shmem unsafe, size_t expectedSize);
parent:
Take(Shmem mem, size_t expectedSize);
Take(Shmem mem, Shmem unsafe, size_t expectedSize);
__delete__();

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

@ -13,17 +13,29 @@ void
TestShmemParent::Main()
{
Shmem mem;
Shmem unsafe;
size_t size = 12345;
if (!AllocShmem(size, SharedMemory::TYPE_BASIC, &mem))
fail("can't alloc shmem");
if (!AllocUnsafeShmem(size, SharedMemory::TYPE_BASIC, &unsafe))
fail("can't alloc shmem");
if (mem.Size<char>() != size)
fail("shmem is wrong size: expected %lu, got %lu",
size, mem.Size<char>());
if (unsafe.Size<char>() != size)
fail("shmem is wrong size: expected %lu, got %lu",
size, unsafe.Size<char>());
char* ptr = mem.get<char>();
memcpy(ptr, "Hello!", sizeof("Hello!"));
if (!SendGive(mem, size))
char* unsafeptr = unsafe.get<char>();
memcpy(unsafeptr, "Hello!", sizeof("Hello!"));
Shmem unsafecopy = unsafe;
if (!SendGive(mem, unsafe, size))
fail("can't send Give()");
// uncomment the following line for a (nondeterministic) surprise!
@ -31,21 +43,33 @@ TestShmemParent::Main()
// uncomment the following line for a deterministic surprise!
//char c2 = *mem.get<char>(); (void)c2;
// unsafe shmem gets rid of those checks
char uc1 = *unsafeptr; (void)uc1;
char uc2 = *unsafecopy.get<char>(); (void)uc2;
}
bool
TestShmemParent::RecvTake(Shmem& mem, const size_t& expectedSize)
TestShmemParent::RecvTake(Shmem& mem, Shmem& unsafe,
const size_t& expectedSize)
{
if (mem.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, mem.Size<char>());
if (unsafe.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, unsafe.Size<char>());
if (strcmp(mem.get<char>(), "And yourself!"))
fail("expected message was not written");
if (strcmp(unsafe.get<char>(), "And yourself!"))
fail("expected message was not written");
if (!DeallocShmem(mem))
fail("DeallocShmem");
if (!DeallocShmem(unsafe))
fail("DeallocShmem");
Close();
@ -56,20 +80,33 @@ TestShmemParent::RecvTake(Shmem& mem, const size_t& expectedSize)
// Child
bool
TestShmemChild::RecvGive(Shmem& mem, const size_t& expectedSize)
TestShmemChild::RecvGive(Shmem& mem, Shmem& unsafe, const size_t& expectedSize)
{
if (mem.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, mem.Size<char>());
if (unsafe.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, unsafe.Size<char>());
if (strcmp(mem.get<char>(), "Hello!"))
fail("expected message was not written");
if (strcmp(unsafe.get<char>(), "Hello!"))
fail("expected message was not written");
char* unsafeptr = unsafe.get<char>();
memcpy(mem.get<char>(), "And yourself!", sizeof("And yourself!"));
memcpy(unsafeptr, "And yourself!", sizeof("And yourself!"));
if (!SendTake(mem, expectedSize))
Shmem unsafecopy = unsafe;
if (!SendTake(mem, unsafe, expectedSize))
fail("can't send Take()");
// these checks also shouldn't fail in the child
char uc1 = *unsafeptr; (void)uc1;
char uc2 = *unsafecopy.get<char>(); (void)uc2;
return true;
}

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

@ -23,6 +23,7 @@ protected:
NS_OVERRIDE
virtual bool RecvTake(
Shmem& mem,
Shmem& unsafe,
const size_t& expectedSize);
NS_OVERRIDE
@ -47,6 +48,7 @@ protected:
NS_OVERRIDE
virtual bool RecvGive(
Shmem& mem,
Shmem& unsafe,
const size_t& expectedSize);
NS_OVERRIDE

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

@ -13,20 +13,34 @@ void
TestSysVShmemParent::Main()
{
Shmem mem;
Shmem unsafe;
size_t size = 12345;
if (!AllocShmem(size, SharedMemory::TYPE_SYSV, &mem))
fail("can't alloc shmem");
if (!AllocUnsafeShmem(size, SharedMemory::TYPE_SYSV, &unsafe))
fail("can't alloc shmem");
if (0 > mem.GetSysVID())
fail("invalid shmem ID");
if (0 > unsafe.GetSysVID())
fail("invalid shmem ID");
if (mem.Size<char>() != size)
fail("shmem is wrong size: expected %lu, got %lu",
size, mem.Size<char>());
if (unsafe.Size<char>() != size)
fail("shmem is wrong size: expected %lu, got %lu",
size, unsafe.Size<char>());
char* ptr = mem.get<char>();
memcpy(ptr, "Hello!", sizeof("Hello!"));
if (!SendGive(mem, size))
char* unsafeptr = unsafe.get<char>();
memcpy(unsafeptr, "Hello!", sizeof("Hello!"));
Shmem unsafecopy = unsafe;
if (!SendGive(mem, unsafe, size))
fail("can't send Give()");
// uncomment the following line for a (nondeterministic) surprise!
@ -34,21 +48,33 @@ TestSysVShmemParent::Main()
// uncomment the following line for a deterministic surprise!
//char c2 = *mem.get<char>(); (void)c2;
// unsafe shmem gets rid of those checks
char uc1 = *unsafeptr; (void)uc1;
char uc2 = *unsafecopy.get<char>(); (void)uc2;
}
bool
TestSysVShmemParent::RecvTake(Shmem& mem, const size_t& expectedSize)
TestSysVShmemParent::RecvTake(Shmem& mem, Shmem& unsafe,
const size_t& expectedSize)
{
if (mem.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, mem.Size<char>());
if (unsafe.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, unsafe.Size<char>());
if (strcmp(mem.get<char>(), "And yourself!"))
fail("expected message was not written");
if (strcmp(unsafe.get<char>(), "And yourself!"))
fail("expected message was not written");
if (!DeallocShmem(mem))
fail("DeallocShmem");
if (!DeallocShmem(unsafe))
fail("DeallocShmem");
Close();
@ -59,20 +85,33 @@ TestSysVShmemParent::RecvTake(Shmem& mem, const size_t& expectedSize)
// Child
bool
TestSysVShmemChild::RecvGive(Shmem& mem, const size_t& expectedSize)
TestSysVShmemChild::RecvGive(Shmem& mem, Shmem& unsafe, const size_t& expectedSize)
{
if (mem.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, mem.Size<char>());
if (unsafe.Size<char>() != expectedSize)
fail("expected shmem size %lu, but it has size %lu",
expectedSize, unsafe.Size<char>());
if (strcmp(mem.get<char>(), "Hello!"))
fail("expected message was not written");
if (strcmp(unsafe.get<char>(), "Hello!"))
fail("expected message was not written");
char* unsafeptr = unsafe.get<char>();
memcpy(mem.get<char>(), "And yourself!", sizeof("And yourself!"));
memcpy(unsafeptr, "And yourself!", sizeof("And yourself!"));
if (!SendTake(mem, expectedSize))
Shmem unsafecopy = unsafe;
if (!SendTake(mem, unsafe, expectedSize))
fail("can't send Take()");
// these checks also shouldn't fail in the child
char uc1 = *unsafeptr; (void)uc1;
char uc2 = *unsafecopy.get<char>(); (void)uc2;
return true;
}

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

@ -23,6 +23,7 @@ protected:
NS_OVERRIDE
virtual bool RecvTake(
Shmem& mem,
Shmem& unsafe,
const size_t& expectedSize);
NS_OVERRIDE
@ -47,6 +48,7 @@ protected:
NS_OVERRIDE
virtual bool RecvGive(
Shmem& mem,
Shmem& unsafe,
const size_t& expectedSize);
NS_OVERRIDE