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
|
/**
* @file llsingleton_test.cpp
* @date 2011-08-11
* @brief Unit test for the LLSingleton class
*
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2011, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lltrace.h"
#include "lltracethreadrecorder.h"
#include "lltracerecording.h"
#include "../test/lltut.h"
namespace LLUnits
{
// using powers of 2 to allow strict floating point equality
LL_DECLARE_BASE_UNIT(Ounces, "oz");
LL_DECLARE_DERIVED_UNIT(TallCup, "", Ounces, / 12);
LL_DECLARE_DERIVED_UNIT(GrandeCup, "", Ounces, / 16);
LL_DECLARE_DERIVED_UNIT(VentiCup, "", Ounces, / 20);
LL_DECLARE_BASE_UNIT(Grams, "g");
LL_DECLARE_DERIVED_UNIT(Milligrams, "mg", Grams, * 1000);
}
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Ounces);
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, TallCup);
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, GrandeCup);
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, VentiCup);
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Grams);
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Milligrams);
namespace tut
{
using namespace LLTrace;
struct trace
{
ThreadRecorder mRecorder;
};
typedef test_group<trace> trace_t;
typedef trace_t::object trace_object_t;
tut::trace_t tut_singleton("LLTrace");
static CountStatHandle<S32> sCupsOfCoffeeConsumed("coffeeconsumed", "Delicious cup of dark roast.");
static SampleStatHandle<F32Milligrams> sCaffeineLevelStat("caffeinelevel", "Coffee buzz quotient");
static EventStatHandle<S32Ounces> sOuncesPerCup("cupsize", "Large, huge, or ginormous");
static F32 sCaffeineLevel(0.f);
const F32Milligrams sCaffeinePerOz(18.f);
void drink_coffee(S32 num_cups, S32Ounces cup_size)
{
add(sCupsOfCoffeeConsumed, num_cups);
for (S32 i = 0; i < num_cups; i++)
{
record(sOuncesPerCup, cup_size);
}
sCaffeineLevel += F32Ounces(num_cups * cup_size).value() * sCaffeinePerOz.value();
sample(sCaffeineLevelStat, sCaffeineLevel);
}
// basic data collection
template<> template<>
void trace_object_t::test<1>()
{
sample(sCaffeineLevelStat, sCaffeineLevel);
Recording all_day;
Recording at_work;
Recording after_3pm;
all_day.start();
{
// warm up with one grande cup
drink_coffee(1, S32TallCup(1));
// go to work
at_work.start();
{
// drink 3 tall cups, 1 after 3 pm
drink_coffee(2, S32GrandeCup(1));
after_3pm.start();
drink_coffee(1, S32GrandeCup(1));
}
at_work.stop();
drink_coffee(1, S32VentiCup(1));
}
after_3pm.stop();
all_day.stop();
ensure("count stats are counted when recording is active",
at_work.getSum(sCupsOfCoffeeConsumed) == 3
&& all_day.getSum(sCupsOfCoffeeConsumed) == 5
&& after_3pm.getSum(sCupsOfCoffeeConsumed) == 2);
ensure("measurement sums are counted when recording is active",
at_work.getSum(sOuncesPerCup) == S32Ounces(48)
&& all_day.getSum(sOuncesPerCup) == S32Ounces(80)
&& after_3pm.getSum(sOuncesPerCup) == S32Ounces(36));
ensure("measurement min is specific to when recording is active",
at_work.getMin(sOuncesPerCup) == S32GrandeCup(1)
&& all_day.getMin(sOuncesPerCup) == S32TallCup(1)
&& after_3pm.getMin(sOuncesPerCup) == S32GrandeCup(1));
ensure("measurement max is specific to when recording is active",
at_work.getMax(sOuncesPerCup) == S32GrandeCup(1)
&& all_day.getMax(sOuncesPerCup) == S32VentiCup(1)
&& after_3pm.getMax(sOuncesPerCup) == S32VentiCup(1));
ensure("sample min is specific to when recording is active",
at_work.getMin(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1)).value()
&& all_day.getMin(sCaffeineLevelStat) == F32Milligrams(0.f)
&& after_3pm.getMin(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(2)).value());
ensure("sample max is specific to when recording is active",
at_work.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3)).value()
&& all_day.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3) + (S32Ounces)S32VentiCup(1)).value()
&& after_3pm.getMax(sCaffeineLevelStat) == sCaffeinePerOz * ((S32Ounces)S32TallCup(1) + (S32Ounces)S32GrandeCup(3) + (S32Ounces)S32VentiCup(1)).value());
}
}
|