Skip to content

Commit a07d16e

Browse files
authoredJan 19, 2023
Merge pull request #19 from cschreib/snitch
Update snitch and CI dependencies
2 parents 649ce7e + 832ba4b commit a07d16e

27 files changed

+493
-500
lines changed
 

‎.github/workflows/cmake.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on: push
44

55
env:
6-
EM_VERSION: 2.0.16
6+
EM_VERSION: 2.0.34
77
EM_CACHE_FOLDER: 'emsdk-cache'
88
CODECOV_TOKEN: '99959e57-0b92-48b4-bf55-559d43d41b58'
99

@@ -28,7 +28,7 @@ jobs:
2828

2929
steps:
3030
- name: Checkout code
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232
with:
3333
submodules: 'recursive'
3434

@@ -46,7 +46,7 @@ jobs:
4646

4747
- name: Setup Emscripten
4848
if: matrix.platform.compiler == 'em++'
49-
uses: mymindstorm/setup-emsdk@v7
49+
uses: mymindstorm/setup-emsdk@v11
5050
with:
5151
version: ${{env.EM_VERSION}}
5252
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
2+
build_wasm/
23
build_clang/
34
doc/html/
45
oup.sublime-workspace

‎oup.sublime-project

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
"shell_cmd": "make -j12 oup_speed_benchmark",
7171
},
7272
{
73-
"name": "snatch",
74-
"shell_cmd": "make -j12 snatch",
73+
"name": "snitch",
74+
"shell_cmd": "make -j12 snitch",
7575
},
7676
],
7777
"working_dir": "$folder/build",

‎tests/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ endfunction()
3131

3232
include(FetchContent)
3333

34-
FetchContent_Declare(snatch
35-
GIT_REPOSITORY https://github.com/cschreib/snatch.git
36-
GIT_TAG v0.1.3)
37-
FetchContent_MakeAvailable(snatch)
34+
FetchContent_Declare(snitch
35+
GIT_REPOSITORY https://github.com/cschreib/snitch.git
36+
GIT_TAG v1.0.0)
37+
FetchContent_MakeAvailable(snitch)
3838

