forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_globals.c
62 lines (43 loc) · 1.37 KB
/
test_globals.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
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "tlib_php.h"
#include "php_agent.h"
#include "php_globals.h"
tlib_parallel_info_t parallel_info
= {.suggested_nthreads = -1, .state_size = 0};
static void test_init(void) {
nrphpglobals_t zeroed;
// Basically, we'll set the per process globals to junk, call init, and
// verify that they're all 0.
nr_memset(&nr_php_per_process_globals, 42, sizeof(nrphpglobals_t));
nr_memset(&zeroed, 0, sizeof(nrphpglobals_t));
nr_php_global_init();
tlib_pass_if_int_equal(
"all bytes are zero", 0,
nr_memcmp(&zeroed, &nr_php_per_process_globals, sizeof(nrphpglobals_t)));
nr_php_global_destroy();
}
static int once_called = 0;
static void increment_once_called(void) {
++once_called;
}
static void test_once(void) {
nr_php_global_init();
once_called = 0;
nr_php_global_once(increment_once_called);
nr_php_global_once(increment_once_called);
tlib_pass_if_int_equal("check once called state", 1, once_called);
nr_php_global_destroy();
nr_php_global_init();
once_called = 0;
nr_php_global_once(increment_once_called);
nr_php_global_once(increment_once_called);
tlib_pass_if_int_equal("check once called state", 1, once_called);
nr_php_global_destroy();
}
void test_main(void* p NRUNUSED) {
test_init();
test_once();
}