source: git/Singular/LIB/tst.lib @ 620c25

spielwiese
Last change on this file since 620c25 was 620c25, checked in by Olaf Bachmann <obachman@…>, 26 years ago
* changes to facilitate tst_status checks git-svn-id: file:///usr/local/Singular/svn/trunk@2319 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.2 KB
Line 
1// $Id: tst.lib,v 1.11 1998-07-14 06:50:11 obachman Exp $
2//(obachman, last modified 6/30/98)
3/////////////////////////////////////////////////////////////////////////////
4
5version="$Id: tst.lib,v 1.11 1998-07-14 06:50:11 obachman Exp $";
6info="
7LIBRARY:  tst.lib      PROCEDURES FOR RUNNING AUTOMATIC TST TESTS
8
9
10 tst_system(s)          returns string which is stdout of system(\"sh\", s)
11 tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout),
12                                   prepending prefix \"// tst_ignore:\"
13 tst_init()             writes some identification data to GetTstStatusFile()
14 tst_status([any])      writes status info to to GetTstStatusFile()
15 tst_groebnerTest(ideal i) 
16                        tests groebner command
17 tst_stdEqual(ideal i1, ideal i2)
18                        test whether two std's are \"equal\"
19";
20
21/////////////////////////////////////////////////////////////////////////////
22
23proc tst_system(string s, list #)
24"USAGE:    tst_system(s); s string
25RETURN:   string which is stdout and stderr of system(\"sh\", s)
26EXAMPLE:  example tst_system; shows examples"
27{
28  string tmpfile = "/tmp/tst_" + string(system("pid"));
29  int errno;
30
31  s = s + " 1>" + tmpfile + " 2>&1";
32  errno = system("sh", s);
33  s = read(tmpfile);
34  errno = system("sh", "rm -f " + tmpfile);
35  if (size(#) > 0)
36  {
37      s = s[1, size(s) -1];
38  }
39  return (s);
40}
41example
42{
43  "EXAMPLE"; echo = 2;
44  string s = tst_system("echo This is is an example of tst_system");
45  "The following is what the system call wrote to stdout: " + s;
46}
47
48proc tst_ignore(list #)
49"USAGE:    tst_ignore(any,[keyword], [link])
50            any     -- valid argument to string()
51            keyword -- an arbitrary string
52            link    -- a link which can be written to
53RETURN:   none; writes string(any) to link (or stdout, if no link given),
54          prepending prefix \"// tst_ignore:\", or
55                            \"// tst_ignore:keyword hostname:\",
56                            if keyword was given.
57          Should be used in tst files to output system dependent data
58          (like date, pathnames).
59EXAMPLE:  example tst_ignore; shows examples
60"
61{
62  string s;
63  string keyword = "";
64  link outlink = "";
65
66  // Check # of args
67  if (size(#) < 1 || size(#) > 3)
68  {
69    "Error tst_ignore: Wrong number of arguments";
70    "Usage: tst_ignore (any,[keyword], [link]);";
71    return();
72  }
73
74  // Get Args
75  s = string(#[1]);
76  if (size(#) == 3)
77  {
78    keyword = #[2];
79    outlink = #[3];
80  }
81  if (size(#) == 2)
82  {
83    if (typeof(#[2]) == "string")
84    {
85      keyword = #[2];
86    }
87    else
88    {
89      outlink = #[2];
90    }
91  }
92
93  // check args
94  if (typeof(keyword) != "string")
95  {
96    "Error tst_ignore: Keyword must be a string";
97    "Usage: tst_ignore (any,[keyword], [link]);";
98    return();
99  }
100
101  if (status(outlink, "open", "no"))
102  {
103    open(outlink);
104  }
105
106  if (status(outlink, "write", "not ready"))
107  {
108    "Error tst_ignore: Can not write to link";
109    outlink;
110    "Usage: tst_ignore (any,[keyword], [link]);";
111    return();
112  }
113
114  // ready -- do the actual work
115  if (keyword != "")
116  {
117    write(outlink,"// tst_ignore:" + keyword + " :: " + tst_system("hostname", 1) + ":" + s);
118  }
119  else
120  {
121    write(outlink, "// tst_ignore: " + s);
122  }
123}
124example
125{
126  "EXAMPLE";
127  "System independent data can safely be output in tst files;";
128  "However, system dependent data like dates, or pathnames, should be output";
129  "using the command tst_ignore(...), like";
130  echo = 2;
131  tst_ignore(tst_system("date"));
132  int t1 = timer;
133  tst_ignore(t1, "time");
134  tst_ignore(memory(1), "memory");
135}
136
137static proc Get_tst_timer()
138{
139  if (! defined (tst_timer))
140  {
141    string tst_timer = "// tst_ignore:0";
142    export tst_timer;
143    return (0);
144  }
145  else
146  {
147    execute "int tst_int_timer = " + tst_timer[15,size(tst_timer)] + ";";
148    return (tst_int_timer);
149  }
150}
151
152static proc Set_tst_timer (int this_time)
153{
154  tst_timer = tst_timer[1,14] + string(this_time);
155}
156
157static proc GetTstStatusFile()
158{
159  if (!defined(tst_status_file))
160  {
161    return ("tst_status.out");
162  }
163  else
164  {
165    return (tst_status_file);
166  }
167}
168 
169static proc tst_status_out (def prefix, def what, list #)
170{
171  string outstring;
172 
173  outstring = string(prefix) + " >> " + string(what);
174  if (size(#) > 0)
175  {
176    outstring = outstring + " :: " +
177      tst_system("hostname", 1) + ":" + string(#[1]);
178  }
179  write(":a " + GetTstStatusFile(), outstring);
180}
181 
182proc tst_status (list #)
183"USAGE:   tst_status([any])
184RETURN:   none; writes to stdout the current memory usage and used time
185          since last call to tst_status(), if no argument is given, or,
186          since start-up of Singular, if an argument is given.
187NOTE:     Should be used regularly within tst files to enable automatic
188          tracking of memory and time performance.
189EXAMPLE: example tst_status; shows example
190"
191{
192  if (! defined(tst_status_counter))
193  {
194    int tst_status_counter = 1;
195    export tst_status_counter;
196  }
197  else
198  {
199    tst_status_counter++;
200  }
201 
202  tst_status_out(tst_status_counter, "tst_memory_0", memory(0));
203  tst_status_out(tst_status_counter, "tst_memory_1", memory(1));
204  tst_status_out(tst_status_counter, "tst_memory_2", memory(2));
205  if (size(#) > 0)
206  {
207    tst_status_out(tst_status_counter, "tst_timer_1", timer);
208  }
209  else
210  {
211    tst_status_out(tst_status_counter, "tst_timer", timer - Get_tst_timer());
212    Set_tst_timer(timer);
213  }
214  string(tst_status_counter) + " >> " + GetTstStatusFile();
215}
216example
217{
218  "EXAMPLE";  echo = 2;
219  tst_status();
220  ring r;
221  poly p = (x+y+z)^40;
222  tst_status();
223  tst_status(1);
224}
225
226 
227proc tst_init()
228"USAGE:   tst_init()
229RETURN:  none; writes some identification data to stdout;
230         should be called as first routine in a tst file
231EXAMPLE: example tst_init; shows example
232"
233{
234  write(":w " + GetTstStatusFile(), "Status Output of " + GetTstStatusFile());
235  tst_status_out("init", "USER    :" + system("getenv", "USER"));
236  tst_status_out("init", "HOSTNAME:" + tst_system("hostname", 1));
237  tst_status_out("init", "uname -a:" + tst_system("uname -a", 1));
238  tst_status_out("init", "date    :" + tst_system("date", 1));
239  tst_status_out("init", "version :" + string(system("version")));
240  tst_status_out("init", "ticks   :" + system("--ticks-per-sec"));
241  "init >> " + GetTstStatusFile();
242}
243example
244{
245  "EXAMPLE";  echo = 2;
246  tst_init();
247}
248
249///////////////////////////////////////////////////////////////////////
250
251proc tst_groebnerTest(ideal i, list #)
252"USAGE: tst_groebnerTesti,[v]) : ideal i, [int v]
253RETURN: 1, if groebner command produced \"equal\" std as std command
254        0, otherwise
255        Two std's are \"equal\" here, if their redSB's are element-wise equal,
256        and if they reduce each other to zero, and if their leading ideals
257        are equal
258        On success, times of std - groebner is written with tst_ignore, and
259        times are added to global variables tst_std_time and
260        tst_groebner_time. If v given, and <= 0, short ideal
261        characteristic is printed, if v > 0, ideals are printed.
262        On failure, Error message and ideals are printed.
263EXAMPLE: example tst_groebner; shows an example
264"
265{
266  int st = timer;
267  ideal si = std(i);
268  st = timer - st;
269 
270  int gt = timer;
271  ideal gi = groebner(i);
272  gt = timer - gt;
273
274  if (tst_stdEqual(si, gi))
275  {
276    tst_ignore(string(st) + " - " + string(gt) + " == " + string(st - gt));
277    if (! defined(tst_groebner_time))
278    {
279      int tst_groebner_time;
280      int tst_std_time;
281      export tst_groebner_time, tst_std_time;
282    }
283    tst_std_time = tst_std_time + st;
284    tst_groebner_time = tst_groebner_time + gt;
285    if (size(#))
286    {
287      if (typeof(#[1] == "int"))
288      {
289        if (#[1] <= 0)
290        {
291          idPrintShort(si, "si");
292          idPrintShort(gi, "gi");
293        }
294        else
295        {
296          si;
297          gi;
298        }
299      }
300    }
301    return (1);
302  }
303  return (0);
304}
305example
306{
307  "EXAMPLE: "; echo = 2;
308  ring r = 0, (a,b,c,d), lp;
309  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
310  tst_groebnerTest(i);
311  tst_groebnerTest(i, 0);
312  tst_groebnerTest(i, 1);
313}
314
315 
316//
317// A routine which test for equality of "std-bases"
318//
319proc tst_stdEqual(ideal i1, ideal i2)
320"USAGE: tst_stdEqual(i1, i2)  ideal i1, i2
321RETURN 1, if i1 \"equald\" i2 as a std bases
322       0, otherwise
323       Two std's are \"equal\" here, if their redSB's are element-wise equal,
324       and if they reduce each other to zero, and if their leading ideals
325       are equal
326       On failure, error message is printed.
327EXAMPLE: example tst_stdEqual; shows an example
328"
329{
330  int i;
331  int back;
332  intvec opts = option(get);
333  option(redSB);
334 
335  ideal ri1 = simplify(interred(i1), 1);
336  ideal ri2 = simplify(interred(i2), 1);
337 
338  option(set, opts);
339
340  if (size(ri1) != size(ri2))
341  {
342    "Error in tst_stdEqual: Reduced sizes differ";
343    size(ri1);
344    size(ri2);
345    return(0);
346  }
347
348  for (i=1; i<=size(ri1); i++)
349  {
350    if (ri1[i] != ri2[i])
351    {
352      "Error in tst_stdEqual: " + string(i) + " th poly differ";
353      ri1[i];
354      ri2[i];
355      return(0);
356    }
357  }
358
359  // reduced SB are now equal
360  if (size(reduce(i1, i2, 1)) == 0)
361  {
362    if (size(reduce(i2, i1, 1)) == 0)
363    {
364      poly p1, p2;
365     
366      ideal si1 = simplify(i1, 7);
367      ideal si2 = simplify(i2, 7);
368     
369      if (size(si1) == size(si2))
370      {
371        for (i=1; i<=size(si1); i++)
372        {
373          p1 = p1 + lead(si1[i]);
374          p2 = p2 + lead(si2[i]);
375        }
376        if (p1 != p2)
377        {
378          "Error in tst_stdEqual: Lead monoms differ:";
379          p1;
380          p2;
381          return(0);
382        }
383      }
384      else
385      {
386        "Error in tst_stdEqual: size differs:";
387        size(si1);
388        size(si2);
389        return(0);
390      }
391    }
392    else
393    {
394      "Error in tst_stdEqual: reduce(i2, i1) != 0";
395      return(0);
396    }
397  }
398  else
399  {
400    back = 1; "Error in tst_stdEqual: reduce(i1, i2) != 0";
401    return(0);
402  }
403
404  return (1);
405}
406example
407{
408  "EXAMPLE: "; echo = 2;
409  ring r = 0, (a,b,c,d), lp;
410  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
411  tst_stdEqual(groebner(i), std(i));
412  tst_stdEqual(std(i), i);
413}
414
415static proc idPrintShort(ideal id, string name)
416{
417  "Summary of " + name + " (leading monoms and size of polys):";
418  int i;
419  for (i = 1; i<=size(id); i++)
420  {
421    "[" + string(i) + "]: #" + string(size(id[i])) + ":" + string(lead(id[i]));
422  }
423}
424
425 
426
427
Note: See TracBrowser for help on using the repository browser.