Grok  7.6.6
testing.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2021 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #pragma once
19 
20 #include <sstream>
21 
22 namespace grk {
23 
24 #if defined(GRK_HAVE_VALGRIND)
25 #include <valgrind/memcheck.h>
26 #endif
27 
28 // uncomment to enable testing of different stages of round-trip lossless compress
29 //#define DEBUG_LOSSLESS_DWT
30 //#define DEBUG_LOSSLESS_T1
31 //#define DEBUG_LOSSLESS_T2
32 
33 //#define GRK_DEBUG_SPARSE
34 
35 #ifdef GRK_DEBUG_SPARSE
36 #undef __SSE__
37 #undef __SSE2__
38 #undef __AVX2__
39 #endif
40 
41 #if defined(GRK_HAVE_VALGRIND) && defined(GRK_DEBUG_SPARSE)
42 const size_t grk_mem_ok = (size_t)-1;
43 
44 #define GRK_DEBUG_VALGRIND
45 template<typename T> size_t grk_memcheck(const T* buf, size_t len){
46  size_t val = VALGRIND_CHECK_MEM_IS_DEFINED(buf,len * sizeof(T));
47  return (val) ? (val - (uint64_t)buf)/sizeof(T) : grk_mem_ok;
48 }
49 template<typename T> void grk_memcheck_all(const T* buf, size_t len, std::string msg){
50  for (uint32_t i = 0; i < len; ++i) {
51  auto val = grk_memcheck<T>(buf + i, 1);
52  if (val != grk_mem_ok){
53  std::ostringstream ss;
54  ss << msg << " " << "offset = " << i + val;
55  GRK_ERROR(ss.str().c_str());
56  }
57  }
58 }
59 
60 
61 #endif
62 
63 }
Copyright (C) 2016-2021 Grok Image Compression Inc.
Definition: BitIO.cpp:23
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:57