Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared_mem_test_base.h
Go to the documentation of this file.
1 // Copyright 2011 Google Inc.
16 
17 #ifndef PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_TEST_BASE_H_
18 #define PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_TEST_BASE_H_
19 
20 #include <cstddef>
21 
27 
28 namespace net_instaweb {
29 
30 class Function;
31 class ThreadSystem;
32 
34  public:
35  virtual ~SharedMemTestEnv();
36  SharedMemTestEnv() {}
37 
38  virtual AbstractSharedMem* CreateSharedMemRuntime() = 0;
39 
45  virtual bool CreateChild(Function* callback) = 0;
46 
49  virtual void WaitForChildren() = 0;
50 
52  virtual void ShortSleep() = 0;
53 
55  virtual void ChildFailed() = 0;
56 
57  private:
58 
59 };
60 
61 class SharedMemTestBase : public testing::Test {
62  protected:
63  typedef void (SharedMemTestBase::*TestMethod)();
64 
65  explicit SharedMemTestBase(SharedMemTestEnv* test_env);
66 
67  bool CreateChild(TestMethod method);
68 
70  void TestReadWrite(bool reattach);
71 
73  void TestLarge();
74 
76  void TestDistinct();
77 
79  void TestDestroy();
80 
83  void TestCreateTwice();
84 
86  void TestTwoKids();
87 
89  void TestMutex();
90 
91  private:
92  static const int kLarge = 0x1000 - 4;
93  static const int kNumIncrements = 0xFFFFF;
95 
96  volatile int* IntPtr(AbstractSharedMemSegment* seg, int offset) {
97  return reinterpret_cast<volatile int*>(&seg->Base()[offset]);
98  }
99 
100  AbstractSharedMemSegment* CreateDefault();
101  AbstractSharedMemSegment* AttachDefault();
102  void DestroyDefault();
103 
105  void WriteSeg1Child();
106 
108  void WriteSeg2Child();
109 
110  void TestReadWriteChild();
111  void TestLargeChild();
112  void TwoKidsChild1();
113  void TwoKidsChild2();
114 
115  bool IncrementStorm(AbstractSharedMemSegment* seg, size_t mutex_size);
116 
117  void MutexChild();
118 
120  scoped_ptr<AbstractSharedMem> shmem_runtime_;
121  scoped_ptr<ThreadSystem> thread_system_;
122  MockMessageHandler handler_;
123 
124 
125 };
126 
129 template<typename ConcreteTestEnv>
131  public:
132  SharedMemTestTemplate() : SharedMemTestBase(new ConcreteTestEnv) {
133  }
134 };
135 
136 TYPED_TEST_CASE_P(SharedMemTestTemplate);
137 
138 TYPED_TEST_P(SharedMemTestTemplate, TestRewrite) {
140 }
141 
142 TYPED_TEST_P(SharedMemTestTemplate, TestRewriteReattach) {
144 }
145 
146 TYPED_TEST_P(SharedMemTestTemplate, TestLarge) {
148 }
149 
150 TYPED_TEST_P(SharedMemTestTemplate, TestDistinct) {
152 }
153 
154 TYPED_TEST_P(SharedMemTestTemplate, TestDestroy) {
156 }
157 
158 TYPED_TEST_P(SharedMemTestTemplate, TestCreateTwice) {
160 }
161 
162 TYPED_TEST_P(SharedMemTestTemplate, TestTwoKids) {
164 }
165 
166 TYPED_TEST_P(SharedMemTestTemplate, TestMutex) {
168 }
169 
170 REGISTER_TYPED_TEST_CASE_P(SharedMemTestTemplate, TestRewrite,
171  TestRewriteReattach, TestLarge, TestDistinct,
172  TestDestroy, TestCreateTwice, TestTwoKids,
173  TestMutex);
174 
175 }
176 
177 #endif
void TestMutex()
Test for mutex operation.
void TestDistinct()
Make sure that 2 segments don't interfere.
Definition: mock_message_handler.h:39
void TestLarge()
Test with large data; also test initialization.
virtual volatile char * Base()=0
Definition: shared_mem_test_base.h:61
Definition: scoped_ptr.h:30
Definition: function.h:47
virtual void WaitForChildren()=0
Definition: abstract_shared_mem.h:86
void TestTwoKids()
Make sure between two kids see the SHM as well.
virtual void ShortSleep()=0
Runtime-specific short sleep.
Definition: shared_mem_test_base.h:33
virtual void ChildFailed()=0
Called in a child to denote it exiting with failure.
Definition: abstract_shared_mem.h:31
Definition: shared_mem_test_base.h:130
void TestReadWrite(bool reattach)
Basic read/write operation test.
void TestDestroy()
Make sure destruction destroys things properly...
virtual bool CreateChild(Function *callback)=0