Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(agent): Add tests that specifically exercise JIT. #715

Merged
merged 37 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0fcbec7
chore(tests): Convert forked PR branch to main repo branch.
zsistla Aug 17, 2023
764a62e
fix(tests): test_span_class_function fix.
zsistla Aug 17, 2023
153fea0
small commit to trigger PR runner
zsistla Aug 22, 2023
fc68e7c
Merge branch 'oapi' into ads/oapi-jit-tests
zsistla Sep 6, 2023
f13d075
Merge branch 'oapi' into ads/oapi-jit-tests
zsistla Oct 5, 2023
fef395d
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
2a47c6c
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
62e699b
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
5095469
Update tests/integration/jit/function/skipif.inc
zsistla Oct 12, 2023
7a5357e
Update tests/integration/jit/tracing/skipif.inc
zsistla Oct 12, 2023
9feccfa
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
496cae5
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
124ddd0
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
3f9df05
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 12, 2023
77622bf
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 13, 2023
acc7942
Update test_span_events_are_created_upon_caught_exception.php
zsistla Oct 13, 2023
38eb42d
fix(tests): Split tests to account for difference in PHP provided inf…
zsistla Oct 16, 2023
f0c1b54
fix(tests):Update uncaught exception with exception handler tests
zsistla Oct 16, 2023
a0025e8
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
249eac4
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
4bcb16b
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
04843fd
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
a1331af
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
163c958
Update tests/integration/jit/tracing/test_span_events_are_created_upo…
zsistla Oct 18, 2023
e92c71f
Update tests/integration/jit/tracing/test_span_events_are_created_upo…
zsistla Oct 18, 2023
098f7c6
Update tests/integration/jit/tracing/test_span_events_are_created_upo…
zsistla Oct 18, 2023
f7717a7
Rename test_span_events_are_created_upon_old_uncaught_handled_excepti…
zsistla Oct 18, 2023
b5b8a9c
Rename test_span_events_are_created_upon_uncaught_old_handled_excepti…
zsistla Oct 18, 2023
32ad388
Rename test_span_events_are_created_upon_uncaught_handled_exception_i…
zsistla Oct 18, 2023
4a8f842
Update test_span_events_are_created_upon_uncaught_handled_exception_i…
zsistla Oct 18, 2023
9a230de
Update test_span_events_are_created_upon_uncaught_handled_exception_i…
zsistla Oct 18, 2023
dee7617
Update tests/integration/jit/tracing/test_span_events_are_created_upo…
zsistla Oct 18, 2023
6a0e686
Update tests/integration/jit/tracing/test_span_events_are_created_upo…
zsistla Oct 18, 2023
d110d2a
Update tests/integration/jit/function/test_span_events_error_collecto…
zsistla Oct 18, 2023
ef32adc
Update tests/integration/jit/function/test_span_events_are_created_up…
zsistla Oct 18, 2023
0fe34e8
Apply suggestions from code review
zsistla Oct 18, 2023
47469df
Update test_span_events_are_created_upon_uncaught_handled_exception_i…
zsistla Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/newrelic/integration/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
"HEADERS": parseHeaders,
"SKIPIF": parseRawSkipIf,
"INI": parseSettings,
"PHPMODULES": parsePHPModules,
"CONFIG": parseConfig,
"DESCRIPTION": parseDescription,
"EXPECT_ANALYTICS_EVENTS": parseAnalyticEvents,
Expand Down Expand Up @@ -196,6 +197,35 @@ func parseSettings(t *Test, content []byte) error {
return nil
}

func parsePHPModules(t *Test, content []byte) error {
trimmed := bytes.TrimSpace(content)
settings := make(map[string]string)
scanner := bufio.NewScanner(bytes.NewReader(trimmed))
delim := []byte("=")

for scanner.Scan() {
parts := bytes.SplitN(scanner.Bytes(), delim, 2)
switch len(parts) {
case 2:
key, value := bytes.TrimSpace(parts[0]), bytes.TrimSpace(parts[1])
if len(key) > 0 {
settings[string(key)] = string(value)
} else {
return errBadSetting
}
case 1:
return errBadSetting
}
}

if err := scanner.Err(); err != nil {
return err
}
t.PhpModules = settings
return nil
}


