diff --git a/src/newrelic/integration/parse.go b/src/newrelic/integration/parse.go index 43af09391..c7123daff 100644 --- a/src/newrelic/integration/parse.go +++ b/src/newrelic/integration/parse.go @@ -23,6 +23,7 @@ var ( "HEADERS": parseHeaders, "SKIPIF": parseRawSkipIf, "INI": parseSettings, + "PHPMODULES": parsePHPModules, "CONFIG": parseConfig, "DESCRIPTION": parseDescription, "EXPECT_ANALYTICS_EVENTS": parseAnalyticEvents, @@ -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 diff --git a/src/newrelic/integration/test.go b/src/newrelic/integration/test.go index 14d66bddc..3aaa98e0f 100644 --- a/src/newrelic/integration/test.go +++ b/src/newrelic/integration/test.go @@ -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 @@ -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) } diff --git a/tests/integration/jit/function/skipif.inc b/tests/integration/jit/function/skipif.inc new file mode 100644 index 000000000..c7f0ce357 --- /dev/null +++ b/tests/integration/jit/function/skipif.inc @@ -0,0 +1,16 @@ +functionName(); + } +} + +for($i = 0; $i < 5; ++$i){ + new LittleClass; +} +echo "OK\n"; diff --git a/tests/integration/jit/function/test_span_events_are_created_from_segments.php b/tests/integration/jit/function/test_span_events_are_created_from_segments.php new file mode 100644 index 000000000..b543794bd --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_from_segments.php @@ -0,0 +1,118 @@ + 'FakeDB', +)); diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php new file mode 100644 index 000000000..7eb35c819 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php @@ -0,0 +1,161 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php new file mode 100644 index 000000000..13e09a87b --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -0,0 +1,142 @@ + 'FakeDB', + ) +); + +try { +a(); +} catch (RuntimeException $e) { +} diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_exit.php b/tests/integration/jit/function/test_span_events_are_created_upon_exit.php new file mode 100644 index 000000000..3274bf154 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_exit.php @@ -0,0 +1,123 @@ + 'FakeDB', + ) +); +a(); diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php new file mode 100644 index 000000000..c3f064b6d --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php @@ -0,0 +1,133 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php new file mode 100644 index 000000000..3c0744dbf --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php @@ -0,0 +1,136 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_error_collector_disabled.php b/tests/integration/jit/function/test_span_events_error_collector_disabled.php new file mode 100644 index 000000000..08a872629 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_error_collector_disabled.php @@ -0,0 +1,127 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_exception_caught_nested.php b/tests/integration/jit/function/test_span_events_exception_caught_nested.php new file mode 100644 index 000000000..2433f1289 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_nested.php @@ -0,0 +1,217 @@ +getMessage() . "\n"); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php b/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php new file mode 100644 index 000000000..036b6a55e --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php @@ -0,0 +1,196 @@ +getMessage()); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php b/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php new file mode 100644 index 000000000..202479b19 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php @@ -0,0 +1,169 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php b/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php new file mode 100644 index 000000000..f182090d3 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php @@ -0,0 +1,245 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_same_span.php b/tests/integration/jit/function/test_span_events_exception_caught_same_span.php new file mode 100644 index 000000000..943b908ba --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_same_span.php @@ -0,0 +1,139 @@ +getMessage() . "\n"); + } +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php b/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php new file mode 100644 index 000000000..d3c317994 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php @@ -0,0 +1,224 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_exist_when_no_segments.php b/tests/integration/jit/function/test_span_events_exist_when_no_segments.php new file mode 100644 index 000000000..ce7cb296f --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exist_when_no_segments.php @@ -0,0 +1,65 @@ +functionName(); + } +} + +for($i = 0; $i < 5; ++$i){ + new LittleClass; +} +echo "OK\n"; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php b/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php new file mode 100644 index 000000000..cc2a52753 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php @@ -0,0 +1,118 @@ + 'FakeDB', +)); diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php new file mode 100644 index 000000000..c01951750 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php @@ -0,0 +1,161 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php new file mode 100644 index 000000000..0b4444679 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -0,0 +1,142 @@ + 'FakeDB', + ) +); + +try { +a(); +} catch (RuntimeException $e) { +} \ No newline at end of file diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php new file mode 100644 index 000000000..176730a7f --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php @@ -0,0 +1,123 @@ + 'FakeDB', + ) +); +a(); diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php new file mode 100644 index 000000000..ee1a578ae --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php @@ -0,0 +1,133 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php new file mode 100644 index 000000000..6141bdef4 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php @@ -0,0 +1,136 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php new file mode 100644 index 000000000..5cb38dcc3 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php @@ -0,0 +1,127 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php b/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php new file mode 100644 index 000000000..4ff854cf2 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php @@ -0,0 +1,217 @@ +getMessage() . "\n"); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php b/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php new file mode 100644 index 000000000..1ec6df51b --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php @@ -0,0 +1,196 @@ +getMessage()); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php new file mode 100644 index 000000000..5b42d5280 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php @@ -0,0 +1,169 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php new file mode 100644 index 000000000..aaeb5a278 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php @@ -0,0 +1,246 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php b/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php new file mode 100644 index 000000000..d92e22d16 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php @@ -0,0 +1,139 @@ +getMessage() . "\n"); + } +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php b/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php new file mode 100644 index 000000000..d352b174e --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php @@ -0,0 +1,225 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php b/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php new file mode 100644 index 000000000..a3c7c6a11 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php @@ -0,0 +1,65 @@ +