File: testapplication.c

package info (click to toggle)
kissat 4.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,068 kB
  • sloc: ansic: 39,201; sh: 1,226; makefile: 91
file content (62 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download | duplicates (2)
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
#include "../src/application.h"
#include "../src/file.h"

#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "test.h"

static char *copy_string (const char *begin, const char *end) {
  const size_t len = end - begin;
  char *res = malloc (len + 1);
  memcpy (res, begin, len);
  res[len] = 0;
  return res;
}

void tissat_call_application (int expected, const char *cmd) {
#define MAX_ARGC 8
  char *argv[MAX_ARGC];
  int argc = 0;
  argv[argc++] = "kissat";
  for (const char *p = cmd, *start = cmd;; p++)
    if (!*p || *p == ' ') {
      if (argc == MAX_ARGC)
        FATAL ("MAX_ARGC exceeded");
      argv[argc++] = copy_string (start, p);
      if (!*p)
        break;
      start = ++p;
    }
#undef MAX_ARGC
  kissat *solver = kissat_init ();
  tissat_init_solver (solver);
  tissat_redirect_stderr_to_stdout ();
  int res = kissat_application (solver, argc, argv);
  tissat_restore_stderr ();
  if (res != expected)
    FATAL ("'kissat %s' returns '%d' and not '%d'", cmd, res, expected);
  kissat_release (solver);
  for (int i = 1; i < argc; i++)
    free (argv[i]);
  tissat_verbose ("Application 'kissat %s' returned '%d' as expected.", cmd,
                  res);
}

const char *tissat_options[] = {
    "",
#if !defined(QUIET) && !defined(NOPTIONS)
    "-q ", "-s ", "-v ", "-s -v ",
#endif
};

#define SIZE_OPTIONS (sizeof (tissat_options) / sizeof (char *))
const unsigned tissat_size_options = SIZE_OPTIONS;
const char **tissat_end_of_options = tissat_options + SIZE_OPTIONS;

const char *tissat_next_option (unsigned count) {
  assert (tissat_size_options);
  return tissat_options[count % tissat_size_options];
}