3939
set(RUNTIME_TEST_FILES
4040
${PROJECT_SOURCE_DIR}/tests/tests_common.cpp
@@ -61,7 +61,7 @@ set(RUNTIME_TEST_FILES
6161

6262
add_executable(oup_runtime_tests ${RUNTIME_TEST_FILES})
6363
target_link_libraries(oup_runtime_tests PRIVATE oup::oup)
64-
target_link_libraries(oup_runtime_tests PRIVATE snatch::snatch)
64+
target_link_libraries(oup_runtime_tests PRIVATE snitch::snitch)
6565
add_platform_definitions(oup_runtime_tests)
6666

6767
add_custom_target(oup_runtime_tests_run

‎tests/memory_tracker.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include <cstdio>
55
#include <stdexcept>
66

7-
void* allocations[max_allocations];
8-
void* allocations_array[max_allocations];
9-
std::size_t allocations_bytes[max_allocations];
10-
std::size_t num_allocations = 0u;
11-
std::size_t size_allocations = 0u;
12-
std::size_t double_delete = 0u;
13-
bool memory_tracking = false;
14-
bool force_next_allocation_failure = false;
7+
volatile void* allocations[max_allocations];
8+
volatile void* allocations_array[max_allocations];
9+
volatile std::size_t allocations_bytes[max_allocations];
10+
volatile std::size_t num_allocations = 0u;
11+
volatile std::size_t size_allocations = 0u;
12+
volatile std::size_t double_delete = 0u;
13+
volatile bool memory_tracking = false;
14+
volatile bool force_next_allocation_failure = false;
1515

1616
constexpr bool debug_alloc = false;
1717
constexpr bool scramble_alloc = true;
@@ -93,8 +93,8 @@ void* allocate(std::size_t size, bool array, std::align_val_t align) {
9393

9494
allocations_bytes[num_allocations] = size;
9595

96-
++num_allocations;
97-
size_allocations += size;
96+
num_allocations = num_allocations + 1u;
97+
size_allocations = size_allocations + size;
9898
}
9999

100100
return p;
@@ -110,21 +110,21 @@ void deallocate(void* p, bool array, std::align_val_t align [[maybe_unused]]) {
110110
}
111111

112112
if (memory_tracking) {
113-
bool found = false;
114-
void** allocations_type = array ? allocations_array : allocations;
113+
bool found = false;
114+
volatile void** allocations_type = array ? allocations_array : allocations;
115115
for (std::size_t i = 0; i < num_allocations; ++i) {
116116
if (allocations_type[i] == p) {
117117
std::swap(allocations_type[i], allocations_type[num_allocations - 1]);
118118
std::swap(allocations_bytes[i], allocations_bytes[num_allocations - 1]);
119-
--num_allocations;
120-
size_allocations -= allocations_bytes[num_allocations - 1];
121-
found = true;
119+
num_allocations = num_allocations - 1u;
120+
size_allocations = size_allocations - allocations_bytes[num_allocations - 1];
121+
found = true;
122122
break;
123123
}
124124
}
125125

126126
if (!found) {
127-
++double_delete;
127+
double_delete = double_delete + 1u;
128128
}
129129
}
130130

@@ -188,11 +188,11 @@ memory_tracker::~memory_tracker() noexcept {
188188
::memory_tracking = false;
189189
}
190190

191-
std::size_t memory_tracker::allocated() const {
191+
std::size_t memory_tracker::allocated() const volatile {
192192
return ::num_allocations - initial_allocations;
193193
}
194194

195-
std::size_t memory_tracker::double_delete() const {
195+
std::size_t memory_tracker::double_delete() const volatile {
196196
return ::double_delete - initial_double_delete;
197197
}
198198

‎tests/memory_tracker.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#include <new>
33

44
// Allocation tracker, to catch memory leaks and double delete
5-
constexpr std::size_t max_allocations = 20'000;
6-
extern void* allocations[max_allocations];
7-
extern void* allocations_array[max_allocations];
8-
extern std::size_t allocations_bytes[max_allocations];
9-
extern std::size_t num_allocations;
10-
extern std::size_t size_allocations;
11-
extern std::size_t double_delete;
12-
extern bool memory_tracking;
13-
extern bool force_next_allocation_failure;
5+
constexpr std::size_t max_allocations = 20'000;
6+
extern volatile void* allocations[max_allocations];
7+
extern volatile void* allocations_array[max_allocations];
8+
extern volatile std::size_t allocations_bytes[max_allocations];
9+
extern volatile std::size_t num_allocations;
10+
extern volatile std::size_t size_allocations;
11+
extern volatile std::size_t double_delete;
12+
extern volatile bool memory_tracking;
13+
extern volatile bool force_next_allocation_failure;
1414

1515
void* operator new(std::size_t size);
1616

@@ -39,8 +39,8 @@ struct memory_tracker {
3939
memory_tracker() noexcept;
4040
~memory_tracker() noexcept;
4141

42-
std::size_t allocated() const;
43-
std::size_t double_delete() const;
42+
std::size_t allocated() const volatile;
43+
std::size_t double_delete() const volatile;
4444
};
4545

4646
struct fail_next_allocation {

‎tests/runtime_tests_lifetime.cpp

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "memory_tracker.hpp"
22
#include "testing.hpp"
3-
#include "tests_common.hpp"
43

54
#include <algorithm>
65
#include <vector>
76

87
TEMPLATE_LIST_TEST_CASE("observer expiring scope", "[lifetime][owner][observer]", owner_types) {
9-
memory_tracker mem_track;
8+
volatile memory_tracker mem_track;
109

1110
{
1211
observer_ptr<TestType> optr;
@@ -25,11 +24,11 @@ TEMPLATE_LIST_TEST_CASE("observer expiring scope", "[lifetime][owner][observer]"
2524
}
2625

2726
CHECK_NO_LEAKS;
28-
};
27+
}
2928

3029
TEMPLATE_LIST_TEST_CASE(
3130
"observer not expiring when owner moved", "[lifetime][owner][observer]", owner_types) {
32-
memory_tracker mem_track;
31+
volatile memory_tracker mem_track;
3332

3433
{
3534
TestType outer_ptr;
@@ -59,10 +58,10 @@ TEMPLATE_LIST_TEST_CASE(
5958
}
6059

6160
CHECK_NO_LEAKS;
62-
};
61+
}
6362

6463
TEMPLATE_LIST_TEST_CASE("observer expiring reset", "[lifetime][owner][observer]", owner_types) {
65-
memory_tracker mem_track;
64+
volatile memory_tracker mem_track;
6665

6766
{
6867
observer_ptr<TestType> optr;
@@ -82,12 +81,12 @@ TEMPLATE_LIST_TEST_CASE("observer expiring reset", "[lifetime][owner][observer]"
8281
}
8382

8483
CHECK_NO_LEAKS;
85-
};
84+
}
8685

8786
TEMPLATE_LIST_TEST_CASE(
8887
"release valid owner with observer", "[lifetime][release][owner][observer]", owner_types) {
8988
if constexpr (!is_sealed<TestType>) {
90-
memory_tracker mem_track;
89+
volatile memory_tracker mem_track;
9190

9291
{
9392
observer_ptr<TestType> optr;
@@ -126,14 +125,14 @@ TEMPLATE_LIST_TEST_CASE(
126125

127126
CHECK_NO_LEAKS;
128127
}
129-
};
128+
}
130129

131130
TEMPLATE_LIST_TEST_CASE(
132131
"release valid owner with observer subobject",
133132
"[lifetime][release][owner][observer]",
134133
owner_types) {
135134
if constexpr (!is_sealed<TestType>) {
136-
memory_tracker mem_track;
135+
volatile memory_tracker mem_track;
137136

138137
{
139138
state_observer_ptr<TestType> optr;
@@ -170,11 +169,11 @@ TEMPLATE_LIST_TEST_CASE(
170169

171170
CHECK_NO_LEAKS;
172171
}
173-
};
172+
}
174173

175174
TEMPLATE_LIST_TEST_CASE(
176175
"observer get and raw get", "[lifetime][get][raw_get][owner][observer]", owner_types) {
177-
memory_tracker mem_track;
176+
volatile memory_tracker mem_track;
178177

179178
{
180179
observer_ptr<TestType> optr;
@@ -196,14 +195,14 @@ TEMPLATE_LIST_TEST_CASE(
196195
}
197196

198197
CHECK_NO_LEAKS;
199-
};
198+
}
200199

201200
TEMPLATE_LIST_TEST_CASE(
202201
"object owning observer pointer to itself",
203202
"[lifetime][cycles][owner][observer]",
204203
owner_types) {
205204
if constexpr (is_cyclic<TestType>) {
206-
memory_tracker mem_track;
205+
volatile memory_tracker mem_track;
207206

208207
{
209208
TestType ptr = make_pointer_deleter_1<TestType>();
@@ -214,12 +213,12 @@ TEMPLATE_LIST_TEST_CASE(
214213

215214
CHECK_NO_LEAKS;
216215
}
217-
};
216+
}
218217

219218
TEMPLATE_LIST_TEST_CASE(
220219
"object owning observer pointer to other", "[lifetime][cycles][owner][observer]", owner_types) {
221220
if constexpr (is_cyclic<TestType>) {
222-
memory_tracker mem_track;
221+
volatile memory_tracker mem_track;
223222

224223
{
225224
TestType ptr1 = make_pointer_deleter_1<TestType>();
@@ -232,14 +231,14 @@ TEMPLATE_LIST_TEST_CASE(
232231

233232
CHECK_NO_LEAKS;
234233
}
235-
};
234+
}
236235

237236
TEMPLATE_LIST_TEST_CASE(
238237
"object owning observer pointer open chain",
239238
"[lifetime][cycles][owner][observer]",
240239
owner_types) {
241240
if constexpr (is_cyclic<TestType>) {
242-
memory_tracker mem_track;
241+
volatile memory_tracker mem_track;
243242

244243
{
245244
TestType ptr1 = make_pointer_deleter_1<TestType>();
@@ -253,14 +252,14 @@ TEMPLATE_LIST_TEST_CASE(
253252

254253
CHECK_NO_LEAKS;
255254
}
256-
};
255+
}
257256

258257
TEMPLATE_LIST_TEST_CASE(
259258
"object owning observer pointer open chain reversed",
260259
"[lifetime][cycles][owner][observer]",
261260
owner_types) {
262261
if constexpr (is_cyclic<TestType>) {
263-
memory_tracker mem_track;
262+
volatile memory_tracker mem_track;
264263

265264
{
266265
TestType ptr1 = make_pointer_deleter_1<TestType>();
@@ -274,14 +273,14 @@ TEMPLATE_LIST_TEST_CASE(
274273

275274
CHECK_NO_LEAKS;
276275
}
277-
};
276+
}
278277

279278
TEMPLATE_LIST_TEST_CASE(
280279
"object owning observer pointer closed chain interleaved",
281280
"[lifetime][cycles][owner][observer]",
282281
owner_types) {
283282
if constexpr (is_cyclic<TestType>) {
284-
memory_tracker mem_track;
283+
volatile memory_tracker mem_track;
285284

286285
{
287286
TestType ptr1 = make_pointer_deleter_1<TestType>();
@@ -298,10 +297,10 @@ TEMPLATE_LIST_TEST_CASE(
298297

299298
CHECK_NO_LEAKS;
300299
}
301-
};
300+
}
302301

303302
TEMPLATE_LIST_TEST_CASE("pointers in vector", "[lifetime][array][owner][observer]", owner_types) {
304-
memory_tracker mem_track;
303+
volatile memory_tracker mem_track;
305304

306305
{
307306
std::vector<TestType> vec_own;
@@ -346,4 +345,4 @@ TEMPLATE_LIST_TEST_CASE("pointers in vector", "[lifetime][array][owner][observer
346345
}
347346

348347
CHECK_NO_LEAKS;
349-
};
348+
}

0 commit comments

Comments
 (0)
Please sign in to comment.