func parseAnalyticEvents(test *Test, content []byte) error {
test.analyticEvents = content
return nil
Expand Down
11 changes: 7 additions & 4 deletions src/newrelic/integration/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type Test struct {
// Raw parsed test information used to construct the Tx.
// The settings and env do not include global env and
// global settings.
rawSkipIf []byte
Env map[string]string
Settings map[string]string
headers http.Header
rawSkipIf []byte
Env map[string]string
Settings map[string]string
PhpModules map[string]string
headers http.Header

// When non-empty describes why failed should be true after the test
// is run. This field may be set in the test definition to indicate
Expand Down Expand Up @@ -195,6 +196,8 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) {
}
}

settings = merge(settings, t.PhpModules)

if t.IsC() {
return CTx(ScriptFile(t.Path), env, settings, headers, ctx)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/jit/function/skipif.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/* JIT only supported with OAPI with PHP 8+ */
if (version_compare(PHP_VERSION, "8.0", "<")) {
die("skip: PHP < 8.0.0 not supported\n");
}

/* Test cannot run without opache */
/* This should be changed to a 'warn' result when supported */
zsistla marked this conversation as resolved.
Show resolved Hide resolved
if (!extension_loaded('Zend OPcache')) {
die("warn: Zend OPcache extension required\n");
}
78 changes: 78 additions & 0 deletions tests/integration/jit/function/test_computations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
Transaction event created and no errors despite creating spans
for a HUGE number of calls.
*/

/*SKIPIF
<?php

require('skipif.inc');
*/

/*INI
newrelic.distributed_tracing_enabled=1
newrelic.transaction_tracer.threshold = 0
error_reporting = E_ALL
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*PHPMODULES
zend_extension=opcache.so
*/

/*EXPECT_ANALYTICS_EVENTS
[
"?? agent run id",
{
"reservoir_size": 50,
"events_seen": 1
},
[
[
{
"traceId": "??",
"duration": "??",
"timestamp": "??",
"type": "Transaction",
"name": "OtherTransaction\/php__FILE__",
"guid": "??",
"priority": "??",
"sampled": true,
"totalTime": "??",
"error": false
},
{},
{}
]
]
]
*/


/*EXPECT
Hello
*/

newrelic_add_custom_tracer('computation');

function computation(float $a): int
{

$b = intval($a) % (2 ** 32);
return $b;
}

for ($i = 0; $i < 500; ++$i) {
computation(2**64);
}
echo 'Hello';
84 changes: 84 additions & 0 deletions tests/integration/jit/function/test_even_odd_count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
Transaction event generated with JIT enabled even when doing lots of loops.
*/

/*SKIPIF
<?php

require('skipif.inc');

*/

/*INI
newrelic.distributed_tracing_enabled=1
newrelic.transaction_tracer.threshold = 0
newrelic.cross_application_tracer.enabled = false
error_reporting = E_ALL
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*PHPMODULES
zend_extension=opcache.so
*/

/*EXPECT_ERROR_EVENTS null */

/*EXPECT_ANALYTICS_EVENTS
[
"?? agent run id",
{
"reservoir_size": 50,
"events_seen": 1
},
[
[
{
"traceId": "??",
"duration": "??",
"timestamp": "??",
"type": "Transaction",
"name": "OtherTransaction\/php__FILE__",
"guid": "??",
"priority": "??",
"sampled": true,
"totalTime": "??",
"error": false
},
{},
{}
]
]
]
*/

/*EXPECT
5000
*/


function even(int $a): bool {
if ($a == 1) {
return false;
} else if (($a % 2) == 0) {
return true;
}
return false;
}

$count = 0;
for ($i = 1; $i <= 10000; $i++)
{
if (even($i)) $count++;
}
echo "$count";

55 changes: 55 additions & 0 deletions tests/integration/jit/function/test_recursion_no_segfault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
JIT enabled, should still instrument without crashing.
Previous tests would invariably cause a segfault when
recursively finding the 10th fibonacci number.
*/

/*SKIPIF
<?php

require('skipif.inc');

*/

/*INI
error_reporting = E_ALL
newrelic.distributed_tracing_enabled=1
newrelic.transaction_tracer.threshold = 0
newrelic.cross_application_tracer.enabled = false
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*PHPMODULES
zend_extension=opcache.so
*/

/*EXPECT_ERROR_EVENTS
null
*/

/*EXPECT
89
*/

newrelic_add_custom_tracer('fibonacci');


function fibonacci($n){
return(($n < 2) ? 1 : fibonacci($n - 2) + fibonacci($n - 1));
}

$n = 10; /* Get the nth Fibonacci number. */

$fibonacci = fibonacci($n);
echo $fibonacci;

Loading
Loading