aboutsummaryrefslogtreecommitdiff
path: root/tests/dag.c
blob: 806aa7546f97e71f37bf23827809cebdc74c714d (plain) (blame)
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
#include <stdio.h>
#include <errno.h>
#include <string.h>

#include "util.h"
#include "queue.h"
#include "evanix.h"
#include "solver_sjf.h"
#include "test.h"

/*
 *  A               C	  A     C
 *   \  +     +   /   =    \  /
 *   B     B    B           B
 */

struct evanix_opts_t evanix_opts = {
	.close_unused_fd = false,
	.isflake = false,
	.ispipelined = true,
	.isdryrun = false,
	.max_build = 0,
	.system = NULL,
	.solver_report = false,
	.check_cache_status = false,
	.solver = solver_sjf,
	.break_evanix = false,
};

static void test_merge()
{
	struct job *job, *a, *b, *c;
	FILE *stream;
	int ret;
	struct job *htab = NULL;

	stream = fopen("../tests/dag_merge.json", "r");
	test_assert(stream != NULL);

	/* A */
	ret = job_read(stream, &job);
	test_assert(ret == JOB_READ_SUCCESS);
	ret = queue_htab_job_merge(&job, &htab);
	test_assert(ret >= 0);
	a = job;

	/* B */
	ret = job_read(stream, &job);
	test_assert(ret == JOB_READ_SUCCESS);
	ret = queue_htab_job_merge(&job, &htab);
	test_assert(ret >= 0);
	b = job;

	/* C */
	ret = job_read(stream, &job);
	test_assert(ret == JOB_READ_SUCCESS);
	ret = queue_htab_job_merge(&job, &htab);
	test_assert(ret >= 0);
	c = job;

	ret = job_read(stream, &job);
	test_assert(ret == JOB_READ_EOF);

	test_assert(a->deps[0] == b);
	test_assert(a->deps[0] == c->deps[0]);

	fclose(stream);
}

int main(void)
{
	test_run(test_merge);
}