Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
11 changes: 2 additions & 9 deletions daemon/cmd/integration_runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,8 @@ 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"
}
ctx.OPCacheModuleLoaded = integration.GetOPCacheModuleLoaded(*flagPHP, *flagCGI)
ctx.UseOPCache = !*flagOpcacheOff

// If the user provided a custom agent extension, use it.
if len(*flagAgent) > 0 {
Expand Down
14 changes: 8 additions & 6 deletions daemon/internal/newrelic/integration/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
)

type Context struct {
PHP string // path to the PHP CLI executable
CGI string // path to the PHP CGI executable
Valgrind string // path to the Valgrind executable, or empty if disabled
Env map[string]string // environment variables to pass to each test
Settings map[string]string // settings to pass to each test
Timeout time.Duration // maximum test duration
PHP string // path to the PHP CLI executable
CGI string // path to the PHP CGI executable
Valgrind string // path to the Valgrind executable, or empty if disabled
Env map[string]string // environment variables to pass to each test
Settings map[string]string // settings to pass to each test
Timeout time.Duration // maximum test duration
OPCacheModuleLoaded map[string]bool // map of PHP and CGI to OPcache default loaded status
UseOPCache bool // whether to use OPcache in tests
}

func NewContext(php, cgi string) *Context {
Expand Down
72 changes: 67 additions & 5 deletions daemon/internal/newrelic/integration/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ func merge(a, b map[string]string) map[string]string {
}

func (t *Test) MakeRun(ctx *Context) (Tx, error) {

// we don't support running C tests - assert this so we can
// troubleshoot if we try to run a C test
if t.IsC() {
fmt.Printf("ERROR - UNEXPECTED - Running C test: %s\n", t.Path)
os.Exit(1)
}

t.Env = merge(ctx.Env, t.Env)
settings := merge(ctx.Settings, t.Settings)
settings["newrelic.appname"] = t.Name
Expand All @@ -214,15 +222,69 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) {
}
}

settings = merge(settings, t.PhpModules)
// Make a copy of settings to avoid mutating the original map
// Need to adjust settings to opcache
phpSettings := make(map[string]string, len(settings))
setOPCacheEnable := true
setOPCacheEnableCLI := true
var php_executable string
if t.IsWeb() {
php_executable = ctx.CGI
} else {
php_executable = ctx.PHP
}
for k, v := range settings {
phpSettings[k] = v

if t.IsC() {
return CTx(ScriptFile(t.Path), t.Env, settings, headers, ctx)
// see if settings affect opcache config
// if so then we will not set config below
if k == "opcache.enable" {
setOPCacheEnable = false
} else if k == "opcache.enable_cli" {
setOPCacheEnableCLI = false
}
}
if ctx.UseOPCache {
if !ctx.OPCacheModuleLoaded[php_executable] {
phpSettings["zend_extension"] = "opcache.so"
}
if setOPCacheEnable {
phpSettings["opcache.enable"] = "1"
}
if setOPCacheEnableCLI {
phpSettings["opcache.enable_cli"] = "1"
}
} else {
if setOPCacheEnable {
phpSettings["opcache.enable"] = "0"
}
if setOPCacheEnableCLI {
phpSettings["opcache.enable_cli"] = "0"
}
}

// Make a copy of t.PhpModules and remove any entries containing "opcache.so"
// if opcache.so is loaded by default
//
// two cases:
// 1. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
// 2. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
phpModulesCopy := make(map[string]string)
if (t.IsWeb() && ctx.OPCacheModuleLoaded[ctx.CGI]) ||
(ctx.OPCacheModuleLoaded[ctx.PHP]) {
for k, v := range t.PhpModules {
if !strings.Contains(v, "opcache.so") {
phpModulesCopy[k] = v
}
}
}

phpSettings = merge(phpSettings, phpModulesCopy)

if t.IsWeb() {
return CgiTx(ScriptFile(t.Path), t.Env, settings, headers, ctx)
return CgiTx(ScriptFile(t.Path), t.Env, phpSettings, headers, ctx)
}
return PhpTx(ScriptFile(t.Path), t.Env, settings, ctx)
return PhpTx(ScriptFile(t.Path), t.Env, phpSettings, ctx)
}

func (t *Test) MakeSkipIf(ctx *Context) (Tx, error) {
Expand Down
28 changes: 28 additions & 0 deletions daemon/internal/newrelic/integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package integration

import (
"bytes"
"fmt"
"os"
"os/exec"
)

Expand All @@ -31,3 +33,29 @@ func GetAgentVersion(agent_extension string) string {
}
return string(output)
}

func IsOPcacheLoaded(php_executable string) bool {
fmt.Printf("Checking if OPcache is loaded using %s\n", php_executable)
cmd := exec.Command(php_executable, "-m")

output, err := cmd.Output()

if err != nil {
fmt.Printf("Failed to check if OPcache is loaded: %v\n", err)
os.Exit(1)
}

// Check if "Zend OPcache" is in the output
return bytes.Contains(output, []byte("Zend OPcache"))
}

func GetOPCacheModuleLoaded(php, cgi string) map[string]bool {
result := make(map[string]bool)

result[php] = IsOPcacheLoaded(php)
result[cgi] = IsOPcacheLoaded(cgi)

fmt.Printf("OPcache default loaded status: %+v\n", result)

return result
}
Loading