-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function yf = best_fit_line(x, y) | ||
% example code for testing auto instrumentation | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
coefs = polyfit(x, y, 1); | ||
yf = polyval(coefs , x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function yf = example1(n) | ||
% example code for testing auto instrumentation. Input n is the number of | ||
% data points. | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
[x, y] = generate_data(n); | ||
yf = best_fit_line(x,y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function [x, y] = generate_data(n) | ||
% example code for testing auto instrumentation | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
% generate some random data | ||
a = 1.5; | ||
b = 0.8; | ||
sigma = 5; | ||
x = 1:n; | ||
y = a * x + b + sigma * randn(1, n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
classdef tautotrace < matlab.unittest.TestCase | ||
% tests for AutoTrace | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
properties | ||
OtelConfigFile | ||
JsonFile | ||
PidFile | ||
OtelcolName | ||
Otelcol | ||
ListPid | ||
ReadPidList | ||
ExtractPid | ||
Sigint | ||
Sigterm | ||
end | ||
|
||
methods (TestClassSetup) | ||
function setupOnce(testCase) | ||
% add the utils folder to the path | ||
utilsfolder = fullfile(fileparts(mfilename('fullpath')), "utils"); | ||
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(utilsfolder)); | ||
% add the example folder to the path | ||
example1folder = fullfile(fileparts(mfilename('fullpath')), "autotrace_examples", "example1"); | ||
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(example1folder)); | ||
commonSetupOnce(testCase); | ||
end | ||
end | ||
|
||
methods (TestMethodSetup) | ||
function setup(testCase) | ||
commonSetup(testCase); | ||
end | ||
end | ||
|
||
methods (TestMethodTeardown) | ||
function teardown(testCase) | ||
commonTeardown(testCase); | ||
end | ||
end | ||
|
||
methods (Test) | ||
function testBasic(testCase) | ||
% testBasic: instrument a simple example | ||
|
||
% configure the global tracer provider | ||
tp = opentelemetry.sdk.trace.TracerProvider(); | ||
setTracerProvider(tp); | ||
clear("tp"); | ||
|
||
% set up AutoTrace | ||
at = opentelemetry.autoinstrument.AutoTrace(@example1); | ||
|
||
% run the example | ||
[~] = beginTrace(at, 100); | ||
|
||
% perform test comparisons | ||
results = readJsonResults(testCase); | ||
verifyNumElements(testCase, results, 3); | ||
|
||
% check logger name, log body and severity, trace and span IDs | ||
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.scope.name), "AutoTrace"); | ||
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), "generate_data"); | ||
verifyEqual(testCase, string(results{2}.resourceSpans.scopeSpans.spans.name), "best_fit_line"); | ||
verifyEqual(testCase, string(results{3}.resourceSpans.scopeSpans.spans.name), "example1"); | ||
end | ||
end | ||
end |