Skip to content

Commit

Permalink
Fix occasional crash in test/libc/intrin/mmap_test (#1289)
Browse files Browse the repository at this point in the history
This test would sometimes crash due to the EZBENCH2() macro occasionally
running the first benchmark (BenchMmapPrivate()) less times than it does
the second benchmark (BenchUnmap()) - this would then lead to a crash in
BenchUnmap() because BenchUnmap() expects that BenchMmapPrivate() has to
previously have been called at least as many times as it has itself such
that a region of memory has been mapped, for BenchUnmap() to then unmap.

This commit fixes this by utilizing the newer BENCHMARK() macro (instead
of the EZBENCH2() macro) which runs the benchmark using an count of runs
specified directly by the benchmark itself, which allows us to make sure
that the two benchmark functions get ran the exact same amount of times.
  • Loading branch information
GabrielRavier authored Sep 15, 2024
1 parent 19563d3 commit 7f21547
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/libc/intrin/mmap_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "libc/sysv/consts/msync.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/benchmark.h"
#include "libc/testlib/testlib.h"
#include "libc/x/xspawn.h"

Expand Down Expand Up @@ -524,7 +524,7 @@ TEST(mmap, sharedFileMapFork) {
////////////////////////////////////////////////////////////////////////////////
// BENCHMARKS

#define N (EZBENCH_COUNT * EZBENCH_TRIES)
#define N 1000

int count;
void *ptrs[N];
Expand Down Expand Up @@ -561,8 +561,8 @@ void BenchBigMunmap(void) {
}

TEST(mmap, bench) {
EZBENCH2("mmap", donothing, BenchMmapPrivate());
EZBENCH2("munmap", donothing, BenchUnmap());
// EZBENCH2("big mmap", donothing, BenchBigMmap());
// EZBENCH2("big munmap", donothing, BenchBigMunmap());
BENCHMARK(N, 1, BenchMmapPrivate());
BENCHMARK(N, 1, BenchUnmap());
// BENCHMARK(N, 1, BenchBigMmap());
// BENCHMARK(N, 1, BenchBigMunmap());
}

0 comments on commit 7f21547

Please sign in to comment.