Tests for bug 598866.
authorChris Jones <jones.chris.g@gmail.com>
Fri, 05 Nov 2010 02:17:07 -0500
changeset 56897 8f3eecda38b21e258aeed4928469194c7168bf44
parent 56896 8cd0af801cb97026ee3a5403e204a2fa6fbe5275
child 56898 dc526c0277432c0f597fd56273aad35290d771c6
push id16725
push usercjones@mozilla.com
push dateFri, 05 Nov 2010 07:21:46 +0000
treeherdermozilla-central@0aa98eae87ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs598866
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Tests for bug 598866.
ipc/ipdl/test/cxx/PTestShmem.ipdl
ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
ipc/ipdl/test/cxx/TestShmem.cpp
ipc/ipdl/test/cxx/TestShmem.h
ipc/ipdl/test/cxx/TestSysVShmem.cpp
ipc/ipdl/test/cxx/TestSysVShmem.h
--- a/ipc/ipdl/test/cxx/PTestShmem.ipdl
+++ b/ipc/ipdl/test/cxx/PTestShmem.ipdl
@@ -1,17 +1,17 @@
 namespace mozilla {
 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__();
 
 
 state GIVING:
     send Give goto TAKING;
 
 state TAKING:
     recv Take goto TAKING;
--- a/ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
+++ b/ipc/ipdl/test/cxx/PTestSysVShmem.ipdl
@@ -1,17 +1,17 @@
 namespace mozilla {
 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__();
 
 
 state GIVING:
     send Give goto TAKING;
 
 state TAKING:
     recv Take goto TAKING;
--- a/ipc/ipdl/test/cxx/TestShmem.cpp
+++ b/ipc/ipdl/test/cxx/TestShmem.cpp
@@ -8,71 +8,108 @@ namespace _ipdltest {
 
 //-----------------------------------------------------------------------------
 // Parent
 
 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!
     //char c1 = *ptr;  (void)c1;
 
     // 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();
 
     return true;
 }
 
 //-----------------------------------------------------------------------------
 // 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;
 }
 
 
 } // namespace _ipdltest
 } // namespace mozilla
--- a/ipc/ipdl/test/cxx/TestShmem.h
+++ b/ipc/ipdl/test/cxx/TestShmem.h
@@ -18,16 +18,17 @@ public:
     virtual ~TestShmemParent() { }
 
     void Main();
 
 protected:
     NS_OVERRIDE
     virtual bool RecvTake(
             Shmem& mem,
+            Shmem& unsafe,
             const size_t& expectedSize);
 
     NS_OVERRIDE
     virtual void ActorDestroy(ActorDestroyReason why)
     {
         if (NormalShutdown != why)
             fail("unexpected destruction!");  
         passed("ok");
@@ -42,16 +43,17 @@ class TestShmemChild :
 public:
     TestShmemChild() { }
     virtual ~TestShmemChild() { }
 
 protected:
     NS_OVERRIDE
     virtual bool RecvGive(
             Shmem& mem,
+            Shmem& unsafe,
             const size_t& expectedSize);
 
     NS_OVERRIDE
     virtual void ActorDestroy(ActorDestroyReason why)
     {
         if (NormalShutdown != why)
             fail("unexpected destruction!");
         QuitChild();
--- a/ipc/ipdl/test/cxx/TestSysVShmem.cpp
+++ b/ipc/ipdl/test/cxx/TestSysVShmem.cpp
@@ -8,74 +8,113 @@ namespace _ipdltest {
 
 //-----------------------------------------------------------------------------
 // Parent
 
 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!
     //char c1 = *ptr;  (void)c1;
 
     // 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();
 
     return true;
 }
 
 //-----------------------------------------------------------------------------
 // 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;
 }
 
 
 } // namespace _ipdltest
 } // namespace mozilla
--- a/ipc/ipdl/test/cxx/TestSysVShmem.h
+++ b/ipc/ipdl/test/cxx/TestSysVShmem.h
@@ -18,16 +18,17 @@ public:
     virtual ~TestSysVShmemParent() { }
 
     void Main();
 
 protected:
     NS_OVERRIDE
     virtual bool RecvTake(
             Shmem& mem,
+            Shmem& unsafe,
             const size_t& expectedSize);
 
     NS_OVERRIDE
     virtual void ActorDestroy(ActorDestroyReason why)
     {
         if (NormalShutdown != why)
             fail("unexpected destruction!");  
         passed("ok");
@@ -42,16 +43,17 @@ class TestSysVShmemChild :
 public:
     TestSysVShmemChild() { }
     virtual ~TestSysVShmemChild() { }
 
 protected:
     NS_OVERRIDE
     virtual bool RecvGive(
             Shmem& mem,
+            Shmem& unsafe,
             const size_t& expectedSize);
 
     NS_OVERRIDE
     virtual void ActorDestroy(ActorDestroyReason why)
     {
         if (NormalShutdown != why)
             fail("unexpected destruction!");
         QuitChild();