Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
base.h File Reference
#include <serene/rt/context.h>
#include <serene/rt/engine.h>
#include <serene/rt/mm/interface.h>
#include <serene/utils.h>
#include "acutest.h"
Include dependency graph for base.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ENTRY(name, test)
#define ASSERT_NOT_NULL(x)
#define ASSERT_NULL(x)
#define TEST_NO_ERROR(x)
#define MAKE_ENGINE(mm, engine)
#define SHUTDOWN_ENGINE(mm, engine)
#define MAKE_CONTEXT(engine, x)
#define RELEASE_CONTEXT(x)
#define TEST_IN_FIBER_WITH(name, arg_expr, body)
#define TEST_IN_FIBER(name, body)

Macro Definition Documentation

◆ ASSERT_NOT_NULL

#define ASSERT_NOT_NULL ( x)
Value:
TEST_ASSERT(x != nullptr)
#define TEST_ASSERT(cond)
Definition acutest.h:117

Definition at line 30 of file base.h.

◆ ASSERT_NULL

#define ASSERT_NULL ( x)
Value:
TEST_ASSERT(x == nullptr)

Definition at line 31 of file base.h.

◆ ENTRY

#define ENTRY ( name,
test )
Value:
{name, test}

Definition at line 28 of file base.h.

◆ MAKE_CONTEXT

#define MAKE_CONTEXT ( engine,
x )
Value:
TEST_ASSERT(x != nullptr)
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:39

Definition at line 44 of file base.h.

44#define MAKE_CONTEXT(engine, x) \
45 srn_context_t *x = srn_context_make(engine); \
46 TEST_ASSERT(x != nullptr)

◆ MAKE_ENGINE

#define MAKE_ENGINE ( mm,
engine )
Value:
srn_mm_t *mm = srn_mm_init(nullptr); \
TEST_ASSERT(mm != nullptr); \
srn_engine_t *engine = srn_engine_make(mm, nullptr); \
TEST_ASSERT(engine != nullptr)
srn_mm_t * srn_mm_init(const srn_configuration_t *config)
Initialize the memory manager, this function will panic on error.
Definition default.c:337
srn_engine_t * srn_engine_make(srn_mm_t *mm, const srn_configuration_t *config)
Create the engine over mm, copying config (the runtime's knobs) into it.
Definition engine.c:103
Engine is a structure to own the long living and main pieces of the compiler.
Definition engine.h:54
Main memory manager structure that will own all the allocated blocks and data.
Definition interface.h:112

Definition at line 34 of file base.h.

34#define MAKE_ENGINE(mm, engine) \
35 srn_mm_t *mm = srn_mm_init(nullptr); \
36 TEST_ASSERT(mm != nullptr); \
37 srn_engine_t *engine = srn_engine_make(mm, nullptr); \
38 TEST_ASSERT(engine != nullptr)

◆ RELEASE_CONTEXT

#define RELEASE_CONTEXT ( x)
Value:
int srn_context_release(srn_context_t *ctx)
Definition context.c:64

Definition at line 48 of file base.h.

◆ SHUTDOWN_ENGINE

#define SHUTDOWN_ENGINE ( mm,
engine )
Value:
srn_mm_shutdown(mm)
void srn_engine_shutdown(srn_engine_t *engine)
Definition engine.c:174

Definition at line 40 of file base.h.

40#define SHUTDOWN_ENGINE(mm, engine) \
41 srn_engine_shutdown(engine); \
42 srn_mm_shutdown(mm)

◆ TEST_IN_FIBER

#define TEST_IN_FIBER ( name,
body )
Value:
static srn_fiber_result_t test_##name##_fiber(srn_context_t *ctx, void *arg) { \
UNUSED(arg); \
{ \
body \
} \
return nullptr; \
} \
static void test_##name() { \
MAKE_ENGINE(mm, engine); \
MAKE_CONTEXT(engine, ctx); \
srn_scheduler_t *sched = engine->scheduler; \
srn_fiber_spawn(ctx, test_##name##_fiber, nullptr); \
srn_sched_run(sched, 1); \
RELEASE_CONTEXT(ctx); \
SHUTDOWN_ENGINE(mm, engine); \
}
struct srn_scheduler_t srn_scheduler_t
Definition engine.h:40
void * srn_fiber_result_t
What a fiber's entry produces, type-erased.
Definition fiber.h:171
void * arg

Definition at line 67 of file base.h.

67#define TEST_IN_FIBER(name, body) \
68 static srn_fiber_result_t test_##name##_fiber(srn_context_t *ctx, void *arg) { \
69 UNUSED(arg); \
70 { \
71 body \
72 } \
73 return nullptr; \
74 } \
75 static void test_##name() { \
76 MAKE_ENGINE(mm, engine); \
77 MAKE_CONTEXT(engine, ctx); \
78 srn_scheduler_t *sched = engine->scheduler; \
79 srn_fiber_spawn(ctx, test_##name##_fiber, nullptr); \
80 srn_sched_run(sched, 1); \
81 RELEASE_CONTEXT(ctx); \
82 SHUTDOWN_ENGINE(mm, engine); \
83 }

◆ TEST_IN_FIBER_WITH

#define TEST_IN_FIBER_WITH ( name,
arg_expr,
body )
Value:
static srn_fiber_result_t test_##name##_fiber(srn_context_t *ctx, void *arg) { \
{ \
body \
} \
return nullptr; \
} \
static void test_##name() { \
MAKE_ENGINE(mm, engine); \
MAKE_CONTEXT(engine, ctx); \
srn_scheduler_t *sched = engine->scheduler; \
srn_fiber_spawn(ctx, test_##name##_fiber, (arg_expr)); \
srn_sched_run(sched, 1); \
RELEASE_CONTEXT(ctx); \
SHUTDOWN_ENGINE(mm, engine); \
}

Definition at line 50 of file base.h.

50#define TEST_IN_FIBER_WITH(name, arg_expr, body) \
51 static srn_fiber_result_t test_##name##_fiber(srn_context_t *ctx, void *arg) { \
52 { \
53 body \
54 } \
55 return nullptr; \
56 } \
57 static void test_##name() { \
58 MAKE_ENGINE(mm, engine); \
59 MAKE_CONTEXT(engine, ctx); \
60 srn_scheduler_t *sched = engine->scheduler; \
61 srn_fiber_spawn(ctx, test_##name##_fiber, (arg_expr)); \
62 srn_sched_run(sched, 1); \
63 RELEASE_CONTEXT(ctx); \
64 SHUTDOWN_ENGINE(mm, engine); \
65 }

◆ TEST_NO_ERROR

#define TEST_NO_ERROR ( x)
Value:
TEST_CHECK((x).maybe_error == nullptr)
#define TEST_CHECK(cond)
Definition acutest.h:95

Definition at line 32 of file base.h.