Skip to content

Commit

Permalink
chore(tests): Convert forked PR branch to main repo branch.
Browse files Browse the repository at this point in the history
So the ci/cd will run...
  • Loading branch information
zsistla committed Aug 17, 2023
1 parent 1e7c861 commit 71d511f
Show file tree
Hide file tree
Showing 50 changed files with 6,516 additions and 4 deletions.
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 @@ -195,6 +196,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 @@ -50,10 +50,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 @@ -194,6 +195,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 */
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 2020 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

0 comments on commit 71d511f

Please sign in to comment.