File: tester-plaf.hh

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (102 lines) | stat: -rw-r--r-- 3,429 bytes parent folder | download | duplicates (4)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (C) 2007 Zack Weinberg <zackw@panix.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

#ifndef __TESTER_PLAF_HH__
#define __TESTER_PLAF_HH__

// this describes functions to be found, alternatively, in win32/* or unix/*
// directories and used only by the tester.

#include <ctime>

std::time_t get_last_write_time(char const * name);
void do_copy_file(std::string const & from, std::string const & to);
void set_env(char const * var, char const * val);
void unset_env(char const * var);
int do_umask(int mask);
char * make_temp_dir();
bool running_as_root();

// This function has a decidedly awkward interface because (a) Windows
// doesn't have fork(), (b) platform files can't talk directly to the Lua
// interpreter.  [Also it would be nice not to have to declare the full
// content of the callback functors, but that is not so bad.]
//
// next_test() is called repeatedly until it returns false.  Each time it
// returns true, it shall fill in its test_to_run argument with the number
// and name of the next test to run.
//
// For each such test, *either* invoke() is called in a forked child
// process, *or* the program named in 'runner' is spawned with argument
// vector [runner, '-r', testfile, firstdir, test-name].  Either way, the
// child process is running in a just-created, empty directory which is
// exclusive to that test.  Standard I/O is not touched; the child is
// expected not to use stdin, stdout, or stderr.  If invoke() is called,
// its return value is the process exit code.
//
// After each per-test child process completes, cleanup() is called for that
// test.  If cleanup() returns true, the per-test directory is deleted.

struct lua_State;

struct test_to_run
{
  int number;
  std::string name;
};

struct test_enumerator
{
  lua_State * st;
  int table_ref;
  mutable int last_index;
  mutable bool iteration_begun;
  test_enumerator(lua_State *st, int t)
    : st(st), table_ref(t), last_index(0), iteration_begun(false) {}
  bool operator()(test_to_run & next_test) const;
};

struct test_invoker
{
  lua_State * st;
  test_invoker(lua_State *st) : st(st) {}
  int operator()(std::string const & testname) const;
};

struct test_cleaner
{
  lua_State * st;
  int reporter_ref;
  test_cleaner(lua_State *st, int r) : st(st), reporter_ref(r) {}
  bool operator()(test_to_run const & test, int status,
                  int wall_seconds, int cpu_seconds) const;
};

void run_tests_in_children(test_enumerator const & next_test,
                           test_invoker const & invoke,
                           test_cleaner const & cleanup,
                           std::string const & run_dir,
                           std::string const & runner,
                           std::string const & testfile,
                           std::string const & firstdir);
void prepare_for_parallel_testcases(int, int, int);

// These functions are actually in tester.cc but are used by tester-plaf.cc.
void do_remove_recursive(std::string const & dir);

#endif


// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: