Grok
12.0.1
src
lib
core
util
testing.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016-2024 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>
46
size_t
grk_memcheck
(
const
T* buf,
size_t
len)
47
{
48
size_t
val =
VALGRIND_CHECK_MEM_IS_DEFINED
(buf, len *
sizeof
(T));
49
return
(val) ? (val - (
uint64_t
)buf) /
sizeof
(T) :
grk_mem_ok
;
50
}
51
template
<
typename
T>
52
bool
grk_memcheck_all
(
const
T* buf,
size_t
len, std::string
msg
)
53
{
54
bool
rc
=
true
;
55
for
(
uint32_t
i
= 0;
i
< len; ++
i
)
56
{
57
auto
val =
grk_memcheck<T>
(buf +
i
, 1);
58
if
(val !=
grk_mem_ok
)
59
{
60
std::ostringstream
ss
;
61
ss
<<
msg
<<
" "
62
<<
"offset = "
<<
i
+ val;
63
Logger::logger_
.
error
(
ss
.str().c_str());
64
rc
=
false
;
65
}
66
}
67
return
rc
;
68
}
69
70
#endif
71
72
}
// namespace grk
grk
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition
ICacheable.h:20
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition
BufferedStream.h:239
grk::Logger::error
void error(const char *fmt,...) override
Definition
Logger.h:53
grk::Logger::logger_
static Logger logger_
Definition
Logger.h:70
Generated by
1.10.0