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

Contents of /trunk/test/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2551 - (show annotations) (download) (as text)
Thu Feb 2 20:14:50 2012 UTC (6 years, 10 months ago) by jpye
File MIME type: text/x-csrc
File size: 5382 byte(s)
Merge 'ospath_chdir' and 'ospath_getcwd' into trunk (from Leon).
Add detection of Ubuntu 11.10 in Sundials, since extra linkage to 'lapack' is required.
Disable defaultall output for the moment.

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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 Test runner for the 'base/generic' routines in ASCEND
21 */
22 #include <stdlib.h>
23 #include <string.h>
24 #include <getopt.h>
25
26 #include <ascend/utilities/config.h>
27 #include <ascend/general/platform.h>
28 #include <ascend/utilities/error.h>
29 #include <ascend/compiler/redirectFile.h>
30 #include <ascend/general/ascMalloc.h>
31
32 #include "printutil.h"
33 #include "test_globals.h"
34
35 #include <ascend/general/ospath.h>
36
37 #include <CUnit/Basic.h>
38
39 #ifdef __WIN32__
40 # include <windows.h>
41 #endif
42
43 extern int register_cunit_tests();
44
45 int list_suites(){
46 struct CU_TestRegistry *reg = CU_get_registry();
47 struct CU_Suite *suite = reg->pSuite;
48 fprintf(stderr,"Test suites found in registry:\n");
49 while(suite!=NULL){
50 fprintf(stderr,"\t%s\n", suite->pName);
51 suite = suite->pNext;
52 }
53 return CUE_NO_SUITENAME;
54 }
55
56 int list_tests(const char *suitename0){
57 char suitename[1000];
58 char *s;
59 const char *n;
60 /* locate the '.' separator and copy bits before that into suitename. */
61 for(s=suitename,n=suitename0; *n!='.' && *n!='\0' && s < suitename+999; *s++=*n++);
62 *s='\0';
63
64 struct CU_TestRegistry *reg = CU_get_registry();
65 struct CU_Suite *suite = reg->pSuite;
66 struct CU_Test *test;
67 while(suite!=NULL){
68 if(0==strcmp(suite->pName,suitename)){
69 fprintf(stderr,"Tests found in suite '%s':\n",suitename);
70 test = suite->pTest;
71 while(test!=NULL){
72 fprintf(stderr,"\t%s\n", test->pName);
73 test = test->pNext;
74 }
75 return CUE_NO_TESTNAME;
76 }
77 suite = suite->pNext;
78 }
79 fprintf(stderr,"Test suite '%s' not found in registry.\n",suitename);
80 return CUE_NO_SUITENAME;
81 }
82
83 /**
84 Main routine, handles command line options
85 */
86 int main(int argc, char* argv[]){
87 CU_BasicRunMode mode = CU_BRM_VERBOSE;
88 CU_ErrorAction error_action = CUEA_IGNORE;
89 CU_ErrorCode result;
90 char suitename[1000];
91 char list = 0;
92
93 #ifdef __WIN32__
94 SetErrorMode(SEM_NOGPFAULTERRORBOX);
95 #endif
96
97 struct FilePath *test_executable = ospath_new(argv[0]);
98 struct FilePath *test_dir = ospath_getdir(test_executable); /** Global Variable containing Path information about the test directory */
99 ospath_strncpy(test_dir,ASC_TEST_PATH,PATH_MAX);
100 ospath_free(test_dir);
101 ospath_free(test_executable);
102
103 static struct option long_options[] = {
104 {"on-error", required_argument, 0, 'e'},
105 {"verbose", no_argument, 0, 'v'},
106 {"silent", no_argument, 0, 's'},
107 {"normal", no_argument, 0, 'n'},
108 {"help", no_argument, 0, '?'},
109 {"usage", no_argument, 0, '?'},
110 {"list-suites",no_argument, 0, 'l'},
111 {"list-tests", required_argument, 0, 't'},
112 {0, 0, 0, 0}
113 };
114
115 /* getopt_long stores the option index here. */
116 int option_index = 0;
117
118 const char *usage =
119 "%s -vsne [SuiteName|SuiteName.testname] ...\n"
120 "Test ASCEND base/generic routines\n"
121 "options:\n"
122 " --verbose, -v full output, including memory checking\n"
123 " --silent, -s\n"
124 " --normal, -n\n"
125 " --on-error=[fail|abort|ignore], -e\n"
126 " --help\n"
127 " --list-suites, -l\n"
128 " --list-tests=SUITENAME, -tSUITENAME\n"
129 ;
130
131 char c;
132 while(-1 != (c = getopt_long (argc, argv, "vsne:t:l", long_options, &option_index))){
133 switch(c){
134 case 'v': mode = CU_BRM_VERBOSE; break;
135 case 's': mode = CU_BRM_SILENT; break;
136 case 'n': mode = CU_BRM_NORMAL; break;
137 case 'e':
138 if(0==strcmp(optarg,"fail")){
139 fprintf(stderr,"on error FAIL\n");
140 error_action = CUEA_FAIL;
141 }else if(0==strcmp(optarg,"abort")){
142 fprintf(stderr,"on error ABORT\n");
143 error_action = CUEA_ABORT;
144 break;
145 }else if(0==strcmp(optarg,"ignore")){
146 error_action = CUEA_IGNORE;
147 }
148 else{
149 fprintf(stderr,"Invalid argument for --on-error option!\n");
150 result = 1;
151 goto cleanup;
152 }
153 break;
154 case 'l':
155 list = 1;
156 suitename[0] = '\0';
157 break;
158 case 't':
159 list = 1;
160 strncpy(suitename, optarg, 999);
161 break;
162 case '?':
163 case 'h':
164 fprintf(stderr,usage,argv[0]);
165 result = 1;
166 goto cleanup;
167 default:
168 fprintf(stderr,"Unknown option -- '%c'", c);
169 fprintf(stderr,usage,argv[0]);
170 result = 2;
171 goto cleanup;
172 }
173 }
174
175 CU_initialize_registry();
176 register_cunit_tests();
177 CU_basic_set_mode(mode);
178 CU_set_error_action(error_action);
179
180 if(list){
181 if(strlen(suitename)){
182 list_tests(suitename);
183 }else{
184 list_suites();
185 }
186 goto cleanup;
187 }
188
189 if(optind < argc){
190 result = CU_basic_run_selected_tests(argc - optind, &argv[optind]);
191 }else{
192 result = CU_basic_run_tests();
193 }
194
195 cleanup:
196 if(mode == CU_BRM_VERBOSE)ascshutdown("Testing completed.");/* shut down memory manager */
197 CU_cleanup_registry();
198 return result;
199 }

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