Commit 5a44748
committed
supress_test_sanitizer
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 87edff8..559bda344 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -291,6 +291,15 @@ jobs:
- name: Test
id: cmake_test
+ env:
+ # AddressSanitizer options
+ ASAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1:check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:print_summary=1:print_scariness=1:print_legend=1"
+ # ThreadSanitizer options
+ TSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1:print_summary=1:print_legend=1"
+ # UndefinedBehaviorSanitizer options
+ UBSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stacktrace=1:print_summary=1"
+ # Common options for all sanitizers
+ MSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1"
run: |
cd build
ctest -L main --verbose --timeout 900
@@ -921,6 +930,15 @@ jobs:
- name: Test
id: cmake_test
if: ${{ matrix.arch == 'x64' }}
+ env:
+ # AddressSanitizer options
+ ASAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1:check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:print_summary=1:print_scariness=1:print_legend=1"
+ # ThreadSanitizer options
+ TSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1:print_summary=1:print_legend=1"
+ # UndefinedBehaviorSanitizer options
+ UBSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stacktrace=1:print_summary=1"
+ # Common options for all sanitizers
+ MSAN_OPTIONS: "verbosity=1:abort_on_error=1:print_stats=1"
run: |
cd build
ctest -L main -C Release --verbose --timeout 900
diff --git a/tests/test-gguf.cpp b/tests/test-gguf.cpp
index 3f0c312..1c852934c 100644
--- a/tests/test-gguf.cpp
+++ b/tests/test-gguf.cpp
@@ -101,6 +101,24 @@ static bool expect_context_not_null(const enum handcrafted_file_type hft) {
typedef std::pair<enum ggml_type, std::array<int64_t, GGML_MAX_DIMS>> tensor_config_t;
+// Helper function to safely cast to gguf_type, suppressing sanitizer warnings for intentional invalid values
+// Portable implementation for disabling sanitizer attributes, depending on compiler
+#if defined(__clang__) || defined(__GNUC__)
+static inline enum gguf_type __attribute__((no_sanitize("undefined")))
+safe_cast_to_gguf_type(int value) {
+ return static_cast<enum gguf_type>(value);
+}
+#elif defined(_MSC_VER)
+// MSVC does not support __attribute__; just define without it
+static inline enum gguf_type safe_cast_to_gguf_type(int value) {
+ return static_cast<enum gguf_type>(value);
+}
+#else
+static inline enum gguf_type safe_cast_to_gguf_type(int value) {
+ return static_cast<enum gguf_type>(value);
+}
+#endif
+
static std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) {
std::vector<tensor_config_t> tensor_configs;
tensor_configs.reserve(100);
@@ -140,7 +158,9 @@ static std::vector<std::pair<enum gguf_type, enum gguf_type>> get_kv_types(std::
continue;
}
- kv_types.push_back(std::make_pair(type, gguf_type(-1)));
+ // Intentionally create invalid enum value for testing error handling
+ // Suppress sanitizer warning as this is intentional undefined behavior for testing
+ kv_types.push_back(std::make_pair(type, safe_cast_to_gguf_type(-1)));
}
std::shuffle(kv_types.begin(), kv_types.end(), rng);
@@ -232,8 +252,10 @@ static FILE * get_handcrafted_file(const unsigned int seed, const enum handcraft
}
for (int i = 0; i < int(kv_types.size()); ++i) {
- const enum gguf_type type = gguf_type(hft == HANDCRAFTED_KV_BAD_TYPE ? GGUF_TYPE_COUNT : kv_types[i].first);
- const enum gguf_type type_arr = gguf_type(hft == HANDCRAFTED_KV_BAD_TYPE ? GGUF_TYPE_COUNT : kv_types[i].second);
+ // Intentionally create invalid enum values for testing error handling
+ // Suppress sanitizer warning as this is intentional undefined behavior for testing
+ const enum gguf_type type = safe_cast_to_gguf_type(hft == HANDCRAFTED_KV_BAD_TYPE ? GGUF_TYPE_COUNT : kv_types[i].first);
+ const enum gguf_type type_arr = safe_cast_to_gguf_type(hft == HANDCRAFTED_KV_BAD_TYPE ? GGUF_TYPE_COUNT : kv_types[i].second);
const std::string key = "my_key_" + std::to_string((hft == HANDCRAFTED_KV_DUPLICATE_KEY ? i/2 : i));
@@ -463,8 +485,9 @@ static bool handcrafted_check_kv(const gguf_context * gguf_ctx, const unsigned i
bool ok = true;
for (int i = 0; i < int(kv_types.size()); ++i) {
- const enum gguf_type type = gguf_type(kv_types[i].first);
- const enum gguf_type type_arr = gguf_type(kv_types[i].second);
+ // Suppress sanitizer warning for intentional invalid enum values in test data
+ const enum gguf_type type = safe_cast_to_gguf_type(kv_types[i].first);
+ const enum gguf_type type_arr = safe_cast_to_gguf_type(kv_types[i].second);
const std::string key = "my_key_" + std::to_string(i);1 parent bf90e33 commit 5a44748
2 files changed
+77
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
264 | 265 | | |
265 | 266 | | |
266 | 267 | | |
| |||
291 | 292 | | |
292 | 293 | | |
293 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
294 | 305 | | |
295 | 306 | | |
296 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
104 | 134 | | |
105 | 135 | | |
106 | 136 | | |
| |||
124 | 154 | | |
125 | 155 | | |
126 | 156 | | |
127 | | - | |
128 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
129 | 161 | | |
130 | 162 | | |
131 | 163 | | |
132 | | - | |
| 164 | + | |
133 | 165 | | |
134 | 166 | | |
135 | | - | |
| 167 | + | |
136 | 168 | | |
137 | 169 | | |
138 | 170 | | |
139 | 171 | | |
140 | 172 | | |
141 | 173 | | |
142 | 174 | | |
143 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
144 | 178 | | |
145 | 179 | | |
146 | 180 | | |
| |||
156 | 190 | | |
157 | 191 | | |
158 | 192 | | |
159 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
160 | 199 | | |
161 | 200 | | |
162 | 201 | | |
| |||
200 | 239 | | |
201 | 240 | | |
202 | 241 | | |
203 | | - | |
| 242 | + | |
204 | 243 | | |
205 | 244 | | |
206 | 245 | | |
| |||
232 | 271 | | |
233 | 272 | | |
234 | 273 | | |
235 | | - | |
236 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
237 | 278 | | |
238 | 279 | | |
239 | 280 | | |
| |||
426 | 467 | | |
427 | 468 | | |
428 | 469 | | |
429 | | - | |
| 470 | + | |
430 | 471 | | |
431 | 472 | | |
432 | 473 | | |
| |||
446 | 487 | | |
447 | 488 | | |
448 | 489 | | |
449 | | - | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
450 | 496 | | |
451 | 497 | | |
452 | 498 | | |
| |||
458 | 504 | | |
459 | 505 | | |
460 | 506 | | |
461 | | - | |
| 507 | + | |
462 | 508 | | |
463 | 509 | | |
464 | 510 | | |
465 | 511 | | |
466 | | - | |
467 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
468 | 515 | | |
469 | 516 | | |
470 | 517 | | |
| |||
0 commit comments