~ubuntu-branches/ubuntu/wily/google-perftools/wily

« back to all changes in this revision

Viewing changes to src/tests/memalign_unittest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2009-09-19 00:10:06 UTC
  • mto: (3.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090919001006-m997dckgoqs3sru9
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
    CHECK(posix_memalign(&ptr, sizeof(void*)+1, 1) == EINVAL);
171
171
    CHECK(posix_memalign(&ptr, 4097, 1) == EINVAL);
172
172
 
 
173
    // Grab some memory so that the big allocation below will definitely fail.
 
174
    void* p_small = malloc(4*1048576);
 
175
    CHECK(p_small != NULL);
 
176
 
173
177
    // Make sure overflow is returned as ENOMEM
174
 
    for (size_t s = 0; ; s += (10 << 20)) {
175
 
      int r = posix_memalign(&ptr, 1024, s);
176
 
      if (r == ENOMEM) break;
177
 
      CHECK(r == 0);
178
 
      free(ptr);
 
178
    const size_t zero = 0;
 
179
    static const size_t kMinusNTimes = 10;
 
180
    for ( size_t i = 1; i < kMinusNTimes; ++i ) {
 
181
      int r = posix_memalign(&ptr, 1024, zero - i);
 
182
      CHECK(r == ENOMEM);
179
183
    }
 
184
 
 
185
    free(p_small);
180
186
  }
181
187
 
182
188
  const int pagesize = getpagesize();
185
191
    for (int s = 0; s != -1; s = NextSize(s)) {
186
192
      void* p = valloc(s);
187
193
      CheckAlignment(p, pagesize);
188
 
      Fill(p, pagesize, 'v');
189
 
      CHECK(Valid(p, pagesize, 'v'));
 
194
      Fill(p, s, 'v');
 
195
      CHECK(Valid(p, s, 'v'));
190
196
      free(p);
191
197
    }
192
198
  }
201
207
      CHECK(Valid(p, alloc_needed, 'x'));
202
208
      free(p);
203
209
    }
204
 
 
205
 
    // should be safe to write upto a page in pvalloc(0) region
206
 
    void* p = pvalloc(0);
207
 
    Fill(p, pagesize, 'y');
208
 
    CHECK(Valid(p, pagesize, 'y'));
209
 
    free(p);
210
210
  }
211
211
 
212
212
  printf("PASS\n");