1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#pragma once
14
15/* Include Kconfig variables. */
16#include <autoconf.h>
17#include <sel4test/gen_config.h>
18#include <stdbool.h>
19
20typedef enum test_result {
21    /* test passed */
22    SUCCESS,
23    /* test failed */
24    FAILURE,
25    /* test corrupted environment, abort tests */
26    ABORT,
27    /* Start of the free slot/ID to be used to request
28     * operations from sel4test-test to sel4test-driver
29     * using the same end point
30     */
31    SEL4TEST_RESULT_FREE
32} test_result_t;
33
34/* Communication codes/requests between a server and a client */
35typedef enum _sel4test_communication_codes {
36    SEL4TEST_TIME_MIN = SEL4TEST_RESULT_FREE,
37    /* Client: requests a timeout from the server
38     * Server: Notify clients after the elapsed requested time.
39     * Previous timeout requests will be overwritten (if ongoing) with
40     * new timeout requests.
41     */
42    SEL4TEST_TIME_TIMEOUT,
43    /* Client: requests a timer reset and cancel previous requests
44     * Server: Cleans up the resources used from previous requests
45     * and stop notifying clients.
46     */
47    SEL4TEST_TIME_RESET,
48    SEL4TEST_TIME_TIMESTAMP,
49
50    SEL4TEST_TIME_MAX,
51
52    SEL4TEST_PROTOBUF_RPC = SEL4TEST_TIME_MAX,
53
54    SEL4TEST_OUTPUT_MAX
55} sel4test_output_t;
56
57/* A buffered printf to avoid corrupting xml output */
58void sel4test_printf(const char *out);
59/* enable printf buffering */
60void sel4test_start_printf_buffer(void);
61/* dump the current buffer and disable printf buffering */
62void sel4test_end_printf_buffer(void);
63
64/* reset the test environment for the next test */
65void sel4test_reset(void);
66
67/**
68 * Report an error in a test case.
69 * Can report multiple errors.
70 * This will fail a test case.
71 */
72void _sel4test_report_error(const char *error, const char *file, int line);
73
74/*
75 * Mark the current test as failed. Should
76 * only be called once per test case
77 */
78void _sel4test_failure(const char *failure, const char *file, int line);
79
80/*
81 * Mark the current test as fatally failed. The test will be terminated and
82 * will not proceed beyond this point.
83 */
84void _sel4test_abort(const char *failure, const char *file, int line);
85
86/*
87 * Indicates if current test passed.
88 */
89test_result_t sel4test_get_result(void);
90
91static inline bool sel4test_isTimerRPC(int output)
92{
93    return (output > SEL4TEST_TIME_MIN && output < SEL4TEST_TIME_MAX);
94}
95