diff options
author | Evan Green <evgreen@chromium.org> | 2021-07-28 10:03:37 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-02 15:43:13 +0000 |
commit | ee342c585c588bf171357753f7b35133a3949fb1 (patch) | |
tree | 07714d89c8975a33a3337d179fb2232b3066dfb8 /test | |
parent | 515883d1cf14cbdcbf389736a9b67293d1e9cfd2 (diff) | |
download | chrome-ec-ee342c585c588bf171357753f7b35133a3949fb1.tar.gz |
test: Make more and smaller allocations in shmalloc
The shmalloc test works like this:
* Randomly select a slot out of 12.
* If that slot is occupied, free it. If that slot is free, attempt to
make an allocation of size rand() % total_heap_size.
* At the end of the test, assert (among other things) that we were able
to make at least 5 allocations at once given 500000 iterations.
It turns out that getting 5 outstanding allocations at once using this
algorithm is not trivial. I did a simulation with a simpler version of
this that just attempts to make (rand % total) size allocations without
overflowing the max [1], and found that the average number of allocations
you're able to make is about 1.8, with a standard deviation of 0.9. That
means that the test is asserting that in 500000 iterations it will be
able to do >3 standard deviations better than the mean in ~500000/1.8
iterations.
Since we never vary the rand seed, and we happened to get lucky with the
default seed, it all works. But when I try to compile in 32-bit mode, I
think I get an unlucky default seed, and always fail this 5 allocation
test.
There are a few knobs you could twist to fix this:
* You could reduce the allocation bar below 5.
* You could increase the iteration count above 500000.
* You could increase the slot count above 12 so that the first dice
roll favors trying allocations more.
* You could decrease the max allocation size from "total" to reduce the
amount each allocation can occupy.
This change opts for the last option. Reducing the max allocation to
total / 2 increases the (simplified) simulation result to a mean of 3.5
with a standard deviation of 1.27. This means the test now only has to
do better than < 1 standard deviation from the mean in 500000
iterations. This is still probabilistic, but is much less likely to
break if you sneeze on it wrong.
[1] https://paste.googleplex.com/6653229610827776
BUG=b:179062230
BRANCH=none
TEST=make -j runhosttests BOARD=host and x86_64 and i686.
Signed-off-by: Evan Green <evgreen@chromium.org>
Change-Id: Ifb16533ee6fa02ce2613c32b1462b78ef0c6cd21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3059230
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/shmalloc.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/test/shmalloc.c b/test/shmalloc.c index 70e0fb5aab..a596d173e7 100644 --- a/test/shmalloc.c +++ b/test/shmalloc.c @@ -253,7 +253,7 @@ void run_test(int argc, char **argv) return; } } else { - size_t alloc_size = r_data % (shmem_size); + size_t alloc_size = r_data % (shmem_size / 2); /* * If the allocation entry is empty - allocate a |