summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/picotls/deps/cifra/src/arm/ext/cutest.h
blob: fa3c5d8433af28e6b841016f0197166dd5ac3f36 (plain)
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
/* cutest, for embedded targets. */

#ifndef CUTEST_H
#define CUTEST_H

/* Main interface. */
#define TEST_LIST const struct test__ test_list__[]
#define TEST_CHECK(cond) test_check__((cond), __FILE__, __LINE__, #cond)
/* no TEST_CHECK_ -- we don't have a good enough printf */

/* Implementation */
#include "../semihost.h"

struct test__
{
  const char *name;
  void (*func)(void);
};

extern const struct test__ test_list__[];

static void test_check__(int cond, const char *file, int line, const char *expr)
{
  if (cond)
    return; /* pass */

  emit("Failed!\n");
  emit("File: "); emit(file); emit("\n");
  emit("Line: "); emit_uint32(line); emit("\n");
  emit("Expr: "); emit(expr); emit("\n");
  quit_failure();
}

static void run_test__(const struct test__ *t)
{
  emit("  "); emit(t->name); emit(": ");
  t->func();
  emit("OK\n");
}

int main(void)
{
  emit("Running tests:\n");

  for (const struct test__ *t = test_list__;
       t->name;
       t++)
  {
    run_test__(t);
  }
  emit("Success\n");
  quit_success();
}

#endif