Commit 6f4cf66e authored by incardon's avatar incardon

refactoring grid checks

parent e3b181a2
......@@ -45,6 +45,63 @@ if test x"$test_cov" = x"yes"; then
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage "
fi
###### Check for se-class1
AC_MSG_CHECKING(whether to build with security enhancement class1)
se_class1=no
AC_ARG_ENABLE(se-class1,
AC_HELP_STRING(
[--enable-se-class1],
[enable security enhancement class1]
),
se_class1="$enableval"
)
AC_MSG_RESULT($se_class1)
if test x"$se_class1" = x"yes"; then
AC_DEFINE([SE_CLASS1],[],[Security enhancement class 1])
fi
###### Check for se-class 2
AC_MSG_CHECKING(whether to build with security enhancement class 2)
se_class2=no
AC_ARG_ENABLE(se-class2,
AC_HELP_STRING(
[--enable-se-class2],
[enable security enhancement class 2]
),
se_class2="$enableval"
)
AC_MSG_RESULT($se_class2)
if test x"$se_class2" = x"yes"; then
AC_DEFINE([SE_CLASS2],[],[Security enhancement class 2])
fi
###### Check for se-class 3
AC_MSG_CHECKING(whether to build with security enhancement class 3)
se_class3=no
AC_ARG_ENABLE(se-class3,
AC_HELP_STRING(
[--enable-se-class3],
[enable security enhancement class 3]
),
se_class3="$enableval"
)
AC_MSG_RESULT($se_class3)
if test x"$se_class3" = x"yes"; then
AC_DEFINE([SE_CLASS3],[],[Security enhancement class 3])
fi
###### Check for debug compilation
AC_MSG_CHECKING(whether to build with debug information)
......@@ -165,6 +222,21 @@ if [ test x"$debuger" = x"yes" ]; then
else
echo "* debug: no *"
fi
if [ test x"$se_class1" = x"yes" ]; then
echo "* se-class1: yes *"
else
echo "* se-class1: no *"
fi
if [ test x"$se_class2" = x"yes" ]; then
echo "* se-class2: yes *"
else
echo "* se-class2: no *"
fi
if [ test x"$se_class3" = x"yes" ]; then
echo "* se-class3: yes *"
else
echo "* se-class3: no *"
fi
if [ test x"$gpu_support" = x"no" ]; then
echo "* gpu: no *"
else
......
......@@ -572,6 +572,34 @@ BOOST_AUTO_TEST_CASE( grid_iterator_test_use)
}
}
BOOST_AUTO_TEST_CASE( grid_safety_check )
{
#ifdef SE_CLASS1
size_t sz = {16,16,16};
// Create a grid
grid_cpu<3,Point_test<float>> g(sz);
// try to access uninitialized grid
grid_key_dx<3> key1({23,1,1});
g.template get(key1);
BOOST_REQUIRE_EQUAL(g.getLastError(),1001);
g.template setMemory<HeapMemory>();
BOOST_REQUIRE_EQUAL(g.getLastError(),1002);
Point_test<float> t;
g.set(key1,t);
g.set(key1,g2,key1);
BOOST_REQUIRE_EQUAL(g.getLastError(),1003);
#endif
}
BOOST_AUTO_TEST_CASE( grid_use)
{
/* tensor<int,3,3,3> c;
......
......@@ -32,6 +32,48 @@
#include "memory_ly/memory_c.hpp"
#include <vector>
#ifdef STOP_ON_ERROR
#define ACTION_ON_ERROR exit(1);
else if defined(WORKAROUND_ON_ERROR)
#define ACTION_ON_ERROR return boost::fusion::at_c<p>(error_sink);
#else
#define ACTION_ON_ERROR
#endif
// Macro for debugging
#define CHECK_INIT() if (is_mem_init == false)\
{\
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";\
size_t * err_code_pointer = (size_t *)&this->err_code;\
*err_code_pointer = 1001;\
ACTION_ON_ERROR;\
}
#define GRID_OVERFLOW(v1) for (long int i = 0 ; i < dim ; i++)\
{\
if (v1.get(i) >= (long int)getGrid().size(i))\
{\
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";\
size_t * err_code_pointer = (size_t *)&this->err_code;\
*err_code_pointer = 1002;\
ACTION_ON_ERROR;\
}\
}
#define GRID_OVERFLOW_EXT(g,key2) for (size_t i = 0 ; i < dim ; i++)\
{\
if (key2.get(i) >= (long int)g.g1.size(i) || key2.get(i) < 0)\
{\
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";\
size_t * err_code_pointer = (size_t *)&this->err_code;\
*err_code_pointer = 1003;\
ACTION_ON_ERROR;\
}\
}
// Debugging macro
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
......@@ -323,6 +365,23 @@ public:
typedef Mem memory_conf;
private:
//! Error code
size_t err_code;
/*! \brief Return the last error
*
*/
size_t getLastError()
{
return err_code;
}
#ifdef WORKAROUND_ON_ERROR
// A sink in case of error
T error_sink;
#endif
//! Is the memory initialized
bool is_mem_init = false;
......@@ -552,17 +611,8 @@ public:
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(grid_key<p> & v1)
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(&data.mem_r->operator[](g1.LinId(v1.getId()))));
......@@ -581,17 +631,8 @@ public:
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(grid_key<p> & v1) const
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(&data.mem_r->operator[](g1.LinId(v1.getId()))));
......@@ -609,17 +650,8 @@ public:
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1)
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))));
......@@ -637,17 +669,8 @@ public:
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(grid_key_d<dim,p> & v1) const
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))));
......@@ -665,16 +688,8 @@ public:
template <unsigned int p>inline typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1)
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type));
......@@ -692,17 +707,8 @@ public:
template <unsigned int p>inline const typename type_cpu_prop<p,memory_lin>::type & get(const grid_key_dx<dim> & v1) const
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(v1))),sizeof(typename type_cpu_prop<p,memory_lin>::type));
......@@ -720,17 +726,8 @@ public:
inline encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1)
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(T));
......@@ -748,17 +745,8 @@ public:
inline const encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1) const
{
#ifdef DEBUG
if (is_mem_init == false)
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " you must call SetMemory before access the grid\n";
for (long int i = 0 ; i < dim ; i++)
{
if (v1.get(i) >= (long int)getGrid().size(i))
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ << "grid overflow";
}
}
CHECK_INIT()
GRID_OVERFLOW(v1)
#endif
#ifdef MEMLEAK_CHECK
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(T));
......@@ -848,7 +836,7 @@ public:
if (dim != 1)
{
#ifdef DEBUG
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " trying to remove " << "\n";
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " remove work only on dimension == 1 " << "\n";
#endif
return;
}
......@@ -933,15 +921,8 @@ public:
template<typename Memory> inline void set(grid_key_dx<dim> dx, const encapc<1,T,Memory> & obj)
{
#ifdef DEBUG
// Check that the element exist
for (size_t i = 0 ; i < dim ; i++)
{
if (dx.get(i) >= (long int)g1.size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";
}
}
CHECK_INIT()
GRID_OVERFLOW(dx)
#endif
// create the object to copy the properties
......@@ -963,15 +944,8 @@ public:
inline void set(grid_key_dx<dim> dx, const T & obj)
{
#ifdef DEBUG
// Check that the element exist
for (size_t i = 0 ; i < dim ; i++)
{
if (dx.get(i) >= (long int)g1.size(i))
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";
}
}
CHECK_INIT()
GRID_OVERFLOW(dx)
#endif
// create the object to copy the properties
......@@ -992,22 +966,9 @@ public:
inline void set(grid_key_dx<dim> key1,const grid_cpu<dim,T,Mem> & g, grid_key_dx<dim> key2)
{
#ifdef DEBUG
// Check that the element exist
for (size_t i = 0 ; i < dim ; i++)
{
if (key1.get(i) >= (long int)g1.size(i) || key1.get(i) < 0)
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";
}
}
for (size_t i = 0 ; i < dim ; i++)
{
if (key2.get(i) >= (long int)g.g1.size(i) || key2.get(i) < 0)
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " out of bound" << "\n";
}
}
CHECK_INIT()
GRID_OVERFLOW(key1)
GRID_OVERFLOW_EXT(g,key2)
#endif
//create the object to copy the properties
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment