diff options
author | Slawek Figiel <slawek@isc.org> | 2024-02-09 12:49:40 +0100 |
---|---|---|
committer | Slawek Figiel <slawek@isc.org> | 2024-02-20 09:33:35 +0100 |
commit | cf888310fc06c8e37cfb3110fd67bf568370cf6e (patch) | |
tree | 6bf9018cdaf9a899d57b07209f0be866b8c0d566 /src | |
parent | [#3207] Add a wrapper for boost rand generator (diff) | |
download | kea-cf888310fc06c8e37cfb3110fd67bf568370cf6e.tar.xz kea-cf888310fc06c8e37cfb3110fd67bf568370cf6e.zip |
[#3207] Remove old implementation
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/perfdhcp/Makefile.am | 1 | ||||
-rw-r--r-- | src/bin/perfdhcp/random_number_generator.h | 62 | ||||
-rw-r--r-- | src/bin/perfdhcp/test_control.h | 2 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/Makefile.am | 5 | ||||
-rw-r--r-- | src/bin/perfdhcp/tests/random_number_generator_unittest.cc | 59 |
5 files changed, 3 insertions, 126 deletions
diff --git a/src/bin/perfdhcp/Makefile.am b/src/bin/perfdhcp/Makefile.am index 63fa8352f9..b6d6169279 100644 --- a/src/bin/perfdhcp/Makefile.am +++ b/src/bin/perfdhcp/Makefile.am @@ -25,7 +25,6 @@ libperfdhcp_la_SOURCES += pkt_transform.cc pkt_transform.h libperfdhcp_la_SOURCES += rate_control.cc rate_control.h libperfdhcp_la_SOURCES += stats_mgr.cc stats_mgr.h libperfdhcp_la_SOURCES += test_control.cc test_control.h -libperfdhcp_la_SOURCES += random_number_generator.h libperfdhcp_la_SOURCES += receiver.cc receiver.h libperfdhcp_la_SOURCES += perf_socket.cc perf_socket.h libperfdhcp_la_SOURCES += abstract_scen.h diff --git a/src/bin/perfdhcp/random_number_generator.h b/src/bin/perfdhcp/random_number_generator.h deleted file mode 100644 index 419b37eec5..0000000000 --- a/src/bin/perfdhcp/random_number_generator.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2010-2024 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef NSAS_RANDOM_NUMBER_GENERATOR_H -#define NSAS_RANDOM_NUMBER_GENERATOR_H - -#include <algorithm> -#include <cmath> -#include <iterator> -#include <numeric> -#include <vector> - -#include <exceptions/exceptions.h> - -#include <boost/random/mersenne_twister.hpp> -#include <boost/random/uniform_int.hpp> -#include <boost/random/uniform_real.hpp> -#include <boost/random/variate_generator.hpp> - -/// PLEASE DO NOT USE THIS IN CRYPTOGRAPHICALLY SENSITIVE CODE. - -namespace isc { -namespace perfdhcp { - -/// \brief Uniform random integer generator -/// -/// Generate uniformly distributed integers in range of [min, max] -class UniformRandomIntegerGenerator{ -public: - /// \brief Constructor - /// - /// \param min The minimum number in the range - /// \param max The maximum number in the range - UniformRandomIntegerGenerator(int min, int max): - min_(std::min(min, max)), max_(std::max(min, max)), - dist_(min_, max_), generator_(rng_, dist_) - { - // Init with the current time - rng_.seed(time(0)); - } - - /// \brief Generate uniformly distributed integer - int operator()() { return generator_(); } -private: - /// Hide default and copy constructor - UniformRandomIntegerGenerator();///< Default constructor - UniformRandomIntegerGenerator(const UniformRandomIntegerGenerator&); ///< Copy constructor - - int min_; ///< The minimum integer that can generate - int max_; ///< The maximum integer that can generate - boost::uniform_int<> dist_; ///< Distribute uniformly. - boost::mt19937 rng_; ///< Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator - boost::variate_generator<boost::mt19937&, boost::uniform_int<> > generator_; ///< Uniform generator -}; - -} // namespace perfdhcp -} // namespace isc - -#endif//NSAS_RANDOM_NUMBER_GENERATOR_H diff --git a/src/bin/perfdhcp/test_control.h b/src/bin/perfdhcp/test_control.h index 650d43eb75..87955532bf 100644 --- a/src/bin/perfdhcp/test_control.h +++ b/src/bin/perfdhcp/test_control.h @@ -196,7 +196,7 @@ public: NumberGenerator(), distribution(min, max) { // Initialize the randomness source with the current time. - randomnessGenerator.seed(time(NULL)); + randomnessGenerator.seed(time(0)); } /// \brief Generate number in range of [min, max]. diff --git a/src/bin/perfdhcp/tests/Makefile.am b/src/bin/perfdhcp/tests/Makefile.am index 4de5e30bf9..35ad72e80c 100644 --- a/src/bin/perfdhcp/tests/Makefile.am +++ b/src/bin/perfdhcp/tests/Makefile.am @@ -11,13 +11,13 @@ if USE_STATIC_LINK AM_LDFLAGS = -static endif +TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) + CLEANFILES = *.gcno *.gcda # The test[1-5].hex are created by the TestControl.PacketTemplates # unit tests and have to be removed. CLEANFILES += test1.hex test2.hex test3.hex test4.hex test5.hex -TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND) - TESTS = if HAVE_GTEST TESTS += run_unittests @@ -35,7 +35,6 @@ run_unittests_SOURCES += perf_socket_unittest.cc run_unittests_SOURCES += basic_scen_unittest.cc run_unittests_SOURCES += avalanche_scen_unittest.cc run_unittests_SOURCES += command_options_helper.h -run_unittests_SOURCES += random_number_generator_unittest.cc run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) run_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS) diff --git a/src/bin/perfdhcp/tests/random_number_generator_unittest.cc b/src/bin/perfdhcp/tests/random_number_generator_unittest.cc deleted file mode 100644 index be7abe432a..0000000000 --- a/src/bin/perfdhcp/tests/random_number_generator_unittest.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2010-2021 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include <config.h> - -#include <perfdhcp/random_number_generator.h> - -#include <gtest/gtest.h> -#include <boost/shared_ptr.hpp> - -#include <iostream> - -using namespace isc; -using namespace isc::perfdhcp; -using namespace std; - -/// \brief Test Fixture Class for uniform random number generator -/// -/// The hard part for this test is how to test that the number is random? -/// and how to test that the number is uniformly distributed? -/// Or maybe we can trust the boost implementation -class UniformRandomIntegerGeneratorTest : public ::testing::Test { -public: - UniformRandomIntegerGeneratorTest(): - gen_(min_, max_) - { - } - virtual ~UniformRandomIntegerGeneratorTest(){} - - int gen() { return (gen_()); } - int max() const { return (max_); } - int min() const { return (min_); } - -private: - UniformRandomIntegerGenerator gen_; - - const static int min_ = 1; - const static int max_ = 10; -}; - -// Test of the generated integers are in the range [min, max] -TEST_F(UniformRandomIntegerGeneratorTest, IntegerRange) { - vector<int> numbers; - - // Generate a lot of random integers - for (int i = 0; i < max()*10; ++i) { - numbers.push_back(gen()); - } - - // Remove the duplicated values - sort(numbers.begin(), numbers.end()); - vector<int>::iterator it = unique(numbers.begin(), numbers.end()); - - // make sure the numbers are in range [min, max] - ASSERT_EQ(it - numbers.begin(), max() - min() + 1); -} |