/[ascend]/trunk/test/test.c
ViewVC logotype

Contents of /trunk/test/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2781 - (show annotations) (download) (as text)
Fri Jun 20 05:12:07 2014 UTC (4 years, 2 months ago) by jpye
File MIME type: text/x-csrc
File size: 5319 byte(s)
remove RCS comments per warnings from clang 3.4
1 /* ASCEND modelling environment
2 Copyright (C) 2005 Jerry St.Clair
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *//**
18 Test runner for the 'base/generic' routines in ASCEND
19 */
20 #include <stdlib.h>
21 #include <string.h>
22 #include <getopt.h>
23
24 #include <ascend/utilities/config.h>
25 #include <ascend/general/platform.h>
26 #include <ascend/utilities/error.h>
27 #include <ascend/compiler/redirectFile.h>
28 #include <ascend/general/ascMalloc.h>
29
30 #include "printutil.h"
31 #include "test_globals.h"
32
33 #include <ascend/general/ospath.h>
34
35 #include <CUnit/Basic.h>
36
37 #ifdef __WIN32__
38 # include <windows.h>
39 #endif
40
41 extern int register_cunit_tests();
42
43 int list_suites(){
44 struct CU_TestRegistry *reg = CU_get_registry();
45 struct CU_Suite *suite = reg->pSuite;
46 fprintf(stderr,"Test suites found in registry:\n");
47 while(suite!=NULL){
48 fprintf(stderr,"\t%s\n", suite->pName);
49 suite = suite->pNext;
50 }
51 return CUE_NO_SUITENAME;
52 }
53
54 int list_tests(const char *suitename0){
55 char suitename[1000];
56 char *s;
57 const char *n;
58 /* locate the '.' separator and copy bits before that into suitename. */
59 for(s=suitename,n=suitename0; *n!='.' && *n!='\0' && s < suitename+999; *s++=*n++);
60 *s='\0';
61
62 struct CU_TestRegistry *reg = CU_get_registry();
63 struct CU_Suite *suite = reg->pSuite;
64 struct CU_Test *test;
65 while(suite!=NULL){
66 if(0==strcmp(suite->pName,suitename)){
67 fprintf(stderr,"Tests found in suite '%s':\n",suitename);
68 test = suite->pTest;
69 while(test!=NULL){
70 fprintf(stderr,"\t%s\n", test->pName);
71 test = test->pNext;
72 }
73 return CUE_NO_TESTNAME;
74 }
75 suite = suite->pNext;
76 }
77 fprintf(stderr,"Test suite '%s' not found in registry.\n",suitename);
78 return CUE_NO_SUITENAME;
79 }
80
81 /**
82 Main routine, handles command line options
83 */
84 int main(int argc, char* argv[]){
85 CU_BasicRunMode mode = CU_BRM_VERBOSE;
86 CU_ErrorAction error_action = CUEA_IGNORE;
87 CU_ErrorCode result = 0;
88 char suitename[1000];
89 char list = 0;
90
91 #ifdef __WIN32__
92 SetErrorMode(SEM_NOGPFAULTERRORBOX);
93 #endif
94
95 struct FilePath *test_executable = ospath_new(argv[0]);
96 struct FilePath *test_dir = ospath_getdir(test_executable); /** Global Variable containing Path information about the test directory */
97 ospath_strncpy(test_dir,ASC_TEST_PATH,PATH_MAX);
98 ospath_free(test_dir);
99 ospath_free(test_executable);
100
101 static struct option long_options[] = {
102 {"on-error", required_argument, 0, 'e'},
103 {"verbose", no_argument, 0, 'v'},
104 {"silent", no_argument, 0, 's'},
105 {"normal", no_argument, 0, 'n'},
106 {"help", no_argument, 0, '?'},
107 {"usage", no_argument, 0, '?'},
108 {"list-suites",no_argument, 0, 'l'},
109 {"list-tests", required_argument, 0, 't'},
110 {0, 0, 0, 0}
111 };
112
113 /* getopt_long stores the option index here. */
114 int option_index = 0;
115
116 const char *usage =
117 "%s -vsne [SuiteName|SuiteName.testname] ...\n"
118 "Test ASCEND base/generic routines\n"
119 "options:\n"
120 " --verbose, -v full output, including memory checking\n"
121 " --silent, -s\n"
122 " --normal, -n\n"
123 " --on-error=[fail|abort|ignore], -e\n"
124 " --help\n"
125 " --list-suites, -l\n"
126 " --list-tests=SUITENAME, -tSUITENAME\n"
127 ;
128
129 char c;
130 while(-1 != (c = getopt_long (argc, argv, "vsne:t:l", long_options, &option_index))){
131 switch(c){
132 case 'v': mode = CU_BRM_VERBOSE; break;
133 case 's': mode = CU_BRM_SILENT; break;
134 case 'n': mode = CU_BRM_NORMAL; break;
135 case 'e':
136 if(0==strcmp(optarg,"fail")){
137 fprintf(stderr,"on error FAIL\n");
138 error_action = CUEA_FAIL;
139 }else if(0==strcmp(optarg,"abort")){
140 fprintf(stderr,"on error ABORT\n");
141 error_action = CUEA_ABORT;
142 break;
143 }else if(0==strcmp(optarg,"ignore")){
144 error_action = CUEA_IGNORE;
145 }
146 else{
147 fprintf(stderr,"Invalid argument for --on-error option!\n");
148 result = 1;
149 goto cleanup;
150 }
151 break;
152 case 'l':
153 list = 1;
154 suitename[0] = '\0';
155 break;
156 case 't':
157 list = 1;
158 strncpy(suitename, optarg, 999);
159 break;
160 case '?':
161 case 'h':
162 fprintf(stderr,usage,argv[0]);
163 result = 1;
164 goto cleanup;
165 default:
166 fprintf(stderr,"Unknown option -- '%c'", c);
167 fprintf(stderr,usage,argv[0]);
168 result = 2;
169 goto cleanup;
170 }
171 }
172
173 CU_initialize_registry();
174 register_cunit_tests();
175 CU_basic_set_mode(mode);
176 CU_set_error_action(error_action);
177
178 if(list){
179 if(strlen(suitename)){
180 list_tests(suitename);
181 }else{
182 list_suites();
183 }
184 goto cleanup;
185 }
186
187 if(optind < argc){
188 result = CU_basic_run_selected_tests(argc - optind, &argv[optind]);
189 }else{
190 result = CU_basic_run_tests();
191 }
192
193 cleanup:
194 if(mode == CU_BRM_VERBOSE)ascshutdown("Testing completed.");/* shut down memory manager */
195 CU_cleanup_registry();
196 return result;
197 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22