Skip to content

Commit c51a59e

Browse files
committed
test: simple test for the checkpoint mechanism
Usage example: check/check.rb -C check/checkpoint /path/to/form Unix is required and ParFORM is not supported for now. This regression test ensures that future FORM enhancements will not break the checkpoint mechanism, at least for some simple cases. The following features are added to check.rb: - Export FORM environment variable for tests. Note that it may contain spaces, e.g., FORM="tform -w4". - Add unix?, which is (cygwin? || mac? || linux?).
1 parent 32e9920 commit c51a59e

4 files changed

Lines changed: 128 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- {bin: form, test: default, timeout: 10}
1919
- {bin: tform, test: default, timeout: 10}
2020
- {bin: parform, test: default, timeout: 15}
21+
- {bin: form, test: checkpoint, timeout: 10}
22+
- {bin: tform, test: checkpoint, timeout: 10}
2123
- {bin: form, test: forcer, timeout: 60}
2224
- {bin: tform, test: forcer, timeout: 60}
2325
steps:

check/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ endif
2727
TESTS += benchmark-fu.sh
2828

2929
EXTRA_DIST = \
30-
check-help.sh \
3130
benchmark-fu.sh \
31+
check-help.sh \
3232
check.rb \
33+
checkpoint/checkpoint.frm \
3334
examples.frm \
3435
features.frm \
3536
fixes.frm \

check/check.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def linux?
235235
RUBY_PLATFORM =~ /linux/i
236236
end
237237

238+
def unix?
239+
cygwin? || mac? || linux?
240+
end
241+
238242
def travis?
239243
ENV["TRAVIS"] == "true"
240244
end
@@ -307,6 +311,7 @@ def do_test(&block)
307311
@stderr = ""
308312
begin
309313
nfiles.times do |i|
314+
ENV["FORM"] = FormTest.cfg.form_cmd
310315
@filename = "#{i + 1}.frm"
311316
execute("#{FormTest.cfg.form_cmd} #{@filename}")
312317
if !finished?

check/checkpoint/checkpoint.frm

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#ifndef `TEST'
2+
#message Use -D TEST=XXX
3+
#terminate
4+
#else
5+
#include `NAME_' # `TEST'
6+
#endif
7+
.end
8+
9+
*--#[ checkpoint_1 :
10+
* This program is intended to be executed 4 times, for example,
11+
* form -D TEST=checkpoint_1 checkpoint.frm # ok
12+
* form -D TEST=checkpoint_1 checkpoint.frm # fail
13+
* form -D TEST=checkpoint_1 -R checkpoint.frm # fail
14+
* form -D TEST=checkpoint_1 -R checkpoint.frm # ok
15+
* We check the result at the end of the program, by which we expect
16+
* possible deficits in snapshot/recovery would be detected.
17+
* Unix is required. ParFORM is not supported.
18+
#ifndef `N'
19+
#define N "8"
20+
#endif
21+
22+
#ifdef `QUIET'
23+
Off stats;
24+
#endif
25+
26+
#define StopThenContinueLockFilePrefix ".stc-"
27+
#define StopThenContinueCounter "0"
28+
29+
#procedure StopThenContinue(?exitcode)
30+
#ifdef `?exitcode'
31+
#define exitcode "`?exitcode'"
32+
#else
33+
#define exitcode "-1"
34+
#endif
35+
#define counter "`StopThenContinueCounter++'"
36+
#define lockfilename "`StopThenContinueLockFilePrefix'`counter'.tmp"
37+
* NOTE: for timestamps, the checkpoint feature uses TimeWallClock(),
38+
* which has only a centisecond precision. We may need some sleep
39+
* to guarantee that a snapshot file will be created (for low N,
40+
* in particular; though the wall clock value is supposed to increase
41+
* monotonically, I experienced cases where
42+
* TimeWallClock(1) - AC.CheckpointStamp == -1).
43+
* 0.05 seconds should be enough, but the POSIX sleep command assumes
44+
* an integral number as its argument; we fall back to 1 second when
45+
* it does not work.
46+
#system sleep 0.05 2>/dev/null || sleep 1
47+
.sort:StopThenContinue-`counter';
48+
#system -e test -f `lockfilename'
49+
#define error "`SYSTEMERROR_'"
50+
#write <`lockfilename'> ""
51+
#close <`lockfilename'>
52+
#if `error'
53+
#message Program intentionally stopped at `counter' (exitcode=`exitcode')
54+
#terminate `?exitcode'
55+
#endif
56+
#remove <`lockfilename'>
57+
#endprocedure
58+
59+
#procedure AssertEqual(expr1,expr2)
60+
#$AssertEqualExpr1 = `expr1';
61+
#$AssertEqualExpr2 = `expr2';
62+
#$AssertEqualExpr3 = $AssertEqualExpr1 - $AssertEqualExpr2;
63+
#$AssertEqualExpr1 = nterms_($AssertEqualExpr3);
64+
#if `$AssertEqualExpr1' == 0
65+
#message Assertion OK: `expr1' == `expr2'
66+
#else
67+
#message Assertion Failed: `expr1' == `expr2'
68+
#terminate
69+
#endif
70+
#endprocedure
71+
72+
#call StopThenContinue(0)
73+
74+
On checkpoint;
75+
Auto S x;
76+
L F = (x1+...+x15);
77+
L G = (x1+...+x15)^`N';
78+
#$n1 = 6;
79+
#$e1 = 1+x1+...+x15;
80+
#define a1 "20"
81+
.sort
82+
83+
#call StopThenContinue()
84+
85+
id x1 = x1 + x2 + x3 + x4 + x5;
86+
#$n2 = 7;
87+
#$e2 = x1+...+x15;
88+
#define a2 "21"
89+
.sort
90+
91+
#call StopThenContinue()
92+
93+
id x6 = -x1;
94+
id x7 = -x2;
95+
id x8 = -x3;
96+
id x9 = -x4;
97+
id x10 = -x5;
98+
id x11 = -x2;
99+
id x12 = -x3;
100+
id x13 = -x4;
101+
id x14 = -x5;
102+
#$e3 = $e1 - $e2;
103+
#message x15 -> {`$n1'*`$n2'-`a1'-`a2'+`$e3'}
104+
id x15 = {`$n1'*`$n2'-`a1'-`a2'+`$e3'};
105+
#ifndef `QUIET'
106+
Print;
107+
#endif
108+
.sort
109+
#call AssertEqual(F,2)
110+
#call AssertEqual(G,{2^`N'})
111+
.end
112+
#system -e `FORM' 1.frm
113+
#system -e `FORM' -R 1.frm
114+
#system `FORM' -R 1.frm
115+
.end
116+
#require unix?
117+
#pend_if mpi? || valgrind?
118+
assert succeeded?
119+
*--#] checkpoint_1 :

0 commit comments

Comments
 (0)