Change safe-buffer test structure 32/240232/3
authorMateusz Cegielka <m.cegielka@samsung.com>
Tue, 4 Aug 2020 13:29:11 +0000 (15:29 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 21 Aug 2020 06:32:21 +0000 (06:32 +0000)
test_safe-buffer.cpp contains tests that ensure std::vector fails to
erase possibly confidential memory when its destructor is called, which
try to make sure the SafeBuffer testing method is valid. Since the
SafeBuffer test results may be completely wrong if these tests fail, it
would be better to merge them into one test to avoid misleading results.

I have merged the 4 tests into a single test and added some comments.

Change-Id: I9d58a7a3942a0318c0fa96047a1bdb7e708a69d4

unit-tests/test_safe-buffer.cpp

index ff9dccd..582bbbd 100644 (file)
@@ -83,35 +83,18 @@ BOOST_AUTO_TEST_SUITE(SAFE_BUFFER_TEST)
 
 // Tests for SafeBuffer. Checks if memory occupied by the buffer is wiped after it's deleted.
 
-POSITIVE_TEST_CASE(SafeBufferTest_uc_control_group)
+POSITIVE_TEST_CASE(SafeBufferTest)
 {
-       size_t cnt = buffer_erase_test<std::vector<unsigned char>>();
-
-       BOOST_REQUIRE_MESSAGE(cnt > LEN / 2,
+       // Run a control group to check if this kind of test can even work.
+       BOOST_REQUIRE_MESSAGE(buffer_erase_test<std::vector<unsigned char>>() > LEN / 2,
                                                  "Less than 1/2 of data matches the original.");
-}
-
-POSITIVE_TEST_CASE(SafeBufferTest_item_control_group)
-{
-       size_t cnt = buffer_erase_test<std::vector<Item>>();
-
-       BOOST_REQUIRE_MESSAGE(cnt > LEN / 2,
+       BOOST_REQUIRE_MESSAGE(buffer_erase_test<std::vector<Item>>() > LEN / 2,
                                                  "Less than 1/2 of data matches the original.");
-}
 
-POSITIVE_TEST_CASE(SafeBufferTest_uc)
-{
-       size_t cnt = buffer_erase_test<RawBuffer>();
-
-       BOOST_REQUIRE_MESSAGE(cnt <= LEN / 10,
+       // Actually check whether SafeBuffer erases memory after destruction.
+       BOOST_REQUIRE_MESSAGE(buffer_erase_test<RawBuffer>() <= LEN / 10,
                                                  "More than 1/10 of data matches the original.");
-}
-
-POSITIVE_TEST_CASE(SafeBufferTest_item)
-{
-       size_t cnt = buffer_erase_test<SafeBuffer<Item>::Type>();
-
-       BOOST_REQUIRE_MESSAGE(cnt <= LEN / 10,
+       BOOST_REQUIRE_MESSAGE(buffer_erase_test<SafeBuffer<Item>::Type>() <= LEN / 10,
                                                  "More than 1/10 of data matches the original.");
 }