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

Annotation of /trunk/base/generic/test/test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1002 - (hide annotations) (download) (as text)
Sat Dec 30 14:27:47 2006 UTC (14 years, 1 month ago) by johnpye
File MIME type: text/x-csrc
File size: 4977 byte(s)
Some work on fixing error with test_ascSignal.
Breaking down into smaller test cases.
Removed some debug output from detection of ASC_RESETNEEDED.
Changed all calls 'signal' to 'SIGNAL' macro that includes optional debug output.
Removed 'libasctest.so' (made part of libasctestsuite.so FWIW)
Fixed big in test.c wrt CUEA_ABORT.
Added 'print_stack' and 'Asc_SignalPrintStack' and 'Asc_SignalStackLength'.

1 johnpye 997 /* 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 <utilities/config.h>
27     #include <utilities/ascConfig.h>
28     #include <utilities/error.h>
29     #include <compiler/redirectFile.h>
30     #include <utilities/ascMalloc.h>
31     #include <printutil.h>
32    
33     #include <CUnit/Basic.h>
34    
35     ASC_IMPORT(int) register_cunit_tests();
36    
37     /*
38     The following allows the CUnit tests to be run using a standalone executable
39     using the CUnit 'basic' interface.
40     */
41     int run_suite_or_test(char *name){
42     char suitename[1000];
43     char *s,*n;
44     for(s=suitename,n=name; *n!='.' && *n!='\0' && s < suitename+999; *s++=*n++);
45     *s='\0';
46     struct CU_TestRegistry *reg = CU_get_registry();
47     struct CU_Suite *suite = reg->pSuite;
48     struct CU_Test *test;
49     CU_ErrorCode result;
50     while(suite!=NULL){
51     fprintf(stderr,"Looking at suite %s\n", suite->pName);
52     if(0==strcmp(suite->pName,suitename)){
53     fprintf(stderr,"Found suite %s\n", suitename);
54     if(*n=='.'){
55     ++n;
56     fprintf(stderr,"Looking for test %s\n", n);
57     test = suite->pTest;
58     while(test!=NULL){
59     fprintf(stderr,"Found test %s\n", test->pName);
60     if(0==strcmp(test->pName,n)){
61     fprintf(stderr,"Running test %s (%p, %p)\n", n,suite,test);
62     result = CU_basic_run_test(suite,test);
63     fprintf(stderr,"Result: %s\n",CU_get_error_msg());
64     return result;
65     }
66     test = test->pNext;
67     }
68     return CUE_NO_TESTNAME;
69     }else{
70     fprintf(stderr,"Running suite %s (%p)\n",suitename,suite);
71     result = CU_basic_run_suite(suite);
72     fprintf(stderr,"Result: %s\n",CU_get_error_msg());
73     return result;
74     }
75     }
76     suite = suite->pNext;
77     }
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;
88    
89     static struct option long_options[] = {
90     {"on-error", required_argument, 0, 'e'},
91     {"verbose", no_argument, 0, 'v'},
92     {"silent", no_argument, 0, 's'},
93     {"normal", no_argument, 0, 'n'},
94     {"help", no_argument, 0, '?'},
95     {"usage", no_argument, 0, '?'},
96     {0, 0, 0, 0}
97     };
98    
99     /* getopt_long stores the option index here. */
100     int option_index = 0;
101    
102     const char *usage =
103     "%s -vsne [SuiteName|SuiteName.testname] ...\n"
104     "Test ASCEND base/generic routines\n"
105     "options:\n"
106     " --verbose, -v full output, including memory checking\n"
107     " --silent, -s\n"
108     " --normal, -n\n"
109     " --on-error=[fail|abort|ignore], -e\n"
110     " --help\n";
111    
112     char c;
113     while(-1 != (c = getopt_long (argc, argv, "vsne:", long_options, &option_index))){
114     switch(c){
115     case 'v': mode = CU_BRM_VERBOSE; break;
116     case 's': mode = CU_BRM_SILENT; break;
117     case 'n': mode = CU_BRM_NORMAL; break;
118     case 'e':
119 johnpye 1002 if(0==strcmp(optarg,"fail")){
120     fprintf(stderr,"on error FAIL\n");
121     error_action = CUEA_FAIL;
122     }else if(0==strcmp(optarg,"abort")){
123     fprintf(stderr,"on error ABORT\n");
124     error_action = CUEA_ABORT;
125     break;
126     }else if(0==strcmp(optarg,"ignore")){
127     error_action = CUEA_IGNORE;
128     }
129     else{
130     fprintf(stderr,"Invalid argument for --on-error option!\n");
131     exit(1);
132     }
133 johnpye 997 break;
134     case '?':
135     case 'h':
136     fprintf(stderr,usage,argv[0]);
137     exit(1);
138     default:
139     fprintf(stderr,"Unknown option -- '%c'", c);
140     fprintf(stderr,usage,argv[0]);
141     exit(2);
142     }
143     }
144    
145     CU_initialize_registry();
146     register_cunit_tests();
147     CU_basic_set_mode(mode);
148     CU_set_error_action(error_action);
149    
150     /* any remaining command-line arguments will be specific test suites and/or tests to run */
151     if(optind < argc){
152     while(optind < argc){
153     result = run_suite_or_test(argv[optind]);
154     if(result==CUE_NO_SUITENAME){
155     fprintf(stderr,"Invalid suite name '%s'\n", argv[optind]);
156     exit(1);
157     }else if(result==CUE_NO_TESTNAME){
158     fprintf(stderr,"Invalid test name '%s'\n", argv[optind]);
159     exit(1);
160     }
161     optind++;
162     }
163     }else{
164     result = CU_basic_run_tests();
165     }
166    
167     CU_cleanup_registry();
168    
169     if(mode == CU_BRM_VERBOSE)ascshutdown("Testing completed.");/* shut down memory manager */
170    
171     return result;
172     }

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