aboutsummaryrefslogtreecommitdiff
path: root/tests/profiling/gatordmock/GatordMockMain.cpp
blob: 9dac6d976ef8354230b9cd47440ceaaa89587d1d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Copyright © 2019 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "../../../src/profiling/PacketVersionResolver.hpp"
#include "../../../src/profiling/PeriodicCounterSelectionCommandHandler.hpp"
#include "CommandFileParser.hpp"
#include "CommandLineProcessor.hpp"
#include "DirectoryCaptureCommandHandler.hpp"
#include "GatordMockService.hpp"
#include "PeriodicCounterCaptureCommandHandler.hpp"
#include "PeriodicCounterSelectionResponseHandler.hpp"

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    // Process command line arguments
    armnn::gatordmock::CommandLineProcessor cmdLine;
    if (!cmdLine.ProcessCommandLine(argc, argv))
    {
        return EXIT_FAILURE;
    }

    armnn::profiling::PacketVersionResolver packetVersionResolver;
    // Create the Command Handler Registry
    armnn::profiling::CommandHandlerRegistry registry;

    // This functor will receive back the selection response packet.
    armnn::gatordmock::PeriodicCounterSelectionResponseHandler periodicCounterSelectionResponseHandler(
        0, 4, packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue());
    // This functor will receive the counter data.
    armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(
        1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue());

    armnn::gatordmock::DirectoryCaptureCommandHandler directoryCaptureCommandHandler(
        0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue());

    // Register different derived functors
    registry.RegisterFunctor(&periodicCounterSelectionResponseHandler);
    registry.RegisterFunctor(&counterCaptureCommandHandler);
    registry.RegisterFunctor(&directoryCaptureCommandHandler);

    armnn::gatordmock::GatordMockService mockService(registry, cmdLine.IsEchoEnabled());

    if (!mockService.OpenListeningSocket(cmdLine.GetUdsNamespace()))
    {
        return EXIT_FAILURE;
    }
    std::cout << "Bound to UDS namespace: \\0" << cmdLine.GetUdsNamespace() << std::endl;

    // Wait for a single connection.
    if (-1 == mockService.BlockForOneClient())
    {
        return EXIT_FAILURE;
    }
    std::cout << "Client connection established." << std::endl;

    // Send receive the strweam metadata and send connection ack.
    if (!mockService.WaitForStreamMetaData())
    {
        return EXIT_FAILURE;
    }
    mockService.SendConnectionAck();

    // Prepare to receive data.
    mockService.LaunchReceivingThread();

    // Process the SET and WAIT command from the file.
    armnn::gatordmock::CommandFileParser commandLineParser;
    commandLineParser.ParseFile(cmdLine.GetCommandFile(), mockService);

    // Once we've finished processing the file wait for the receiving thread to close.
    mockService.WaitForReceivingThread();

    return EXIT_SUCCESS;
}