Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
engine_tests.h
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "base.h"
22
23#define CTX_TESTS(X) \
24 X("engine::make", test_engine_make), X("engine::srn_hash", test_srn_hash)
25
26static void test_engine_make() {
27 MAKE_ENGINE(mm, engine);
28 ASSERT_NOT_NULL(engine);
29 ASSERT_NOT_NULL(engine->mm);
30 ASSERT_NOT_NULL(engine->jit);
31}
32
33// Supert dumb tests to check whether xxhash and our seed
34// work as expected or not. Soooo dump.
35static void test_srn_hash() {
36 MAKE_ENGINE(mm, engine);
37
38 engine->seed = 0xA5F17C3DU;
39
40 const char *data = "serene";
41 srn_hash_t h = srn_hash(engine, (void *)data, strlen(data));
42 TEST_CHECK(h == 0x76ea5383);
43
44 typedef struct d {
45 int foo;
46 int bar;
47 } d;
48
49 const d test1 = {.foo = 10, .bar = 22};
50 const d test2 = {.foo = 10, .bar = 12};
51
52 srn_hash_t h1 = srn_hash(engine, (void *)&test1, sizeof(test1));
53 srn_hash_t h2 = srn_hash(engine, (void *)&test2, sizeof(test2));
54 TEST_CHECK(h1 == 0xf240658b);
55 TEST_CHECK(h2 == 0x177e0a92);
56}
#define TEST_CHECK(cond)
Definition acutest.h:96
#define ASSERT_NOT_NULL(x)
Definition base.h:30
#define MAKE_ENGINE(mm, engine)
Definition base.h:32
SRN_HASH_TYPE srn_hash_t
Definition context.h:44
srn_hash_t srn_hash(const srn_engine_t *engine, const void *data, size_t len)
Definition engine.c:131
static void test_srn_hash()
static void test_engine_make()