-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathtest_php_wrapper.c
773 lines (691 loc) · 29.2 KB
/
test_php_wrapper.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "tlib_php.h"
#include "php_agent.h"
#include "php_call.h"
#include "php_wrapper.h"
tlib_parallel_info_t parallel_info
= {.suggested_nthreads = -1, .state_size = 0};
#if ZEND_MODULE_API_NO >= ZEND_7_3_X_API_NO
/*
* endif to match:
* ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
* && !defined OVERWRITE_ZEND_EXECUTE_DATA
*/
NR_PHP_WRAPPER(test_add_array) {
zval* arg = nr_php_zval_alloc();
(void)wraprec;
array_init(arg);
nr_php_arg_add(NR_EXECUTE_ORIG_ARGS, arg);
nr_php_zval_free(&arg);
NR_PHP_WRAPPER_CALL;
}
NR_PHP_WRAPPER_END
NR_PHP_WRAPPER(test_add_2_arrays) {
zval* arg = NULL;
(void)wraprec;
arg = nr_php_zval_alloc();
array_init(arg);
nr_php_arg_add(NR_EXECUTE_ORIG_ARGS, arg);
nr_php_zval_free(&arg);
arg = nr_php_zval_alloc();
array_init(arg);
nr_php_arg_add(NR_EXECUTE_ORIG_ARGS, arg);
nr_php_zval_free(&arg);
NR_PHP_WRAPPER_CALL;
}
NR_PHP_WRAPPER_END
#if ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO
NR_PHP_WRAPPER(test_name_txn_before_not_ok) {
nr_txn_set_path("UnitTest", NRPRG(txn), wraprec->funcname,
NR_PATH_TYPE_ACTION, NR_NOT_OK_TO_OVERWRITE);
NR_PHP_WRAPPER_CALL;
}
NR_PHP_WRAPPER_END
NR_PHP_WRAPPER(test_name_txn_before_ok) {
nr_txn_set_path("UnitTest", NRPRG(txn), wraprec->funcname,
NR_PATH_TYPE_ACTION, NR_OK_TO_OVERWRITE);
NR_PHP_WRAPPER_CALL;
}
NR_PHP_WRAPPER_END
NR_PHP_WRAPPER(test_name_txn_after_not_ok) {
NR_PHP_WRAPPER_CALL;
nr_txn_set_path("UnitTest", NRPRG(txn), wraprec->funcname,
NR_PATH_TYPE_ACTION, NR_NOT_OK_TO_OVERWRITE);
}
NR_PHP_WRAPPER_END
NR_PHP_WRAPPER(test_name_txn_after_ok) {
NR_PHP_WRAPPER_CALL;
nr_txn_set_path("UnitTest", NRPRG(txn), wraprec->funcname,
NR_PATH_TYPE_ACTION, NR_OK_TO_OVERWRITE);
}
NR_PHP_WRAPPER_END
static void populate_functions() {
tlib_php_request_eval("function three($a) { return $a; }" TSRMLS_CC);
tlib_php_request_eval("function two($a) { return three($a); }" TSRMLS_CC);
tlib_php_request_eval("function one($a) { return two($a); }" TSRMLS_CC);
}
/*
* This function is meant to wrap/test when only ONE before/after special
* callback is chosen for one, two, and three. If one_before is configured,
* one_after must be NULL.
*/
static void execute_nested_framework_calls(nrspecialfn_t one_before,
nrspecialfn_t one_after,
nrspecialfn_t two_before,
nrspecialfn_t two_after,
nrspecialfn_t three_before,
nrspecialfn_t three_after,
char* expected_name,
char* message) {
zval* expr = NULL;
zval* arg = NULL;
tlib_php_engine_create("" PTSRMLS_CC);
tlib_php_request_start();
populate_functions();
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
&& !defined OVERWRITE_ZEND_EXECUTE_DATA
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("one"), one_before, one_after, NULL);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("two"), two_before, two_after, NULL);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("three"), three_before, three_after, NULL);
#else
/*
* This will pick up whichever one isn't null.
*/
nr_php_wrap_user_function(NR_PSTR("one"), one_before TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("two"), two_before TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("three"), three_before TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("one"), one_after TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("two"), two_after TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("three"), three_after TSRMLS_CC);
#endif
arg = tlib_php_request_eval_expr("1" TSRMLS_CC);
expr = nr_php_call(NULL, "one", arg);
tlib_pass_if_not_null("Runs fine.", expr);
tlib_pass_if_zval_type_is("Should have received the arg value.", IS_LONG,
expr);
tlib_pass_if_str_equal(message, expected_name, NRTXN(path));
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
tlib_php_request_end();
tlib_php_engine_destroy(TSRMLS_C);
}
/*
* to customize txn naming per framework, PHP agent uses the order in which
* (functions are processed, NR_NOT_OK_TO_OVERWRITE/NR_OK_TO_OVERWRITE, and
* whether it is called either before or after NR_PHP_WRAPPER_CALL (for pre PHP
* 8+) or whether it is called in func_begin or func_end (for PHP 8+ / OAPI).
*
* This test serves to illustrate and test *framework* txn naming conventions
* and how they are affected by calling nr_tx_set path either 1) before
* nr_wrapper_call for preoapi and in func_begin as a before callback in oapi 2)
* after nr_wrapper_call for preoapi and in func_end as an after callback in
* oapi
*
* The execution order is as follows:
* 1) oapi: `one` before callback OR legacy:any statements before the `one`
* PHP_CALL_WRAPPER
*
* 2) `one` begins execution and calls `two`
*
* 3) oapi: `two` before callback OR legacy: any statements before the
* `two` PHP_CALL_WRAPPER
*
* 4) `two` begins execution and calls `three`
*
* 5) oapi: `three` before callback OR legacy: any statements
* before the `three` PHP_CALL_WRAPPER
*
* 6) `three` begins execution
*
* 7) `three` ends
*
* 8) oapi: `three` after callback OR legacy: any statements
* after the `three` PHP_CALL_WRAPPER
*
* 9) `two` ends
*
* 10) oapi:`two` after callback OR legacy: any statements after the
* `two` PHP_CALL_WRAPPER
*
* 11) `one` ends
*
* 12) oapi: `one` after callback OR legacy: any statements after the `one`
* PHP_CALL_WRAPPER
*/
static void test_framework_txn_naming() {
/*
* This function both tests and illustrates how to use the wrapped function
* special callbacks in the various framework scenarios for naming the txn
* when there are multiple routes for naming (i.e. nested calls that have
* wrapper special functions that all call nr_set_txn_path in different ways.
* Each test case can be considered a "framework" with three different ways of
* naming the txn called by the three nested functions. For all cases,
* function `one` calls `two` calls `three`.
*/
/*
* case 1) IF wrapper function is called before NR_PHP_WRAPPER_CALL or called
* in func_begin AND NR_NOT_OK_TO_OVERWRITE is set THEN the FIRST wrapped
* function encountered determines the txn name.
*
* All functions set the txn before NR_PHP_WRAPPER_CALL and/or in OAPI
* func_begin and use NR_NOT_OK_TO_OVERWRITE.
*
* Expecting `one` to name txn.
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_not_ok, NULL,
test_name_txn_before_not_ok, NULL, "one",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_not_"
"overwrite,three:name_before_call:will_not_overwrite");
/*
*
* 2) IF wrapper function is called before NR_PHP_WRAPPER_CALL or called in
* func_begin AND NR_OK_TO_OVERWRITE is set THEN the LAST wrapped function
* encountered determines the txn name.
*
* All functions set the txn before NR_PHP_WRAPPER_CALL and/or in OAPI
* func_begin and use NR_OK_TO_OVERWRITE.
*
* Expecting `three` to name txn.
*/
execute_nested_framework_calls(
test_name_txn_before_ok, NULL, test_name_txn_before_ok, NULL,
test_name_txn_before_ok, NULL, "three",
"one:name_before_call:will_overwrite,two:name_before_call:will_overwrite,"
"three:name_before_call:will_overwrite");
/*
*
* 3) IF wrapper function is called after NR_PHP_WRAPPER_CALL or called in
* func_end AND NR_NOT_OK_TO_OVERWRITE is set THEN the LAST wrapped function
* encountered determines the txn name.
* All functions set the txn after NR_PHP_WRAPPER_CALL and/or in OAPI
* func_begin and use NR_NOT_OK_TO_OVERWRITE.
*
* Expecting `three` to name txn.
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, NULL, test_name_txn_after_not_ok, NULL,
test_name_txn_after_not_ok, "three",
"one:name_after_call:will_not_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_after_call:will_not_overwrite");
/*
* 4) IF wrapper function is called after NR_PHP_WRAPPER_CALL or called in
* func_end AND NR_OK_TO_OVERWRITE is set THEN the FIRST wrapped function
* encountered determines the txn name.
*
* All functions set the txn before NR_PHP_WRAPPER_CALL and/or in OAPI
* func_begin and use NR_OK_TO_OVERWRITE.
*
* Expecting `one` to name txn.
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, NULL, test_name_txn_after_ok, NULL,
test_name_txn_after_ok, "one",
"one:name_after_call:will_overwrite,two:name_after_call:will_overwrite,"
"three:name_after_call:will_overwrite");
/*
* 5) If there are nested functions that have wrapped functions called before
* NR_PHP_WRAPPER_CALL or called in func_begin AND that also have called after
* NR_PHP_WRAPPER_CALL or called in func_end if the after call uses
* NR_NOT_OK_TO_OVERWRITE, then rule 1 or 2 applies depending on whether a
* before_func used NR_NOT_OK_TO_OVERWRITE or NR_NOT_TO_OVERWRITE.
*
* 6) If there are nested functions that have wrapped functions called before
* NR_PHP_WRAPPER_CALL or called in func_begin AND that also have called after
* NR_PHP_WRAPPER_CALL or called in func_end if the after call uses
* NR_OK_TO_OVERWRITE, then rule 4 applies.
*
* Basically a mix and match situation where we have some best tries at naming
* a nested function transaction via one txn naming wrapped function, but if
* something better comes along via a DIFFERENT wrapped function, we'd prefer
* that. Special functions are mixed with regards to calling before/after and
* NR_NOT_OK_TO_OVERWRITE/NR_OK_TO_OVERWRITE
*/
/*
* After only mixes of NR_NOT_OK_TO_OVERWRITE/NR_NOT_OK_TO_OVERWRITE
*/
/*
* special function for one is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called after and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, NULL, test_name_txn_after_ok, NULL,
test_name_txn_after_ok, "two",
"one:name_after_call:will_not_overwrite,two:name_after_call:will_"
"overwrite,three:name_after_call:will_overwrite");
/*
* special function for one is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called after and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, NULL, test_name_txn_after_not_ok, NULL,
test_name_txn_after_ok, "three",
"one:name_after_call:will_not_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_after_call:will_overwrite");
/*
* special function for one is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called after and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, NULL, test_name_txn_after_ok, NULL,
test_name_txn_after_not_ok, "two",
"one:name_after_call:will_not_overwrite,two:name_after_call:will_"
"overwrite,three:name_after_call:will_not_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called after and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, NULL, test_name_txn_after_not_ok, NULL,
test_name_txn_after_ok, "one",
"one:name_after_call:will_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_after_call:will_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, NULL, test_name_txn_after_not_ok, NULL,
test_name_txn_after_not_ok, "one",
"one:name_after_call:will_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_after_call:will_not_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called after and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, NULL, test_name_txn_after_ok, NULL,
test_name_txn_after_not_ok, "one",
"one:name_after_call:will_overwrite,two:name_after_call:will_overwrite,"
"three:name_after_call:will_not_overwrite");
/*
* Before only mixes of NR_NOT_OK_TO_OVERWRITE/NR_NOT_OK_TO_OVERWRITE
*/
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_ok, NULL,
test_name_txn_before_ok, NULL, "three",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_not_ok, NULL,
test_name_txn_before_ok, NULL, "three",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_not_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called before and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_ok, NULL,
test_name_txn_before_not_ok, NULL, "two",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_"
"overwrite,three:name_before_call:will_not_overwrite");
/*
* special function for one is called before and uses NR_OK_TO_OVERWRITE
* special function for two is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
test_name_txn_before_ok, NULL, test_name_txn_before_not_ok, NULL,
test_name_txn_before_ok, NULL, "three",
"one:name_before_call:will_overwrite,two:name_before_call:will_not_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_OK_TO_OVERWRITE
* special function for two is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
test_name_txn_before_ok, NULL, test_name_txn_before_not_ok, NULL,
test_name_txn_before_not_ok, NULL, "one",
"one:name_before_call:will_overwrite,two:name_before_call:will_not_"
"overwrite,three:name_before_call:will_not_overwrite");
/*
* special function for one is called before and uses NR_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called before and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
test_name_txn_before_ok, NULL, test_name_txn_before_ok, NULL,
test_name_txn_before_not_ok, NULL, "two",
"one:name_before_call:will_overwrite,two:name_before_call:will_overwrite,"
"three:name_before_call:will_not_overwrite");
/*
* Before/After and NR_NOT_OK_TO_OVERWRITE/NR_NOT_OK_TO_OVERWRITE mixes
*/
/*
* special function for one is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, test_name_txn_before_ok, NULL,
test_name_txn_before_ok, NULL, "three",
"one:name_after_call:will_not_overwrite,two:name_before_call:will_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, test_name_txn_before_ok, NULL,
test_name_txn_before_ok, NULL, "one",
"one:name_after_call:will_overwrite,two:name_before_call:will_overwrite,"
"three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, NULL, test_name_txn_after_not_ok,
test_name_txn_before_ok, NULL, "three",
"one:name_before_call:will_not_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, NULL, test_name_txn_after_ok,
test_name_txn_before_ok, NULL, "two",
"one:name_before_call:will_not_overwrite,two:name_after_call:will_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_ok, NULL, NULL,
test_name_txn_after_not_ok, "two",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_"
"overwrite,three:name_after_call:will_not_overwrite");
/*
* special function for one is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for two is called before and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `three`
*/
execute_nested_framework_calls(
test_name_txn_before_not_ok, NULL, test_name_txn_before_ok, NULL, NULL,
test_name_txn_after_ok, "three",
"one:name_before_call:will_not_overwrite,two:name_before_call:will_"
"overwrite,three:name_after_call:will_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called after and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called before and uses NR_OK_TO_OVERWRITE
*
* expect txn to be named `one`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_ok, NULL, test_name_txn_after_not_ok,
test_name_txn_before_ok, NULL, "one",
"one:name_after_call:will_overwrite,two:name_after_call:will_not_"
"overwrite,three:name_before_call:will_overwrite");
/*
* special function for one is called after and uses NR_OK_TO_OVERWRITE
* special function for two is called before and uses NR_NOT_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
NULL, test_name_txn_after_not_ok, test_name_txn_before_not_ok, NULL, NULL,
test_name_txn_after_not_ok, "two",
"one:name_after_call:will_overwrite,two:name_before_call:will_not_"
"overwrite,three:name_after_call:will_not_overwrite");
/*
* special function for one is called before and uses NR_OK_TO_OVERWRITE
* special function for two is called after and uses NR_OK_TO_OVERWRITE
* special function for three is called after and uses NR_NOT_OK_TO_OVERWRITE
*
* expect txn to be named `two`
*/
execute_nested_framework_calls(
test_name_txn_before_ok, NULL, NULL, test_name_txn_after_ok, NULL,
test_name_txn_after_not_ok, "two",
"one:name_before_call:will_overwrite,two:name_after_call:will_overwrite,"
"three:name_after_call:will_not_overwrite");
}
#endif /* ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO */
static void test_add_arg(TSRMLS_D) {
zval* expr = NULL;
zval* arg = NULL;
tlib_php_request_start();
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
&& !defined OVERWRITE_ZEND_EXECUTE_DATA /* PHP 8.0+ and OAPI */
tlib_php_request_eval("function arg0_def0() { return 4; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("arg0_def0"), test_add_array, NULL, NULL TSRMLS_CC);
tlib_php_request_eval("function arg1_def0($a) { return $a; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("arg1_def0"), test_add_array, NULL, NULL TSRMLS_CC);
tlib_php_request_eval(
"function arg0_def1($a = null) { return $a; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("arg0_def1"), test_add_array, NULL, NULL TSRMLS_CC);
tlib_php_request_eval(
"function arg1_def1($a, $b = null) { return $b; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("arg1_def1"), test_add_array, NULL, NULL TSRMLS_CC);
tlib_php_request_eval(
"function arg1_def1_2($a, $b = null) { return $b; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("arg1_def1_2"), test_add_2_arrays, NULL, NULL TSRMLS_CC);
tlib_php_request_eval("function splat(...$a) { return $a[0]; }" TSRMLS_CC);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("splat"), test_add_array, NULL, NULL TSRMLS_CC);
#else
tlib_php_request_eval("function arg0_def0() { return 4; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("arg0_def0"), test_add_array TSRMLS_CC);
tlib_php_request_eval("function arg1_def0($a) { return $a; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("arg1_def0"), test_add_array TSRMLS_CC);
tlib_php_request_eval(
"function arg0_def1($a = null) { return $a; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("arg0_def1"), test_add_array TSRMLS_CC);
tlib_php_request_eval(
"function arg1_def1($a, $b = null) { return $b; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("arg1_def1"), test_add_array TSRMLS_CC);
tlib_php_request_eval(
"function arg1_def1_2($a, $b = null) { return $b; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("arg1_def1_2"),
test_add_2_arrays TSRMLS_CC);
tlib_php_request_eval("function splat(...$a) { return $a[0]; }" TSRMLS_CC);
nr_php_wrap_user_function(NR_PSTR("splat"), test_add_array TSRMLS_CC);
#endif
/*
* 0 arguments, 0 default arguments, 0 arguments given
*/
expr = nr_php_call(NULL, "arg0_def0");
tlib_pass_if_not_null("0 args, 0 default args, 0 given", expr);
tlib_pass_if_zval_type_is("0 args, 0 default args, 0 given", IS_LONG, expr);
nr_php_zval_free(&expr);
/*
* 0 arguments, 0 default arguments, 1 argument given
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg0_def0", arg);
tlib_pass_if_not_null("0 args, 0 default args, 1 given", expr);
tlib_pass_if_zval_type_is("0 args, 0 default args, 1 given", IS_LONG, expr);
nr_php_zval_free(&arg);
nr_php_zval_free(&expr);
/*
* 1 argument, 0 default arguments, 0 arguments given
*/
expr = nr_php_call(NULL, "arg1_def0");
tlib_pass_if_not_null("1 args, 0 default args, 0 given", expr);
tlib_pass_if_zval_type_is("1 args, 0 default args, 0 given", IS_ARRAY, expr);
nr_php_zval_free(&expr);
/*
* 1 argument, 0 default arguments, 1 argument given
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg1_def0", arg);
tlib_pass_if_not_null("1 args, 0 default args, 1 given", expr);
tlib_pass_if_zval_type_is("1 args, 0 default args, 1 given", IS_STRING, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
/*
* 0 arguments, 1 default arguments, 0 arguments given
*/
expr = nr_php_call(NULL, "arg0_def1");
tlib_pass_if_not_null("0 args, 1 default args, 0 given", expr);
tlib_pass_if_zval_type_is("0 args, 1 default args, 0 given", IS_ARRAY, expr);
nr_php_zval_free(&expr);
/*
* 0 arguments, 1 default arguments, 1 argument given
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg0_def1", arg);
tlib_pass_if_not_null("0 args, 1 default args, 1 given", expr);
tlib_pass_if_zval_type_is("0 args, 1 default args, 1 given", IS_STRING, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
/*
* 1 argument, 1 default arguments, 0 arguments given
*/
expr = nr_php_call(NULL, "arg1_def1");
tlib_pass_if_not_null("1 args, 1 default args, 0 given", expr);
tlib_pass_if_zval_type_is("1 args, 1 default args, 0 given", IS_NULL, expr);
nr_php_zval_free(&expr);
/*
* 1 argument, 1 default arguments, 2 arguments given
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg1_def1", arg);
tlib_pass_if_not_null("1 args, 1 default args, 1 given", expr);
tlib_pass_if_zval_type_is("1 args, 1 default args, 1 given", IS_ARRAY, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
/*
* 1 argument, 1 default arguments, 0 arguments given, 2 added
*/
expr = nr_php_call(NULL, "arg1_def1_2");
tlib_pass_if_not_null("1 args, 1 default args, 0 given, 2 added", expr);
tlib_pass_if_zval_type_is("1 args, 1 default args, 0 given, 2 added",
IS_ARRAY, expr);
nr_php_zval_free(&expr);
/*
* 1 argument, 1 default arguments, 1 argument given, 2 added
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg1_def1_2", arg);
tlib_pass_if_not_null("1 args, 1 default args, 1 given, 2 added", expr);
tlib_pass_if_zval_type_is("1 args, 1 default args, 1 given, 2 added",
IS_ARRAY, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
/*
* 1 argument, 1 default arguments, 2 arguments given, 2 added
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "arg1_def1_2", arg, arg);
tlib_pass_if_not_null("1 args, 1 default args, 2 given, 2 added", expr);
tlib_pass_if_zval_type_is("1 args, 1 default args, 2 given, 2 added",
IS_STRING, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
/*
* splat, 0 arguments given
*
* nr_php_add_arg does not alter any splat argument lists.
*/
expr = nr_php_call(NULL, "splat");
tlib_pass_if_not_null("splat, 0 given", expr);
tlib_pass_if_zval_type_is("splat, 0 given", IS_NULL, expr);
nr_php_zval_free(&expr);
/*
* splat, 1 argument given,
*
* nr_php_add_arg does not alter any splat argument lists.
*/
arg = tlib_php_request_eval_expr("'a'" TSRMLS_CC);
expr = nr_php_call(NULL, "splat", arg);
tlib_pass_if_not_null("splat, 1 given", expr);
tlib_pass_if_zval_type_is("splat, 1 given", IS_STRING, expr);
nr_php_zval_free(&expr);
nr_php_zval_free(&arg);
tlib_php_request_end();
}
void test_main(void* p NRUNUSED) {
#if defined(ZTS) && !defined(PHP7)
void*** tsrm_ls = NULL;
#endif /* ZTS && !PHP7 */
tlib_php_engine_create("" PTSRMLS_CC);
test_add_arg();
tlib_php_engine_destroy(TSRMLS_C);
/*
* The Jenkins PHP 7.3 nodes are unable to handle the multiple
* create/destroys, but works on more recent OSs.
*/
#if ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO
if (PHP_VERSION_ID < 80000 && PHP_VERSION_ID > 80002) {
test_framework_txn_naming();
}
#endif
}
#else /* PHP 7.3 */
void test_main(void* p NRUNUSED) {}
#endif /* PHP 7.3 */