forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sampling.c
68 lines (51 loc) · 1.92 KB
/
test_sampling.c
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
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include "util_random.h"
#include "util_sampling.h"
#include "tlib_main.h"
static void test_no_random_generator(void) {
nr_sampling_priority_t p = nr_generate_initial_priority(NULL);
tlib_pass_if_false("NULL random number generator generates invalid priority",
nr_priority_is_valid(p), "p=%f", p);
}
static void test_with_random_generator(nr_random_t* rnd) {
nr_sampling_priority_t p;
p = nr_generate_initial_priority(rnd);
tlib_pass_if_true(
"well-formed random number generator generates valid initial priority",
nr_priority_is_valid(p), "p=%f", p);
}
static void test_comparison(nr_random_t* rnd) {
nr_sampling_priority_t p;
p = nr_generate_initial_priority(rnd);
tlib_pass_if_true("p is higher", nr_is_higher_priority(p, NR_PRIORITY_LOWEST),
"p=%f", p);
tlib_pass_if_false("p is lower",
nr_is_higher_priority(p, NR_PRIORITY_HIGHEST), "p=%f", p);
tlib_pass_if_false("p is equal to p, thus lower", nr_is_higher_priority(p, p),
"p=%f", p);
}
static void test_validity(void) {
nr_sampling_priority_t p = 0.00001;
tlib_pass_if_true("p is valid", nr_priority_is_valid(p), "p=%f", p);
p = 0.99999;
tlib_pass_if_true("p is valid", nr_priority_is_valid(p), "p=%f", p);
p = NR_PRIORITY_LOWEST;
tlib_pass_if_true("p is valid", nr_priority_is_valid(p), "p=%f", p);
p = NR_PRIORITY_HIGHEST;
tlib_pass_if_false("p is invalid", nr_priority_is_valid(p), "p=%f", p);
}
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
void test_main(void* p NRUNUSED) {
nr_random_t* rnd;
rnd = nr_random_create();
nr_random_seed(rnd, 345345);
test_no_random_generator();
test_with_random_generator(rnd);
test_comparison(rnd);
test_validity();
nr_random_destroy(&rnd);
}