29#include <gtest/gtest-spi.h>
30#include <gtest/gtest.h>
59TEST(StatsStatStorTest, SetValueResult)
76TEST(StatsStatStorTest, Prepare)
89TEST(StatsStatStorTest, IncDec)
117TEST(StatsStatStorTest, ZeroReset)
122 ASSERT_TRUE(stor.
zero());
125 ASSERT_TRUE(stor.
zero());
129 ASSERT_FALSE(stor.
zero());
133TEST(StatsAvgStorTest, SetValueResult)
167 ASSERT_DEATH(stor.result(),
".+");
233TEST(StatsAvgStorTest, ZeroReset)
238 ASSERT_TRUE(stor.
zero());
241 ASSERT_TRUE(stor.
zero());
249 ASSERT_FALSE(stor.
zero());
254TEST(StatsDistStorDeathTest, BucketSize0)
265TEST(StatsDistStorTest, ZeroReset)
272 ASSERT_TRUE(stor.
zero());
276 ASSERT_FALSE(stor.
zero());
279 ASSERT_TRUE(stor.
zero());
296 ASSERT_EQ(stor.
size(), size);
298 ASSERT_EQ(stor.
size(), size);
300 ASSERT_EQ(stor.
size(), size);
302 ASSERT_EQ(stor.
size(), size);
304 ASSERT_EQ(stor.
size(), size);
318 ASSERT_EQ(
data.type, expected_data.
type);
319 ASSERT_EQ(
data.min, expected_data.
min);
320 ASSERT_EQ(
data.max, expected_data.
max);
324 ASSERT_EQ(
data.sum, expected_data.
sum);
327 ASSERT_EQ(
data.logs, expected_data.
logs);
330 ASSERT_EQ(
data.cvec.size(), expected_data.
cvec.size());
331 for (
int i = 0;
i < expected_data.
cvec.size();
i++) {
332 ASSERT_EQ(
data.cvec[
i], expected_data.
cvec[
i]);
355 expected_data.
min = params.
min;
356 expected_data.
max = params.
max;
357 expected_data.
sum = 0;
359 expected_data.
logs = 0;
363 for (
int i = 0;
i < num_values;
i++) {
364 stor.
sample(values[
i].value, values[
i].numSamples);
378TEST(StatsDistStorTest, SamplePrepareSingle)
393 expected_data.
cvec.clear();
395 expected_data.
cvec[2] = 5;
401TEST(StatsDistStorTest, SamplePrepareMultiple)
411 ValueSamples values[] = {{10, 5}, {1234, 2}, {12345678, 99}, {-10, 4},
412 {17, 17}, {52, 63}, {18, 11}, {0, 1}, {99, 15}, {-1, 200}, {100, 50}};
419 expected_data.
max_val = 12345678;
423 expected_data.
sum = 0;
426 expected_data.
cvec.clear();
428 expected_data.
cvec[0] = 1;
429 expected_data.
cvec[2] = 5;
430 expected_data.
cvec[3] = 17+11;
431 expected_data.
cvec[10] = 63;
432 expected_data.
cvec[19] = 15;
444 ValueSamples values[] = {{10, 5}, {1234, 2}, {12345678, 99}, {-10, 4},
445 {17, 17}, {52, 63}, {18, 11}, {0, 1}, {99, 15}, {-1, 200}, {100, 50}};
447 for (
int i = 0;
i < num_values;
i++) {
448 stor.
sample(values[
i].value, values[
i].numSamples);
461 expected_data.
min = params.
min;
462 expected_data.
max = params.
max;
465 expected_data.
sum = 0;
468 expected_data.
cvec.clear();
476TEST(StatsHistStorDeathTest, NotEnoughBuckets0)
482TEST(StatsHistStorDeathTest, NotEnoughBuckets1)
493TEST(StatsHistStorTest, ZeroReset)
500 ASSERT_TRUE(stor.
zero());
504 ASSERT_FALSE(stor.
zero());
507 ASSERT_TRUE(stor.
zero());
525 ASSERT_EQ(stor.
size(), sizes[
i]);
527 ASSERT_EQ(stor.
size(), sizes[
i]);
529 ASSERT_EQ(stor.
size(), sizes[
i]);
531 ASSERT_EQ(stor.
size(), sizes[
i]);
533 ASSERT_EQ(stor.
size(), sizes[
i]);
559 expected_data.
sum = 0;
561 expected_data.
logs = 0;
565 for (
int i = 0;
i < num_values;
i++) {
566 stor.
sample(values[
i].value, values[
i].numSamples);
571 if (values[
i].value < 0) {
575 expected_data.
logs +=
588TEST(StatsHistStorTest, SamplePrepareFit)
595 ValueSamples values[] = {{0, 5}, {1, 2}, {2, 99}, {3, 4}};
596 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
600 expected_data.
min = 0;
602 expected_data.
cvec.clear();
604 expected_data.
cvec[0] = 5;
605 expected_data.
cvec[1] = 2;
606 expected_data.
cvec[2] = 99;
607 expected_data.
cvec[3] = 4;
616TEST(StatsHistStorTest, SamplePrepareSingleGrowUp)
624 ValueSamples values[] = {{0, 5}, {1, 2}, {2, 99}, {4, 4}};
625 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
629 expected_data.
min = 0;
631 expected_data.
cvec.clear();
633 expected_data.
cvec[0] = 5+2;
634 expected_data.
cvec[1] = 99;
635 expected_data.
cvec[2] = 4;
636 expected_data.
cvec[3] = 0;
645TEST(StatsHistStorTest, SamplePrepareMultipleGrowUp)
653 ValueSamples values[] = {{0, 5}, {1, 2}, {2, 99}, {16, 4}};
654 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
658 expected_data.
min = 0;
660 expected_data.
cvec.clear();
662 expected_data.
cvec[0] = 5+2+99;
663 expected_data.
cvec[1] = 0;
664 expected_data.
cvec[2] = 4;
665 expected_data.
cvec[3] = 0;
675TEST(StatsHistStorTest, SamplePrepareGrowDownOddBuckets)
684 {{0, 5}, {1, 2}, {2, 99}, {3, 12}, {4, 33}, {-1, 4}};
685 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
689 expected_data.
min = -4;
691 expected_data.
cvec.clear();
693 expected_data.
cvec[0] = 0;
694 expected_data.
cvec[1] = 4;
695 expected_data.
cvec[2] = 5+2;
696 expected_data.
cvec[3] = 99+12;
697 expected_data.
cvec[4] = 33;
707TEST(StatsHistStorTest, SamplePrepareGrowDownEvenBuckets)
715 ValueSamples values[] = {{0, 5}, {1, 2}, {2, 99}, {-1, 4}};
716 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
720 expected_data.
min = -4;
722 expected_data.
cvec.clear();
724 expected_data.
cvec[0] = 0;
725 expected_data.
cvec[1] = 4;
726 expected_data.
cvec[2] = 5+2;
727 expected_data.
cvec[3] = 99;
737TEST(StatsHistStorTest, SamplePrepareGrowDownGrowOutOddBuckets)
746 {{0, 5}, {1, 2}, {2, 99}, {3, 12}, {4, 33}, {-12, 4}};
747 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
751 expected_data.
min = -16;
753 expected_data.
cvec.clear();
755 expected_data.
cvec[0] = 4;
756 expected_data.
cvec[1] = 0;
757 expected_data.
cvec[2] = 5+2+99+12+33;
758 expected_data.
cvec[3] = 0;
759 expected_data.
cvec[4] = 0;
769TEST(StatsHistStorTest, SamplePrepareGrowDownGrowOutEvenBuckets)
778 {{0, 5}, {1, 2}, {2, 99}, {3, 12}, {-12, 4}};
779 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
783 expected_data.
min = -16;
785 expected_data.
cvec.clear();
787 expected_data.
cvec[0] = 4;
788 expected_data.
cvec[1] = 0;
789 expected_data.
cvec[2] = 5+2+99+12;
790 expected_data.
cvec[3] = 0;
800TEST(StatsHistStorTest, SamplePrepareMultipleGrowOddBuckets)
810 {{0, 5}, {7, 2}, {31, 99}, {-8, 12}, {127, 4}, {-120, 53}, {-50, 1}};
811 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
815 expected_data.
min = -128;
817 expected_data.
cvec.clear();
819 expected_data.
cvec[0] = 53;
820 expected_data.
cvec[1] = 12+1;
821 expected_data.
cvec[2] = 5+2+99;
822 expected_data.
cvec[3] = 4;
823 expected_data.
cvec[4] = 0;
833TEST(StatsHistStorTest, SamplePrepareMultipleGrowEvenBuckets)
842 {{0, 5}, {7, 2}, {31, 99}, {-8, 12}, {127, 4}, {-120, 53}, {-50, 1}};
843 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
847 expected_data.
min = -128;
849 expected_data.
cvec.clear();
851 expected_data.
cvec[0] = 53;
852 expected_data.
cvec[1] = 12+1;
853 expected_data.
cvec[2] = 5+2+99;
854 expected_data.
cvec[3] = 4;
870 {{0, 5}, {7, 2}, {31, 99}, {-8, 12}, {127, 4}, {-120, 53}, {-50, 1}};
871 const int num_values =
sizeof(values) /
sizeof(
ValueSamples);
872 for (
int i = 0;
i < num_values;
i++) {
873 stor.
sample(values[
i].value, values[
i].numSamples);
882 expected_data.
min = 0;
884 expected_data.
cvec.clear();
891TEST(StatsHistStorDeathTest, AddDifferentSize)
899 ASSERT_DEATH(stor.add(&stor2),
".+");
903TEST(StatsHistStorDeathTest, AddDifferentMin)
913 ASSERT_DEATH(stor.add(&stor2),
".+");
925 ValueSamples values[] = {{0, 5}, {3, 2}, {20, 37}, {32, 18}};
927 for (
int i = 0;
i < num_values;
i++) {
928 stor.
sample(values[
i].value, values[
i].numSamples);
936 ValueSamples values2[] = {{10, 10}, {0, 1}, {80, 4}, {17, 100}, {95, 79}};
937 int num_values2 =
sizeof(values2) /
sizeof(
ValueSamples);
938 for (
int i = 0;
i < num_values2;
i++) {
939 stor2.
sample(values2[
i].value, values2[
i].numSamples);
947 stor.
prepare(¶ms, merge_data);
954 expected_data.
min = 0;
955 expected_data.
max = 127;
958 expected_data.
cvec.clear();
960 expected_data.
cvec[0] = 5+2+37+10+1+100;
961 expected_data.
cvec[1] = 18;
962 expected_data.
cvec[2] = 4+79;
963 expected_data.
cvec[3] = 0;
978TEST(StatsSampleStorTest, ZeroReset)
984 ASSERT_TRUE(stor.
zero());
988 ASSERT_FALSE(stor.
zero());
991 ASSERT_TRUE(stor.
zero());
995TEST(StatsSampleStorTest, SamplePrepare)
998 ValueSamples values[] = {{10, 5}, {1234, 2}, {0xFFFFFFFF, 18}};
1006 stor.
sample(values[0].value, values[0].numSamples);
1013 ASSERT_EQ(
data.type, expected_data.
type);
1014 ASSERT_EQ(
data.sum, expected_data.
sum);
1019 expected_data.
sum = 0;
1022 stor.
reset(
nullptr);
1024 ASSERT_EQ(
data.type, expected_data.
type);
1025 ASSERT_EQ(
data.sum, expected_data.
sum);
1030 for (
int i = 0;
i < num_values;
i++) {
1031 stor.
sample(values[
i].value, values[
i].numSamples);
1034 expected_data.
sum +=
val;
1039 ASSERT_EQ(
data.type, expected_data.
type);
1040 ASSERT_EQ(
data.sum, expected_data.
sum);
1054 ASSERT_EQ(stor.
size(), 1);
1056 ASSERT_EQ(stor.
size(), 1);
1058 ASSERT_EQ(stor.
size(), 1);
1059 stor.
reset(
nullptr);
1060 ASSERT_EQ(stor.
size(), 1);
1062 ASSERT_EQ(stor.
size(), 1);
1070TEST(StatsAvgSampleStorTest, ZeroReset)
1076 ASSERT_TRUE(stor.
zero());
1078 stor.
reset(
nullptr);
1080 ASSERT_FALSE(stor.
zero());
1082 stor.
reset(
nullptr);
1083 ASSERT_TRUE(stor.
zero());
1087TEST(StatsAvgSampleStorTest, SamplePrepare)
1090 ValueSamples values[] = {{10, 5}, {1234, 2}, {0xFFFFFFFF, 18}};
1091 int num_values =
sizeof(values) /
sizeof(
ValueSamples);
1098 stor.
sample(values[0].value, values[0].numSamples);
1104 ASSERT_EQ(
data.type, expected_data.
type);
1105 ASSERT_EQ(
data.sum, expected_data.
sum);
1112 expected_data.
sum = 0;
1114 stor.
reset(
nullptr);
1116 ASSERT_EQ(
data.type, expected_data.
type);
1117 ASSERT_EQ(
data.sum, expected_data.
sum);
1124 for (
int i = 0;
i < num_values;
i++) {
1125 stor.
sample(values[
i].value, values[
i].numSamples);
1128 expected_data.
sum +=
val;
1132 ASSERT_EQ(
data.type, expected_data.
type);
1133 ASSERT_EQ(
data.sum, expected_data.
sum);
1147 ASSERT_EQ(stor.
size(), 1);
1149 ASSERT_EQ(stor.
size(), 1);
1151 ASSERT_EQ(stor.
size(), 1);
1152 stor.
reset(
nullptr);
1153 ASSERT_EQ(stor.
size(), 1);
1155 ASSERT_EQ(stor.
size(), 1);
1163TEST(StatsSparseHistStorTest, ZeroReset)
1169 ASSERT_TRUE(stor.
zero());
1171 stor.
reset(
nullptr);
1173 ASSERT_FALSE(stor.
zero());
1175 stor.
reset(
nullptr);
1176 ASSERT_TRUE(stor.
zero());
1180TEST(StatsSparseHistStorTest, SamplePrepare)
1183 ValueSamples values[] = {{10, 5}, {1234, 2}, {0xFFFFFFFF, 18}};
1184 int num_values =
sizeof(values) /
sizeof(
ValueSamples);
1189 stor.
sample(values[0].value, values[0].numSamples);
1191 ASSERT_EQ(stor.
size(), 1);
1192 ASSERT_EQ(
data.cmap.size(), 1);
1197 stor.
reset(
nullptr);
1199 ASSERT_EQ(stor.
size(), 0);
1200 ASSERT_EQ(
data.cmap.size(), 0);
1201 ASSERT_EQ(
data.samples, 0);
1204 for (
int i = 0;
i < num_values;
i++) {
1205 stor.
sample(values[
i].value, values[
i].numSamples);
1209 ASSERT_EQ(stor.
size(), num_values);
1210 ASSERT_EQ(
data.cmap.size(), num_values);
1211 for (
int i = 0;
i < num_values;
i++) {
1215 ASSERT_EQ(
data.samples, total_samples);
void setCurTick(Tick tick)
Assign a value to the current simulation tick.
Templatized storage for distribution that calculates per tick mean and variance.
bool zero() const
Return true if no samples have been added.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
size_type size() const
Return the number of entries, in this case 1.
void prepare(const StorageParams *const storage_params, DistData &data)
Templatized storage and interface to a per-tick average stat.
Counter value() const
Return the current count.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
void inc(Counter val)
Increment the current count by the provided value, calls set.
Result result() const
Return the current average.
void dec(Counter val)
Deccrement the current count by the provided value, calls set.
void prepare(const StorageParams *const storage_params)
Prepare stat data for dumping or serialization.
void set(Counter val)
Set the current count to the one provided, update the total and last set values.
Templatized storage and interface for a distribution stat.
size_type size() const
Return the number of buckets in this distribution.
void prepare(const StorageParams *const storage_params, DistData &data)
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
bool zero() const
Returns true if any calls to sample have been made.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
Templatized storage and interface for a histogram stat.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
void add(HistStor *other)
Adds the contents of the given storage to this storage.
size_type size() const
Return the number of buckets in this distribution.
bool zero() const
Returns true if any calls to sample have been made.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
void prepare(const StorageParams *const storage_params, DistData &data)
Templatized storage and interface for a distribution that calculates mean and variance.
size_type size() const
Return the number of entries in this stat, 1.
bool zero() const
Return true if no samples have been added.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
void prepare(const StorageParams *const storage_params, DistData &data)
void sample(Counter val, int number)
Add a value the given number of times to this running average.
Templatized storage and interface for a sparse histogram stat.
size_type size() const
Return the number of buckets in this distribution.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
void prepare(const StorageParams *const storage_params, SparseHistData &data)
bool zero() const
Returns true if any calls to sample have been made.
Templatized storage and interface for a simple scalar stat.
void prepare(const StorageParams *const storage_params)
Prepare stat data for dumping or serialization.
Result result() const
Return the value of this stat as a result type.
void dec(Counter val)
Decrement the stat by the given value.
Counter value() const
Return the value of this stat as its base type.
void set(Counter val)
The the stat to the given value.
void inc(Counter val)
Increment the stat by the given value.
void reset(const StorageParams *const storage_params)
Reset stat value to default.
const FlagsType total
Print the total.
double Counter
All counters are of 64-bit values.
double Result
All results are doubles.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Tick curTick()
The universal simulation clock.
uint64_t Tick
Tick count type.
void increaseTick()
Increases the current tick by one.
void prepareCheckHistStor(statistics::HistStor::Params ¶ms, ValueSamples *values, int num_values, statistics::DistData &expected_data)
Auxiliary function that finishes preparing the HistStor's expected values, perform the calls to the s...
TEST(StatsStatStorTest, SetValueResult)
Test setting and getting a value to the storage.
void checkExpectedDistData(const statistics::DistData &data, const statistics::DistData &expected_data, bool no_log=true)
Compare both dist datas to see if their contents match.
GTestTickHandler tickHandler
void prepareCheckDistStor(statistics::DistStor::Params ¶ms, ValueSamples *values, int num_values, statistics::DistData &expected_data)
Auxiliary function that finishes preparing the DistStor's expected values, perform the calls to the s...
A pair of value and its number of samples, used for sampling.
ValueSamples(statistics::Counter value, statistics::Counter num_samples)
statistics::Counter numSamples
statistics::Counter value
General container for distribution data.
The parameters for a distribution stat.
size_type buckets
The number of buckets.
Counter max
The maximum value to track.
Counter bucket_size
The number of entries in each bucket.
Counter min
The minimum value to track.
The parameters for a distribution stat.
size_type buckets
The number of buckets.
Data structure of sparse histogram.