summaryrefslogtreecommitdiffstats
path: root/fire-pit/test.h
blob: c9075304c27a98b54cdce9d78c5e7f2e1e0eb9b3 (plain) (blame)
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
#ifndef EXITEST_TEST_H_INCLUDED
#define EXITEST_TEST_H_INCLUDED

#include <gccore.h>

struct et_test;

typedef u32 et_status;

/* Test passed. */
#define ET_STATUS_PASS  (et_status)0x00

/* Test failed. */
#define ET_STATUS_FAIL  (et_status)0x01

/* Test skipped or not applicable. */
#define ET_STATUS_SKIP  (et_status)0x02

/* Internal error during testing. */
#define ET_STATUS_ERROR (et_status)0x03

#define ET_STATUS_MASK  (et_status)0x03

#define ET_STATUS_GET_BASE(_status) ((et_status)(_status) & ~((1u << ET_STATUS_ERRCODE_SHIFT) - 1))

#define ET_STATUS_ERRCODE_SHIFT 2u
#define ET_STATUS_ERRCODE_MASK (((1u << ET_STATUS_PRIVATE_SHIFT) - 1) & ~ET_STATUS_MASK)
#define ET_STATUS_MAKE_ERRCODE(_code) (((et_status)(_code) << ET_STATUS_ERRCODE_SHIFT) & ET_STATUS_ERRCODE_MASK)
#define ET_STATUS_GET_ERRCODE(_status) (((et_status)(_status) & ET_STATUS_ERRCODE_MASK) >> ET_STATUS_ERRCODE_SHIFT)

#define ET_STATUS_PRIVATE_SHIFT 8u
#define ET_STATUS_GET_PRIVATE(_status) ((et_status)(_status) >> ET_STATUS_PRIVATE_SHIFT)
#define ET_STATUS_MAKE_PRIVATE(_exp) ((et_status)(_exp) << ET_STATUS_PRIVATE_SHIFT)
#define ET_STATUS_PRIVATE_MASK (ET_STATUS_MAKE_PRIVATE(~0u))

typedef enum {
  ET_TEST_INTERACTIVE = 0x0001u,
  ET_TEST_ESSENTIAL = 0x0002u
} et_test_flags;

typedef enum {
  ET_ERRCODE_NONE = ET_STATUS_MAKE_ERRCODE(0),
  ET_ERRCODE_BAD_ALLOC = ET_STATUS_MAKE_ERRCODE(0x01u),

  /* Error code is test-specific */
  ET_ERRCODE_PRIVATE = ET_STATUS_MAKE_ERRCODE(~0u),
} et_status_errcode;

/* returns 1 to continue testing, 0 when test is complete (call finish for status) */
typedef int (et_test_setup_proc)(struct et_test *test, void *work, int exi_channel);
typedef int (et_test_tick_proc)(struct et_test *test, void *work);
typedef et_status (et_test_finish_proc)(struct et_test *test, void *work);

/* translates a status code into a readable message. The returned pointer is a static string, and may not have all the information
 * as if a writeable buffer is passed into the function.
 *
 * Tests: do not write into out if outbuf_sz is too small. Try to keep the max message length within 256 bytes. */
typedef const char *(et_test_translate_proc)(struct et_test *test, char *out, size_t outbuf_sz, et_status status);

struct et_test {
  et_test_flags flags;
  const char *name;
  size_t work_size;

  et_test_setup_proc *setup_f;
  et_test_tick_proc *tick_f;
  et_test_finish_proc *finish_f;
  et_test_translate_proc *trans_f;

  const void *priv_data[4];
};

/* Array of tests. */
extern const struct et_test et_tests[];
extern const size_t et_ntests;

#endif /* include guard */