summaryrefslogtreecommitdiff
path: root/tests/src/GC/Stress/Framework/DetourHelpers.cs
blob: 81142fab7adcf5c7f3011133d173911fb19a5c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Runtime.InteropServices;

/// <summary>
/// Helper class for dealing with RF detours
/// </summary>
public class DetourHelpers
{
    ReliabilityTestSet _testSet;
    public void Initialize(ReliabilityTestSet testSet)
    {
        _testSet = testSet;
        InstallDetours();
    }

    public void Uninitialize()
    {
        RemoveDetours();
    }

    public void SetThreadTestId(int index)
    {
        SetThreadTest(index);
    }

    public int GetThreadTestId()
    {
        return ((int)GetThreadTest());
    }

    public void SetTestIdName(int id, string name)
    {
        AddTestToNameMapping(id, name);
    }

    [DllImport("RFDetours")]
    static extern void AddTestToNameMapping(int id, [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]string name);

    [DllImport("RFDetours")]
    static extern void InstallDetours();

    [DllImport("RFDetours")]
    static extern void RemoveDetours();

    [DllImport("RFDetours")]
    static extern void SetThreadTest(int testId);

    [DllImport("RFDetours")]
    static extern IntPtr GetThreadTest();
}