Skip to content

Commit

Permalink
Revise testing
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Mar 10, 2024
1 parent 9aa4101 commit 837ea31
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def unmount(cls):
securefs_unmount(cls.securefs_process, cls.mount_point)
cls.securefs_process = None

if version == 4:
if version == 4 and not plain_text_names:

def test_long_name(self):
os.mkdir(os.path.join(self.mount_point, "k" * 200))
Expand Down
46 changes: 46 additions & 0 deletions test/test_thread_local.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include "thread_local.h"
#include <atomic>
#include <doctest/doctest.h>
#include <memory>

namespace securefs
{
namespace
{
struct A
{
int value = 1;
static inline std::atomic<int> destroy_count = 0;

~A() { ++destroy_count; }
};

TEST_CASE("Test custom ThreadLocal")
{
ThreadLocal<A> a1([]() { return std::make_unique<A>(); });
{
ThreadLocal<A> a2(
[]()
{
auto result = std::make_unique<A>();
result->value = 2;
return result;
});
CHECK(a1.get().value == 1);
CHECK(a2.get().value == 2);
}
// Now a2 is destroyed, and a3 will take over its slot.
ThreadLocal<A> a3(
[]()
{
auto result = std::make_unique<A>();
result->value = 3;
return result;
});
CHECK(a1.get().value == 1);
CHECK(a3.get().value == 3);
CHECK(A::destroy_count.load() == 1);
}
} // namespace
} // namespace securefs

0 comments on commit 837ea31

Please sign in to comment.