int main (int argc, char* argv[]) { // informs test-listener about testresults CPPUNIT_NS :: TestResult testresult; // register listener for collecting the test-results CPPUNIT_NS :: TestResultCollector collectedresults; testresult.addListener (&collectedresults); CPPUNIT_NS :: BriefTestProgressListener listener; if (argc > 1 || getenv("V")) { // Shows a message as each test starts testresult.addListener( &listener ); } // insert test-suite at test-runner by registry CPPUNIT_NS :: TestRunner testrunner; testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ()); testrunner.run (testresult); // output results in compiler-format CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr); compileroutputter.write (); // return 0 if tests were successful int ret = collectedresults.wasSuccessful() ? 0 : 1; #ifdef USE_SCRIPT_TCL /* Avoid valgrind memory leaks. */ Tcl_Finalize(); #endif return ret; }
/* * Make the executable exit due to some error with the error code expected by * S-N. */ void sn_exit() { if (encoding) { Tcl_FreeEncoding(encoding); Tcl_Finalize(); } exit(1); }
void shell_run(tree_t e, struct tree_rd_ctx *ctx) { const int ndecls = tree_decls(e); hash_t *decl_hash = hash_new(ndecls * 2, true); for (int i = 0; i < ndecls; i++) { tree_t d = tree_decl(e, i); hash_put(decl_hash, tree_ident(d), d); } Tcl_Interp *interp = Tcl_CreateInterp(); shell_cmd_t shell_cmds[] = { CMD(quit, NULL, "Exit simulation"), CMD(run, NULL, "Start or resume simulation"), CMD(restart, e, "Restart simulation"), CMD(show, decl_hash, "Display simulation objects"), CMD(help, shell_cmds, "Display this message"), CMD(copyright, NULL, "Display copyright information"), CMD(signals, e, "Find signal objects in the design"), CMD(now, NULL, "Display current simulation time"), CMD(watch, decl_hash, "Trace changes to a signal"), CMD(unwatch, decl_hash, "Stop tracing signals"), { NULL, NULL, NULL, NULL} }; qsort(shell_cmds, ARRAY_LEN(shell_cmds) - 1, sizeof(shell_cmd_t), compare_shell_cmd); for (shell_cmd_t *c = shell_cmds; c->name != NULL; c++) Tcl_CreateObjCommand(interp, c->name, c->fn, c->cd, NULL); show_banner(); char *line; while ((line = shell_get_line())) { switch (Tcl_Eval(interp, line)) { case TCL_OK: break; case TCL_ERROR: errorf("%s", Tcl_GetStringResult(interp)); break; } free(line); } printf("\nBye.\n"); Tcl_Finalize(); }
void Destroy(void) { CallBinds(Type_Unload, NULL, NULL, 0, NULL); Tcl_FreeEncoding(g_Encoding); Tcl_DeleteInterp(g_Interp); Tcl_Release(g_Interp); g_Interp = NULL; Tcl_Finalize(); int i = 0; while (hash_t<CTclSocket*>* p = g_TclListeners->Iterate(i)) { static_cast<CSocketEvents*>(p->Value)->Destroy(); } delete g_TclListeners; i = 0; while (hash_t<CTclClientSocket*>* p = g_TclClientSockets->Iterate(i++)) { p->Value->Destroy(); } delete g_TclClientSockets; for (int a = 0; a < g_TimerCount; a++) { if (g_Timers[a]) { g_Timers[a]->timer->Destroy(); free(g_Timers[a]->proc); free(g_Timers[a]->param); } } delete this; }
value camltk_finalize(value unit) /* ML */ { Tcl_Finalize(); return Val_unit; }
/// Call this after deleting last VMDApp instance, to ensure that all event /// handlers (like Tk) shut down cleanly. static void vmd_finalize_tcl() { #ifdef VMDTCL Tcl_Finalize(); #endif }
int main(int argc, const char** argv) { argv0 = argv[0]; bool print_stats = false; U.start(); // Set up smsh related error codes if (! (w_error_t::insert( "ss_m shell", smsh_error_list, SSH_MAX_ERROR - SSH_MIN_ERROR - 1))) { abort(); } /* * The following section of code sets up all the various options * for the program. The following steps are performed: - determine the name of the program - setup an option group for the program - initialize the ssm options - scan default option configuration files ($HOME/.shoreconfig .shoreconfig) - process any options found on the command line - use getopt() to process smsh specific flags on the command line - check that all required options are set before initializing sm */ // set prog_name to the file name of the program const char* prog_name = strrchr(argv[0], '/'); if (prog_name == NULL) { prog_name = argv[0]; } else { prog_name += 1; /* skip the '/' */ if (prog_name[0] == '\0') { prog_name = argv[0]; } } /* * Set up and option group (list of options) for use by * all layers of the system. Level "smsh" indicates * that the program is a a part to the smsh test suite. * Level "server" indicates * the type of program (the smsh server program). The third * level is the program name itself. */ option_group_t options(3); W_COERCE(options.add_class_level("smsh")); W_COERCE(options.add_class_level("server")); W_COERCE(options.add_class_level(prog_name)); /* * Set up and smsh option for the name of the tcl library directory * and the name of the .smshrc file. */ option_t* smsh_libdir; option_t* smsh_smshrc; W_COERCE(options.add_option("smsh_libdir", "directory name", NULL, "directory for smsh tcl libraries", true, option_t::set_value_charstr, smsh_libdir)); W_COERCE(options.add_option("smsh_smshrc", "rc file name", ".smshrc", "full path name of the .smshrc file", false, option_t::set_value_charstr, smsh_smshrc)); // have the sm add its options to the group W_COERCE(ss_m::setup_options(&options)); /* * Scan the default configuration files: $HOME/.shoreconfig, .shoreconfig. Note * That OS errors are ignored since it is not an error * for this file to not be found. */ rc_t rc; { char opt_file[ss_m::max_devname+1]; for(int file_num = 0; file_num < 2 && !rc.is_error(); file_num++) { // scan default option files w_ostrstream err_stream; const char* config = ".shoreconfig"; if (file_num == 0) { if (!getenv("HOME")) { // ignore it ... // cerr << "Error: environment variable $HOME is not set" << endl; // rc = RC(SSH_FAILURE); break; } if (sizeof(opt_file) <= strlen(getenv("HOME")) + strlen("/") + strlen(config) + 1) { cerr << "Error: environment variable $HOME is too long" << endl; rc = RC(SSH_FAILURE); break; } strcpy(opt_file, getenv("HOME")); strcat(opt_file, "/"); strcat(opt_file, config); } else { w_assert3(file_num == 1); strcpy(opt_file, "./"); strcat(opt_file, config); } { option_file_scan_t opt_scan(opt_file, &options); rc = opt_scan.scan(true, err_stream); err_stream << ends; if (rc.is_error()) { // ignore OS error messages if (rc.err_num() == fcOS) { rc = RCOK; } else { // this error message is kind of gross but is // sufficient for now cerr << "Error in reading option file: " << opt_file << endl; //cerr << "\t" << w_error_t::error_string(rc.err_num()) << endl; cerr << "\t" << err_stream.c_str() << endl; } } } } } /* * Assuming there has been no error so far, the command line * is processed for any options in the option group "options". */ if (!rc.is_error()) { // parse command line w_ostrstream err_stream; rc = options.parse_command_line(argv, argc, 2, &err_stream); err_stream << ends; if (rc.is_error()) { cerr << "Error on command line " << endl; cerr << "\t" << w_error_t::error_string(rc.err_num()) << endl; cerr << "\t" << err_stream.c_str() << endl; print_usage(cerr, prog_name, false, options); } } /* * Assuming there has been no error so far, the command line * is processed for any smsh specific flags. */ int option; //if (!rc) { // do even if error so that smsh -h can be recognized bool verbose_opt = false; // print verbose option values while ((option = getopt(argc, (char * const*) argv, "Cf:hLOsTvV")) != -1) { switch (option) { case 'T': extern bool logtrace; logtrace = true; break; case 'O': // Force use of old sort cout << "Force use of old sort implementation." <<endl; newsort = false; break; case 'C': // force compression of btrees force_compress = true; break; case 's': print_stats = true; break; case 'f': f_arg = optarg; break; case 'L': // use log warning callback log_warn_callback = true; break; case 'h': // print a help message describing options and flags print_usage(cerr, prog_name, true, options); // free rc structure to avoid complaints on exit W_IGNORE(rc); goto done; break; case 'v': verbose_opt = true; break; case 'V': verbose = true; break; default: cerr << "unknown flag: " << option << endl; rc = RC(SSH_COMMAND_LINE); } } if (verbose_opt) { options.print_values(false, cerr); } } /* * Assuming no error so far, check that all required options * in option_group_t options are set. */ if (!rc.is_error()) { // check required options w_ostrstream err_stream; rc = options.check_required(&err_stream); err_stream << ends; if (rc.is_error()) { cerr << "These required options are not set:" << endl; cerr << err_stream.c_str() << endl; print_usage(cerr, prog_name, false, options); } } /* * If there have been any problems so far, then exit */ if (rc.is_error()) { // free the rc error structure to avoid complaints on exit W_IGNORE(rc); goto errordone; } /* * At this point, all options and flags have been properly * set. What follows is initialization for the rest of * the program. The ssm will be started by a tcl_thread. */ // setup table of sm commands - doesn't involve the Tcl_Interp dispatch_init(); // set up the linked variables // either these should be read-only or // they need to be made thread-safe. We can assume for smsh they // are for all purposes read-only, since only the mama thread sets // them in the scripts. linked.sm_page_sz = ss_m::page_sz; linked.sm_max_exts = ss_m::max_exts; linked.sm_max_vols = ss_m::max_vols; linked.sm_max_servers = ss_m::max_servers; linked.sm_max_keycomp = ss_m::max_keycomp; linked.sm_max_dir_cache = ss_m::max_dir_cache; linked.sm_max_rec_len = ss_m::max_rec_len; linked.sm_srvid_map_sz = ss_m::srvid_map_sz; linked.verbose_flag = verbose?1:0; linked.verbose2_flag = verbose2?1:0; linked.instrument_flag = instrument?1:0; linked.compress_flag = force_compress?1:0; linked.log_warn_callback_flag = log_warn_callback?1:0; { int tty = isatty(0); interactive = tty && f_arg; } // Create the main tcl_thread { tcl_thread_t* tcl_thread = NULL; bool ok = true; if(ok) { if (f_arg) { TCL_AV char* av[2]; av[0] = TCL_AV1 "source"; av[1] = f_arg; // smsh -f <file> tcl_thread = new tcl_thread_t(2, av, smsh_libdir->value(), smsh_smshrc->value() ); } else { // interactive /* cerr << __func__ << " " << __LINE__ << " " << __FILE__ << " INTERACTIVE libdir " << smsh_libdir->value() << " msshrc " << smsh_smshrc->value() << endl; */ tcl_thread = new tcl_thread_t(0, 0, smsh_libdir->value(), smsh_smshrc->value() ); } assert(tcl_thread); W_COERCE( tcl_thread->fork() ); W_COERCE( tcl_thread->join() ); delete tcl_thread; } } // Shutdown TCL and have it deallocate resources still held! Tcl_Finalize(); U.stop(1); // 1 iteration if(print_stats) { cout << "Thread stats" <<endl; sthread_t::dump_stats(cout); cout << endl; cout << "Unix stats for parent:" <<endl; cout << U << endl << endl; } cout << flush; done: clean_up_shell(); fprintf(stderr, "%d tcl threads ran\n", num_tcl_threads_ttl); return 0; errordone: clean_up_shell(); return 1; }