Skip to content

Commit

Permalink
feat(tests): Enable opcache by default for the integration runner. (#752
Browse files Browse the repository at this point in the history
)

* Enable the opcache.so extension by default in the integration_runner
* Ensure the opcache INI settings in the integration_runner environment
are enabled (these can be overwritten in the test case INI section if
needing to test without opcache)
* Added few tests to ensure compatibility with opcache disabled and to
demonstrate how to overwrite the value.

---------

Co-authored-by: ZNeumann <[email protected]>
Co-authored-by: Zach Neumann <[email protected]>
Co-authored-by: Michal Nowacki <[email protected]>
  • Loading branch information
4 people authored Feb 22, 2024
1 parent 958d859 commit 55d3904
Show file tree
Hide file tree
Showing 28 changed files with 3,575 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/integration_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
flagTime = flag.Bool("time", false, "time each test")
flagMaxCustomEvents = flag.Int("max_custom_events", 30000, "value for newrelic.custom_events.max_samples_stored")
flagWarnIsFail = flag.Bool("warnisfail", false, "warn result is treated as a fail")
flagOpcacheOff = flag.Bool("opcacheoff", false, "run without opcache. Some tests are intended to fail when run this way")

// externalPort is the port on which we start a server to handle
// external calls.
Expand Down Expand Up @@ -346,6 +347,16 @@ func main() {
ctx.Settings["newrelic.loglevel"] = *flagLoglevel
}

if false == *flagOpcacheOff {
// PHP Modules common to all tests
ctx.Settings["zend_extension"] = "opcache.so"

// PHP INI values common to all tests
// These settings can be overwritten by adding new values to the INI block
ctx.Settings["opcache.enable"] = "1"
ctx.Settings["opcache.enable_cli"] = "1"
}

// If the user provided a custom agent extension, use it.
if len(*flagAgent) > 0 {
ctx.Settings["extension"], _ = filepath.Abs(*flagAgent)
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/opcache/disabled/opcache_test.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/* Test should not run with opache */
if (extension_loaded('Zend OPcache')) {
if (false != opcache_get_status()) {
die("fail: OPcache enabled but needs to be disabled\n");
}
}
10 changes: 10 additions & 0 deletions tests/integration/opcache/disabled/skipif.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/* Opcache only supported with PHP 7+ */
if (version_compare(PHP_VERSION, "7.1", "<")) {
die("skip: PHP < 7.1 not supported\n");
}
75 changes: 75 additions & 0 deletions tests/integration/opcache/disabled/test_computations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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=0
opcache.enable_cli=0
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*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
*/
require('opcache_test.inc');

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';
81 changes: 81 additions & 0 deletions tests/integration/opcache/disabled/test_even_odd_count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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=0
opcache.enable_cli=0
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*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
*/
require('opcache_test.inc');


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";

52 changes: 52 additions & 0 deletions tests/integration/opcache/disabled/test_recursion_no_segfault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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=0
opcache.enable_cli=0
opcache.file_update_protection=0
opcache.jit_buffer_size=32M
opcache.jit=function
*/

/*EXPECT_ERROR_EVENTS
null
*/

/*EXPECT
89
*/
require('opcache_test.inc');

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

0 comments on commit 55d3904

Please sign in to comment.