aboutsummaryrefslogtreecommitdiff
path: root/tools/100_checkdata/checkdata.c
blob: 3a3c09807795501f612cc847621486a34ada70f7 (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
#include "../tool.h"

char *solver, *filename;

static void
run(void) {
	bool result;
	long long int size, sizeread;
	char dataid[NISSY_SIZE_DATAID];
	unsigned char *buf;
	FILE *f;
	
	size = nissy_solverinfo(solver, dataid);

	if (size <= 0) {
		printf("Error in solverinfo\n");
		return;
	}

	if ((f = fopen(filename, "rb")) == NULL) {
		printf("Error reading file %s\n", filename);
		return;
	}

	buf = malloc(size);
	sizeread = fread(buf, size, 1, f);
	fclose(f);
	if (sizeread != 1)
		printf("File has unexpected size\n");
	result = sizeread == 1 && nissy_checkdata(solver, size, buf) == NISSY_OK;
	free(buf);

	printf("checkdata %s\n", result ? "succeeded" : "failed");

	/* TODO: cross-check with expected distributions? */
}

int main(int argc, char **argv) {
	if (argc < 3) {
		printf("Error: not enough arguments. "
		    "A solver and a file name must be given.\n");
		return 1;
	}

	solver = argv[1];
	filename = argv[2];
	nissy_setlogger(log_stderr, NULL);

	timerun(run);

	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net