comparison m-toolbox/test/run_tests.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % Run many tests
2 %
3 % M Hewitson 27-04-07
4 %
5 %
6 clear all;
7
8
9 VERSION = '$Id: run_tests.m,v 1.25 2010/07/14 17:04:03 hewitson Exp $';
10
11 % load list of tests
12 test_list;
13
14 %% Run these tests
15
16 nt = 1:length(test_struct);
17
18 tstart = now;
19 results = [];
20 k = 1;
21 for n=nt
22 ctest = test_struct(n).name;
23 % try to run the test only if the file exists
24 if exist(ctest, 'file') == 2
25
26 disp(' ');
27 disp(' ');
28 disp('=================================');
29 disp('===');
30 disp(sprintf('=== Running: %s', ctest));
31 disp('===');
32 disp('=================================');
33 disp(' ');
34 disp(' ');
35
36 try
37 tic
38 eval(ctest)
39 results(k).test = ctest;
40 results(k).result = 'pass';
41 results(k).duration = toc;
42 catch
43 l_error = lasterror;
44 results(k).test = ctest;
45 results(k).result = ['fail Error message: ' strrep(l_error.message, char(10), ' ')];
46 results(k).duration = toc;
47 end
48 close all
49 else
50 results(k).test = ctest;
51 results(k).result = 'fail: test file not found';
52 results(k).duration = 0;
53 end
54 k = k + 1;
55 end
56 tend = now;
57
58 %% Post processing
59
60 npassed = 0;
61 for j=1:length(results)
62 r = results(j);
63 if strcmp(r.result, 'pass')
64 npassed = npassed + 1;
65 end
66 end
67
68 %% Write report
69
70 % get max test name
71 maxstr = 0;
72 for t=1:length(test_struct)
73 ctest = test_struct(t).name;
74 if length(ctest) > maxstr
75 maxstr = length(ctest);
76 end
77 end
78
79
80 v = ver('ltpda');
81
82 pth = utils.prog.get_curr_m_file_path(mfilename);
83
84 filename = [pth 'test_run_' strrep(strrep(datestr(now), ' ', '_'), ':', '_') '_' computer '.log'];
85
86 fd = fopen(filename, 'w+');
87
88 fprintf(fd, '%% Test run \n');
89 fprintf(fd, '%% \n');
90 fprintf(fd, '%% Started %s\n', strrep(datestr(tstart), ' ', '_'));
91 fprintf(fd, '%% Finished %s\n', strrep(datestr(tend), ' ', '_'));
92 fprintf(fd, '%% \n');
93 fprintf(fd, '%% \n');
94 fprintf(fd, '%% writen by %s / %s \n', mfilename, VERSION);
95 fprintf(fd, '%% \n');
96 fprintf(fd, '%% %d tests run\n', length(test_struct));
97 fprintf(fd, '%% %d tests passed\n', npassed);
98 fprintf(fd, '%% %d tests failed\n', length(test_struct)-npassed);
99 fprintf(fd, '%% \n');
100 fprintf(fd, '%% Tests run on %s with version %s of LTPDA\n', computer, v.Version);
101 fprintf(fd, '%% \n');
102 fprintf(fd, '%% \n');
103 fprintf(fd, '%% Test No | Test | Execution time [s] | pass/fail \n');
104 fprintf(fd, '\n');
105 fprintf(fd, '\n');
106
107 for j=1:length(results)
108 r = results(j);
109 fprintf(fd, '%03d %s %06.2f %s\n', j, utils.prog.strpad(r.test, maxstr), r.duration, r.result);
110 end
111
112
113 fprintf(fd, '\n');
114 fprintf(fd, '\n');
115 fprintf(fd, '%% END \n');
116
117 fclose(fd);
118 edit(filename);
119
120 % END