Test are run through dotnet CLI from the project root directory:
```
cd tests
-dotnet test
+dotnet build && dotnet test runner
```
It is possible to override path to the debugger binary through `PIPE` environment variable:
Refer to `run_tests_sdb.sh` as an example of running tests on Tizen device.
+`TIMEOUT` environment variable overrides a default timeout (in seconds) for test's `Expect` command.
+
## Writing new tests
### Add new test
* `string TestBin` is a full path to test dll file.
+* `int DefaultExpectTimeout` is a timeout for `Expect` operation, default value is 20 (seconds).
+
* `ITestOutputHelper Output` is a log interface from Xunit, it contains methods like `WriteLine` etc.
#### Methods
* `void Send(string s)` sends command to the debugger process through stdin. New line is automatically appended to `s`.
-* `MICore.Results Expect(string s, int timeoutSec = 10)` reads debugger output line by line and checks if some line starts with `s`. If the expected line is found then it is parsed into MI responce object `MICore.Results`. In case of timeout or invalid MI responce an exception is thrown.
+* `MICore.Results Expect(string s, int timeoutSec = DefaultExpectTimeout)` reads debugger output line by line and checks if some line starts with `s`. If the expected line is found then it is parsed into MI responce object `MICore.Results`. In case of timeout or invalid MI responce an exception is thrown.
For more info about MI responce object see https://github.com/Microsoft/MIEngine/blob/master/src/MICore/MIResults.cs
* `int GetCurrentLine()` provides current line number.
[Fact]
public void BreakpointAddRemoveTest() => ExecuteTest();
+ private const int DefaultTimeoutSec = 20;
+ private int expectTimeoutSec;
+
public class ProcessInfo
{
- public ProcessInfo(string command, ITestOutputHelper output)
+ public ProcessInfo(string command, int defaultTimeoutSec, ITestOutputHelper output)
{
this.output = output;
+ this.defaultTimeoutSec = defaultTimeoutSec;
process = new Process();
queue = new BufferBlock<string>();
public MICore.Results Expect(string text, int timeoutSec)
{
+ if (timeoutSec < 0)
+ timeoutSec = defaultTimeoutSec;
+
TimeSpan timeSpan = TimeSpan.FromSeconds(timeoutSec);
CancellationTokenSource ts = new CancellationTokenSource();
public Process process;
private readonly ITestOutputHelper output;
+ private int defaultTimeoutSec { get; }
public BufferBlock<string> queue;
}
Dictionary<string, int> lines,
string testSource,
string testBin,
+ int defaultExpectTimeout,
ITestOutputHelper output)
{
this.processInfo = processInfo;
this.Lines = lines;
this.TestSource = testSource;
this.TestBin = testBin;
+ this.DefaultExpectTimeout = defaultExpectTimeout;
this.Output = output;
}
public int GetCurrentLine([CallerLineNumber] int line = 0) { return line; }
public void Send(string s) => processInfo.Send(s);
- public MICore.Results Expect(string s, int timeoutSec = 20) => processInfo.Expect(s, timeoutSec);
+ public MICore.Results Expect(string s, int timeoutSec = -1) => processInfo.Expect(s, timeoutSec);
public readonly string TestSource;
public readonly string TestBin;
+ public readonly int DefaultExpectTimeout;
public readonly ITestOutputHelper Output;
}
this.debuggerCommand = Path.Combine(d.Parent.Parent.Parent.Parent.Parent.FullName, "bin", "netcoredbg");
}
+ var timeout = Environment.GetEnvironmentVariable("TIMEOUT");
+ if (timeout == null || !Int32.TryParse(timeout, out expectTimeoutSec) || expectTimeoutSec < 0)
+ expectTimeoutSec = DefaultTimeoutSec;
+
var testDir = Environment.GetEnvironmentVariable("TESTDIR");
// Find all dlls
);
script.Compile();
- ProcessInfo processInfo = new ProcessInfo(debuggerCommand, output);
+ ProcessInfo processInfo = new ProcessInfo(debuggerCommand, expectTimeoutSec, output);
try
{
lines,
data.srcFilePath,
data.dllPath,
+ expectTimeoutSec,
output
);