diff options
author | Andrea Grandi <agrandi@google.com> | 2022-10-21 09:36:15 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-24 19:24:26 +0000 |
commit | 5de86d973f8a472ba7787319e21c54cbb19a4767 (patch) | |
tree | ef193f0f782a2e9ef16c4381d10a26b290af9577 /test | |
parent | 1afeeef4f4e69960199e32f4de50094c43625b27 (diff) | |
download | chrome-ec-5de86d973f8a472ba7787319e21c54cbb19a4767.tar.gz |
test: Check that std::vector memory is destroyed
Add test that creates a new vector after one has been destroyed.
BUG=b:243964606
TEST=util/run_device_tests.py --board=dartmonkey \
--tests=std_vector
TEST=make run-std_vector
BRANCH=none
Signed-off-by: Andrea Grandi <agrandi@google.com>
Change-Id: Ia6a6c906deea2c75181e77bf2ee994e89c66c5fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3971020
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/std_vector.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/std_vector.cc b/test/std_vector.cc index 5873b416b6..84259ccf57 100644 --- a/test/std_vector.cc +++ b/test/std_vector.cc @@ -72,6 +72,35 @@ test_static int fill_multiple_vectors() return EC_SUCCESS; } +test_static int create_and_destroy_two_vectors() +{ + // This allocates 64kB of memory twice. + // The first vector is declared in a local scope and the memory is + // free'd at the end of the block. + constexpr int num_elements = 16 * 1024; + { + std::vector<int32_t> vec; + for (int i = 0; i < num_elements; ++i) + vec.push_back(i); + + TEST_EQ(static_cast<int>(vec.size()), num_elements, "%d"); + for (int i = 0; i < num_elements; ++i) { + TEST_ASSERT(vec[i] == i); + } + } + + std::vector<int32_t> vec; + for (int i = 0; i < num_elements; ++i) + vec.push_back(i); + + TEST_EQ(static_cast<int>(vec.size()), num_elements, "%d"); + for (int i = 0; i < num_elements; ++i) { + TEST_ASSERT(vec[i] == i); + } + + return EC_SUCCESS; +} + extern "C" void run_test(int argc, const char **argv) { test_reset(); @@ -79,6 +108,7 @@ extern "C" void run_test(int argc, const char **argv) RUN_TEST(push_back_elements); RUN_TEST(fill_one_vector); RUN_TEST(fill_multiple_vectors); + RUN_TEST(create_and_destroy_two_vectors); test_print_result(); } |