Serene Runtime 1.0.0-dev
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) X("engine::make", test_engine_make), X("engine::srn_hash", test_srn_hash)
24
25static void test_engine_make() {
26 MAKE_ENGINE(mm, engine);
27 ASSERT_NOT_NULL(engine);
28 ASSERT_NOT_NULL(engine->mm);
29 ASSERT_NOT_NULL(engine->jit);
30}
31
32// Supert dumb tests to check whether xxhash and our seed
33// work as expected or not. Soooo dump.
34static void test_srn_hash() {
35 MAKE_ENGINE(mm, engine);
36
37 engine->seed = 0xA5F17C3DU;
38
39 const char *data = "serene";
40 srn_hash_t h = srn_hash(engine, (void *)data, strlen(data));
41 TEST_CHECK(h == 0x76ea5383);
42
43 typedef struct d {
44 int foo;
45 int bar;
46 } d;
47
48 const d test1 = {.foo = 10, .bar = 22};
49 const d test2 = {.foo = 10, .bar = 12};
50
51 srn_hash_t h1 = srn_hash(engine, (void *)&test1, sizeof(test1));
52 srn_hash_t h2 = srn_hash(engine, (void *)&test2, sizeof(test2));
53 TEST_CHECK(h1 == 0xf240658b);
54 TEST_CHECK(h2 == 0x177e0a92);
55}
#define TEST_CHECK(cond)
Definition acutest.h:95
#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:166
static void test_srn_hash()
static void test_engine_make()