AsmGrader
0.0.0
Loading...
Searching...
No Matches
test_macros.hpp
Go to the documentation of this file.
1
#pragma once
2
3
// Macro names in this file are short and may conflict with identifiers in 3rd-party libraries
4
// known conflicts with range-v3, so we just make sure to include it before
5
#include <range/v3/all.hpp>
// IWYU pragma: export
6
//
7
8
#include <
asmgrader/api/assignment.hpp
>
// IWYU pragma: export
9
#include <
asmgrader/api/requirement.hpp
>
// IWYU pragma: export
10
#include <
asmgrader/api/test_base.hpp
>
// IWYU pragma: export
11
#include <
asmgrader/api/test_context.hpp
>
12
#include <
asmgrader/common/macros.hpp
>
13
#include <
asmgrader/grading_session.hpp
>
// IWYU pragma: export
14
#include <
asmgrader/logging.hpp
>
15
#include <
asmgrader/registrars/auto_registrars.hpp
>
// IWYU pragma: export
16
17
#include <boost/preprocessor/repetition/repeat.hpp>
18
19
// Some macros to substantially simplify test case development
20
21
#define ASSIGNMENT(cpp_identifier, name, executable) \
22
const static Assignment& cpp_identifier =
/* NOLINT(misc-use-anonymous-namespace)*/
\
23
::asmgrader::GlobalRegistrar::get().add(Assignment{name, executable});
24
25
#define TEST_IMPL(ident, name,
/*metadata attributes*/
...) \
26
namespace { \
27
class ident final : public ::asmgrader::TestBase \
28
{ \
29
public: \
30
using TestBase::TestBase; \
31
void run(::asmgrader::TestContext& ctx) override; \
32
}; \
33
using namespace ::asmgrader::metadata;
/*NOLINT(google-build-using-namespace)*/
\
34
constexpr auto CONCAT(ident, \
35
__metadata) = ::asmgrader::metadata::create(::asmgrader::metadata::DEFAULT_METADATA, \
36
::asmgrader::metadata::global_file_metadata() \
37
__VA_OPT__(, ) __VA_ARGS__); \
38
const ::asmgrader::TestAutoRegistrar<ident> CONCAT(ident, __registrar){name, CONCAT(ident, __metadata)}; \
39
} \
40
void ident::run([[maybe_unused]] ::asmgrader::TestContext& ctx)
41
42
#define TEST(name, ...) TEST_IMPL(CONCAT(TEST__, __COUNTER__), name __VA_OPT__(, ) __VA_ARGS__)
43
49
#ifdef PROFESSOR_VERSION
50
#define PROF_ONLY_TEST(name, ...) TEST(name, ProfOnly __VA_OPT__(, ) __VA_ARGS__)
51
#else
52
#define PROF_ONLY_TEST(name, ...) [[maybe_unused]] static void CONCAT(prof_test_unused, __COUNTER__)(TestContext & ctx)
53
#endif
// PROFESSOR_VERSION
54
55
#define REQUIRE_IMPL(unq_ident, condition, condition_raw_str, ...) \
56
do {
/* NOLINT(cppcoreguidelines-avoid-do-while) */
\
57
/*NOLINTNEXTLINE(bugprone-chained-comparison)*/
\
58
const auto& unq_ident = ::asmgrader::Requirement{asmgrader::Decomposer{} <= condition, \
59
{condition_raw_str} __VA_OPT__(, ONLY_FIRST(__VA_ARGS__))}; \
60
bool CONCAT(bool_, unq_ident) = ctx.require(unq_ident); \
61
} while (false);
62
63
#define REQUIRE(condition, ...) REQUIRE_IMPL(CONCAT(require_unq_, __COUNTER__), condition, #condition, __VA_ARGS__)
64
65
#define FILE_METADATA(...) \
66
namespace asmgrader::metadata { \
67
consteval auto global_file_metadata() { \
68
using namespace ::asmgrader;
/* NOLINT(google-build-using-namespace) */
\
69
return ::asmgrader::metadata::Metadata{__VA_ARGS__}; \
70
} \
71
}
// namespace metadata
72
73
// Macros for registers and flags
74
75
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
76
#define REGS_MACRO_IMPL(which) ctx.get_registers().which
77
78
#define W0 REGS_MACRO_IMPL(w0)
79
#define X0 REGS_MACRO_IMPL(x0)
80
#define W1 REGS_MACRO_IMPL(w1)
81
#define X1 REGS_MACRO_IMPL(x1)
82
#define W2 REGS_MACRO_IMPL(w2)
83
#define X2 REGS_MACRO_IMPL(x2)
84
#define W3 REGS_MACRO_IMPL(w3)
85
#define X3 REGS_MACRO_IMPL(x3)
86
#define W4 REGS_MACRO_IMPL(w4)
87
#define X4 REGS_MACRO_IMPL(x4)
88
#define W5 REGS_MACRO_IMPL(w5)
89
#define X5 REGS_MACRO_IMPL(x5)
90
#define W6 REGS_MACRO_IMPL(w6)
91
#define X6 REGS_MACRO_IMPL(x6)
92
#define W7 REGS_MACRO_IMPL(w7)
93
#define X7 REGS_MACRO_IMPL(x7)
94
#define W8 REGS_MACRO_IMPL(w8)
95
#define X8 REGS_MACRO_IMPL(x8)
96
#define W9 REGS_MACRO_IMPL(w9)
97
#define X9 REGS_MACRO_IMPL(x9)
98
#define W10 REGS_MACRO_IMPL(w10)
99
#define X10 REGS_MACRO_IMPL(x10)
100
#define W11 REGS_MACRO_IMPL(w11)
101
#define X11 REGS_MACRO_IMPL(x11)
102
#define W12 REGS_MACRO_IMPL(w12)
103
#define X12 REGS_MACRO_IMPL(x12)
104
#define W13 REGS_MACRO_IMPL(w13)
105
#define X13 REGS_MACRO_IMPL(x13)
106
#define W14 REGS_MACRO_IMPL(w14)
107
#define X14 REGS_MACRO_IMPL(x14)
108
#define W15 REGS_MACRO_IMPL(w15)
109
#define X15 REGS_MACRO_IMPL(x15)
110
#define W16 REGS_MACRO_IMPL(w16)
111
#define X16 REGS_MACRO_IMPL(x16)
112
#define W17 REGS_MACRO_IMPL(w17)
113
#define X17 REGS_MACRO_IMPL(x17)
114
#define W18 REGS_MACRO_IMPL(w18)
115
#define X18 REGS_MACRO_IMPL(x18)
116
#define W19 REGS_MACRO_IMPL(w19)
117
#define X19 REGS_MACRO_IMPL(x19)
118
#define W20 REGS_MACRO_IMPL(w20)
119
#define X20 REGS_MACRO_IMPL(x20)
120
#define W21 REGS_MACRO_IMPL(w21)
121
#define X21 REGS_MACRO_IMPL(x21)
122
#define W22 REGS_MACRO_IMPL(w22)
123
#define X22 REGS_MACRO_IMPL(x22)
124
#define W23 REGS_MACRO_IMPL(w23)
125
#define X23 REGS_MACRO_IMPL(x23)
126
#define W24 REGS_MACRO_IMPL(w24)
127
#define X24 REGS_MACRO_IMPL(x24)
128
#define W25 REGS_MACRO_IMPL(w25)
129
#define X25 REGS_MACRO_IMPL(x25)
130
#define W26 REGS_MACRO_IMPL(w26)
131
#define X26 REGS_MACRO_IMPL(x26)
132
#define W27 REGS_MACRO_IMPL(w27)
133
#define X27 REGS_MACRO_IMPL(x27)
134
#define W28 REGS_MACRO_IMPL(w28)
135
#define X28 REGS_MACRO_IMPL(x28)
136
#define W29 REGS_MACRO_IMPL(w29)
137
#define X29 REGS_MACRO_IMPL(x29)
138
#define W30 REGS_MACRO_IMPL(w30)
139
#define X30 REGS_MACRO_IMPL(x30)
140
141
#define FP REGS_MACRO_IMPL(fp)
142
#define LR REGS_MACRO_IMPL(lr)
143
#define SP REGS_MACRO_IMPL(sp)
144
#define PC REGS_MACRO_IMPL(pc)
145
146
#define PSTATE REGS_MACRO_IMPL(pstate)
147
#define N PSTATE.n()
148
#define Z PSTATE.z()
149
#define C PSTATE.c()
150
#define V PSTATE.v()
151
152
// TODO: x86-64 accessors
assignment.hpp
auto_registrars.hpp
grading_session.hpp
Defines data classes to store result data for the current run session.
logging.hpp
macros.hpp
requirement.hpp
test_base.hpp
test_context.hpp
include
asmgrader
api
test_macros.hpp
Generated by
1.12.0