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

Contents of /trunk/test/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2332 - (show annotations) (download) (as text)
Fri Dec 24 00:29:41 2010 UTC (9 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 5495 byte(s)
Cleaning lint from some compiler/*.c files, removing debug output from bintoken.c.
Working to debug strange results from command "ASCENDLIBRARY=~/ascend/models LD_LIBRARY_PATH=~/ascend test/test compiler_basics.init compiler_basics.parse_string_module compiler_basics.instantiate_string".
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 ASC_IMPORT int register_cunit_tests();
40
41 extern struct FilePath* ASC_TEST_DIR;
42
43 /*
44 The following allows the CUnit tests to be run using a standalone executable
45 using the CUnit 'basic' interface.
46 */
47 int run_suite_or_test(char *name){
48 char suitename[1000];
49 char *s,*n;
50 for(s=suitename,n=name; *n!='.' && *n!='\0' && s < suitename+999; *s++=*n++);
51 *s='\0';
52 struct CU_TestRegistry *reg = CU_get_registry();
53 struct CU_Suite *suite = reg->pSuite;
54 struct CU_Test *test;
55 if(suite==NULL){
56 fprintf(stderr,"No suites present in registry!\n");
57 return CUE_NO_SUITENAME;
58 }
59
60 CU_ErrorCode result;
61 while(suite!=NULL){
62 fprintf(stderr,"Looking at suite %s\n", suite->pName);
63 if(0==strcmp(suite->pName,suitename)){
64 fprintf(stderr,"Found suite %s\n", suitename);
65 if(*n=='.'){
66 ++n;
67 fprintf(stderr,"Looking for test %s\n", n);
68 test = suite->pTest;
69 while(test!=NULL){
70 fprintf(stderr,"Found test %s\n", test->pName);
71 if(0==strcmp(test->pName,n)){
72 fprintf(stderr,"Running test %s (%p, %p)\n", n,suite,test);
73 result = CU_basic_run_test(suite,test);
74 fprintf(stderr,"Result: %s\n",CU_get_error_msg());
75 return result;
76 }
77 test = test->pNext;
78 }
79 return CUE_NO_TESTNAME;
80 }else{
81 fprintf(stderr,"Running suite %s (%p)\n",suitename,suite);
82 result = CU_basic_run_suite(suite);
83 fprintf(stderr,"Result: %s\n",CU_get_error_msg());
84 return result;
85 }
86 }
87 suite = suite->pNext;
88 }
89 return CUE_NO_SUITENAME;
90 };
91
92 /**
93 Main routine, handles command line options
94 */
95 int main(int argc, char* argv[]){
96 CU_BasicRunMode mode = CU_BRM_VERBOSE;
97 CU_ErrorAction error_action = CUEA_IGNORE;
98 CU_ErrorCode result;
99
100 struct FilePath* test_executable = ospath_new(argv[0]);
101 ASC_TEST_DIR = ospath_getdir(test_executable); /** Global Variable containing Path information about the test directory */
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 {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
126 char c;
127 while(-1 != (c = getopt_long (argc, argv, "vsne:", long_options, &option_index))){
128 switch(c){
129 case 'v': mode = CU_BRM_VERBOSE; break;
130 case 's': mode = CU_BRM_SILENT; break;
131 case 'n': mode = CU_BRM_NORMAL; break;
132 case 'e':
133 if(0==strcmp(optarg,"fail")){
134 fprintf(stderr,"on error FAIL\n");
135 error_action = CUEA_FAIL;
136 }else if(0==strcmp(optarg,"abort")){
137 fprintf(stderr,"on error ABORT\n");
138 error_action = CUEA_ABORT;
139 break;
140 }else if(0==strcmp(optarg,"ignore")){
141 error_action = CUEA_IGNORE;
142 }
143 else{
144 fprintf(stderr,"Invalid argument for --on-error option!\n");
145 exit(1);
146 }
147 break;
148 case '?':
149 case 'h':
150 fprintf(stderr,usage,argv[0]);
151 result = 1;
152 goto cleanup;
153 default:
154 fprintf(stderr,"Unknown option -- '%c'", c);
155 fprintf(stderr,usage,argv[0]);
156 result = 2;
157 goto cleanup;
158 }
159 }
160
161 CU_initialize_registry();
162 register_cunit_tests();
163 CU_basic_set_mode(mode);
164 CU_set_error_action(error_action);
165
166 /* any remaining command-line arguments will be specific test suites and/or tests to run */
167 if(optind < argc){
168 while(optind < argc){
169 result = run_suite_or_test(argv[optind]);
170 if(result==CUE_NO_SUITENAME){
171 fprintf(stderr,"Invalid suite name '%s'\n", argv[optind]);
172 result = 1;
173 goto cleanup;
174 }else if(result==CUE_NO_TESTNAME){
175 fprintf(stderr,"Invalid test name '%s'\n", argv[optind]);
176 result = 1;
177 goto cleanup;
178 }
179 optind++;
180 }
181 }else{
182 result = CU_basic_run_tests();
183 }
184
185 cleanup:
186 if(mode == CU_BRM_VERBOSE)ascshutdown("Testing completed.");/* shut down memory manager */
187 CU_cleanup_registry();
188 ospath_free(test_executable);
189 ospath_free(ASC_TEST_DIR);
190 return result;
191 }

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