File: utest.c

package info (click to toggle)
bart 0.9.00-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,040 kB
  • sloc: ansic: 116,116; python: 1,329; sh: 726; makefile: 639; javascript: 589; cpp: 106
file content (75 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright 2016. The Regents of the University of California.
 * Copyright 2016. Martin Uecker.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2016 Jonathan Tamir <jtamir@eecs.berkeley.edu>
 * 2016 Martin Uecker <martin.uecker@med.uni-goettingen.de>
 */

#include <stdlib.h>

#include "misc/debug.h"
#include "misc/misc.h"

#include "num/mpi_ops.h"

#include "utest.h"


#if 0
/* A linker script is used to assemble a list of all
 * registered unit tests and to set begin and end.
 */
extern ut_test_f* _utests_begin;
extern ut_test_f* _utests_end;
#else
/* A shell script called by make is used to create
 * the list of registered unit tests in UTESTS.
 * This also works on MacOS X.
 */
extern ut_test_f
UTESTS
dummy;

ut_test_f* ut_tests[] = {
UTESTS
};

#define _utests_begin	(ut_tests[0])
#define _utests_end	(ut_tests[ARRAY_SIZE(ut_tests)])
#endif


int main(int argc, char* argv[])
{
#ifdef USE_MPI
	init_mpi(&argc, &argv);
#endif

	UNUSED(argc);

	int num_tests_run = 0;
	int num_tests_pass = 0;

	for (ut_test_f** ptr = &_utests_begin; ptr != &_utests_end; ptr++) {

		if ((**ptr)())
			num_tests_pass++;
		else
			debug_printf(DP_ERROR, "Test %d failed.\n", num_tests_run);

		num_tests_run++;
	}

	bool good = (num_tests_pass == num_tests_run);

	debug_printf(good ? DP_INFO : DP_ERROR, "%20s: %2d/%2d passed.\n", argv[0], num_tests_pass, num_tests_run);

	deinit_mpi();

	exit(good ? 0 : 1);
}