1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// *****************************************************************************
/*!
  \file      tests/unit/Base/TestLoadDistributor.cpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Unit tests for Base/LoadDistributor
  \details   Unit tests for Base/LoadDistributor
*/
// *****************************************************************************

#include "NoWarning/tut.hpp"<--- Include file: "NoWarning/tut.hpp" not found.

#include "TUTConfig.hpp"<--- Include file: "TUTConfig.hpp" not found.
#include "LoadDistributor.hpp"
#include "Exception.hpp"

namespace unittest {

extern std::string g_executable;

} // unittest::

#ifndef DOXYGEN_GENERATING_OUTPUT

namespace tut {

#if defined(__clang__)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wmissing-noreturn"
#elif defined(STRICT_GNUC)
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
#endif

//! All tests in group inherited from this base
struct LoadDistributor_common {};

//! Test group shortcuts
using LoadDistributor_group =
  test_group< LoadDistributor_common, MAX_TESTS_IN_GROUP >;
using LoadDistributor_object = LoadDistributor_group::object;

//! Define test group
static LoadDistributor_group LoadDistributor( "Base/LoadDistributor" );

//! Test definitions for group

//! Test if linear distributor does not throw on bounded virtualization
template<> template<>
void LoadDistributor_object::test< 1 >() {
  set_test_name( "linear doesn't throw on bounded virt" );

  uint64_t chunksize, remainder;
  tk::linearLoadDistributor( 0.5, 1234, 2, chunksize, remainder );
}

//! Test if linear distributor throws on too low virtualization parameter
template<> template<>
void LoadDistributor_object::test< 2 >() {
  set_test_name( "linear throws on too low virt" );

  #ifdef NDEBUG        // exception only thrown in DEBUG mode
    skip( "in RELEASE mode, would yield floating point exception" );
  #else
  try {

    uint64_t chunksize, remainder;
    tk::linearLoadDistributor( -0.5, 1234, 2, chunksize, remainder );

  } catch( tk::Exception& e ) {
    // exception thrown, test ok
    // if any other type of exception is thrown, test fails with except
    // find  out if exception was thrown due to the correct reason
    ensure( std::string("wrong exception thrown: ") + e.what(),
            std::string( e.what() ).find( "must be between" ) !=
              std::string::npos );
  }
  #endif
}

//! Test if linear distributor throws on to high virtualization parameter
template<> template<>
void LoadDistributor_object::test< 3 >() {
  set_test_name( "linear throws on too high virt" );

  #ifdef NDEBUG        // exception only thrown in DEBUG mode
    skip( "in RELEASE mode, would yield floating point exception" );
  #else
  try {

    uint64_t chunksize, remainder;
    tk::linearLoadDistributor( 1.5, 1234, 2, chunksize, remainder );

  } catch( tk::Exception& e ) {
    // exception thrown, test ok
    // if any other type of exception is thrown, test fails with except
    // find  out if exception was thrown due to the correct reason
    ensure( std::string("wrong exception thrown: ") + e.what(),
            std::string( e.what() ).find( "must be between" ) !=
              std::string::npos );
  }
  #endif
}

//! Test if linear distributor returns number of chares less than or equal load
template<> template<>
void LoadDistributor_object::test< 4 >() {
  set_test_name( "linear returns sane nchare" );

  uint64_t nchare, chunksize, remainder;
  nchare = tk::linearLoadDistributor( 0.5, 1234, 2, chunksize, remainder );
  // nchare should never be larger than the load
  ensure( "number of chares too large", nchare < 1235 );
}


//! Test if linear distributor returns chunksize less than or equal the load
template<> template<>
void LoadDistributor_object::test< 5 >() {
  set_test_name( "linear returns sane chunksize" );

  uint64_t chunksize, remainder;
  tk::linearLoadDistributor( 0.0, 1234, 2, chunksize, remainder );
  // chunksize should never be larger than the load
  ensure( "chunksize too large", chunksize < 1235 );
}

//! Test if linear distributor returns remainder less than or equal to chunksize
template<> template<>
void LoadDistributor_object::test< 6 >() {
  set_test_name( "linear returns sane remainder" );

  uint64_t chunksize, remainder;
  tk::linearLoadDistributor( 1.0, 1234, 2, chunksize, remainder );
  // remainder should never be larger than chunksize
  ensure( "remainder too large",  remainder < chunksize );
}

//! Test if linear distributor throws on garbage number of processing elements
template<> template<>
void LoadDistributor_object::test< 7 >() {
  set_test_name( "linear throws on garbage npe" );

  #ifdef NDEBUG        // exception only thrown in DEBUG mode
    skip( "in RELEASE mode, would yield floating point exception" );
  #else
  try {

    uint64_t chunksize, remainder;
    tk::linearLoadDistributor( 0.5, 1234, 0, chunksize, remainder );

  } catch( tk::Exception& e ) {
    // exception thrown, test ok
    // if any other type of exception is thrown, test fails with except
    // find out if exception was thrown due to the correct reason
    ensure( std::string("wrong exception thrown: ") + e.what(),
            std::string( e.what() ).find( "must be larger" ) !=
              std::string::npos );
  }
  #endif
}

#if defined(__clang__)
  #pragma clang diagnostic pop
#elif defined(STRICT_GNUC)
  #pragma GCC diagnostic pop
#endif

} // tut::

#endif  // DOXYGEN_GENERATING_OUTPUT