File: platform.h

package info (click to toggle)
tango 10.0.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 272; sql: 72; ruby: 24
file content (126 lines) | stat: -rw-r--r-- 4,011 bytes parent folder | download | duplicates (3)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef TANGO_TESTS_CATCH2_UTILS_PLATFORM_PLATFORM_H
#define TANGO_TESTS_CATCH2_UTILS_PLATFORM_PLATFORM_H

#include "utils/test_server.h"

#include <vector>
#include <string>
#include <string_view>
#include <chrono>

namespace TangoTest::platform
{

constexpr static const char *k_test_server_binary_path = TANGO_TEST_CATCH2_SERVER_BINARY_PATH;
constexpr static const char *k_output_directory_path = TANGO_TEST_CATCH2_OUTPUT_DIRECTORY_PATH;
constexpr static const std::string_view k_resource_path = TANGO_TEST_CATCH2_RESOURCE_PATH;

/** Return the platform specific default environment table
 */
std::vector<std::string> default_env();

/** Called when the test run starts to do any setup required by the platform
 */
void init();

struct StartServerResult
{
    enum class Kind
    {
        Started, // The server started and outputted the ready_string,
                 // this->handle will be active
        Timeout, // The server timed out waiting for the ready_string,
                 // this->handle will be active
        Exited   // The server exited before outputting the ready_string,
                 // this->exit_status will be active
    };

    Kind kind;

    union
    {
        TestServer::Handle *handle;
        ExitStatus exit_status;
    };
};

// The following two functions are to be defined by each platform implementation

/**
 * @brief Start a TestServer process
 *
 * All memory passed to this function is copied to the child process as
 * required.
 *
 * @param args - arguments to pass to the TestServer binary.
 *              These strings will end up as the `argv` array for the process.
 * @param env - environment to provide for the child process.
 *              Each entry must be of the form "KEY=VALUE" or "KEY=".
 * @param redirect_filename - file to redirect all output to
 * @param ready_string - string to wait for to know when ready
 * @param timeout - how long until we give up waiting for `ready_string`
 * @return - the outcome of starting the server. See TangoTest::platform::StartServerResult.
 */
StartServerResult start_server(const std::vector<std::string> &args,
                               const std::vector<std::string> &env,
                               const std::string &redirect_filename,
                               const std::string &ready_string,
                               std::chrono::milliseconds timeout);

struct StopServerResult
{
    enum class Kind
    {
        ExitedEarly, // The server had already exited when `stop_server()` was called,
                     // exit_status is set
        Exiting,     // The server has been signalled to stop, exit_status is
                     // undefined
    };

    Kind kind;
    ExitStatus exit_status;
};

/**
 * @brief Signal to a server to stop a server
 *
 * If stop_server returns a StopServerResult with kind ExitedEarly,
 * then the handle is no longer valid.  Otherwise, you must call
 * wait_for_stop in order to free the handle.
 *
 * @param handle - a server returned by
 *                 TangoTest::platform::start_server
 * @return - the outcome of stopping the server. See
 *           TangoTest::platform::StopServerResult
 */
StopServerResult stop_server(TestServer::Handle *handle);

struct WaitForStopResult
{
    enum class Kind
    {
        Timeout, // Timed out waiting for the sever to exit, exit_status
                 // undefined
        Exited,  // The server stopped with exit_status
    };

    Kind kind;
    ExitStatus exit_status;
};

/**
 * @brief Wait for the server to stop.
 *
 * After this call the handle is no longer valid.
 *
 * @param handle - a server returned by
 *                 TangoTest::platform::start_server
 * @param timeout - how long until we give up waiting for the server
 * @return - the outcome of waiting for the server. See
 *           TangoTest::platform::WaitForStopResult
 */
WaitForStopResult wait_for_stop(TestServer::Handle *handle, std::chrono::milliseconds timeout);

} // namespace TangoTest::platform

#endif