forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate TestRandomGenerator from utility_lib (envoyproxy#25050)
Commit Message: Separate TestRandomGenerator from utility_lib Additional Description: This is a precursor cleanup to envoyproxy#24994. When adding stat() to Filesystem operations, the fake file system will need to keep track of file timestamps. As such, it needs access to a TimeSource to generate those timestamps, i.e. simulated_time_system.h. However, utility.h depends on the Memfile filesystem, and simulated_time_system depended on utility.h, so this creates a circular dependency. simulated_time_system only actually wants random numbers and thread_factory from utility.h, so separating TestRandomGenerator into its own library allows for a reduction in the dependency chain size and a solution to that otherwise-upcoming circular dependency. Risk Level: None, this is test-only and no-op. Testing: Test-only and no-op. Docs Changes: n/a Release Notes: n/a Platform Specific Features: n/a Signed-off-by: Raven Black <[email protected]>
- Loading branch information
1 parent
a9e6031
commit 6fffa40
Showing
11 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "test/test_common/test_random_generator.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
using testing::GTEST_FLAG(random_seed); | ||
|
||
namespace Envoy { | ||
|
||
// The purpose of using the static seed here is to use --test_arg=--gtest_random_seed=[seed] | ||
// to specify the seed of the problem to replay. | ||
int32_t getSeed() { | ||
static const int32_t seed = std::chrono::duration_cast<std::chrono::nanoseconds>( | ||
std::chrono::system_clock::now().time_since_epoch()) | ||
.count(); | ||
return seed; | ||
} | ||
|
||
TestRandomGenerator::TestRandomGenerator() | ||
: seed_(GTEST_FLAG(random_seed) == 0 ? getSeed() : GTEST_FLAG(random_seed)), generator_(seed_) { | ||
ENVOY_LOG_MISC(info, "TestRandomGenerator running with seed {}", seed_); | ||
} | ||
|
||
uint64_t TestRandomGenerator::random() { return generator_(); } | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <random> | ||
|
||
#include "source/common/common/utility.h" | ||
|
||
namespace Envoy { | ||
|
||
// Random number generator which logs its seed to stderr. To repeat a test run with a non-zero seed | ||
// one can run the test with --test_arg=--gtest_random_seed=[seed] | ||
class TestRandomGenerator { | ||
public: | ||
TestRandomGenerator(); | ||
|
||
uint64_t random(); | ||
|
||
private: | ||
const int32_t seed_; | ||
std::ranlux48 generator_; | ||
}; | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters