static int tc_primaryport() { int rc = tc_query("box.cfg.primary_port", tc_primaryportof); if (rc == -1) tc_error("%s\n", "failed to send console query"); if (rc > 0) return rc; rc = tc_query("lua box.cfg.primary_port", tc_primaryportof); if (rc == -1) tc_error("%s\n", "failed to send console query"); return rc; }
static void tc_validate(void) { tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format); tc.opt.snap_printer = tc_print_getsnapcb(tc.opt.format); if (tc.opt.xlog_printer == NULL) tc_error("unsupported output xlog format '%s'", tc.opt.format); if (tc.opt.snap_printer == NULL) tc_error("unsupported output snap format '%s'", tc.opt.format); if (tc.opt.format && strcmp(tc.opt.format, "raw") == 0) tc.opt.raw = 1; }
static void tc_motd(void) { int rc = tc_query("motd()", tc_motdof); if (rc == -1) tc_error("%s\n", "failed to send console query"); }
TEST_F( TCErrorTest, testOff ) { int error_status = tc_error( device, 0 ); EXPECT_EQ( device->error_handler->report_level, TRICK_ERROR_SILENT ); EXPECT_EQ( error_status, 0 ); }
/* compose -- evaluate a sequential composition or piping */ PRIVATE env compose(tree t, env e, tok ldec, tok rdec, char *kind) { env e1 = tc_sexp(t->x_arg1, e); env e2 = tc_sexp(t->x_arg2, e); env ee = new_env(e); def q; /* Get vars from left arg that don't match */ for (;;) { def d = pop_def(e1); if (d == NULL) break; else if (d->d_name->s_decor != ldec) push_def(d, ee); else { sym rname = mk_symbol(d->d_name->s_basename, rdec); type rtype = del_var(rname, e2); if (rtype == NULL) push_def(d, ee); else if (! unify(d->d_type, rtype)) { tc_error(t->x_loc, "Type mismatch in %s", kind); tc_e_etc("Expression: %z", t); tc_e_etc("Type of %n in LHS: %t", d->d_name, d->d_type); tc_e_etc("Type of %n in RHS: %t", rname, rtype); tc_e_end(); } } } /* Now merge the unmatched vars from the right */ for (q = e2->e_defs; q != NULL; q = q->d_next) merge_def(VAR, q->d_name, q->d_type, ee, t, t->x_loc); return ee; }
static void tc_connect_admin(void) { if (tc_admin_connect(&tc.admin, tc.opt.host, tc.opt.port_admin) == -1) tc_error("admin console connection failed"); }
int SatGraphicsComm::connect() { int ret, num_attempts; system(syscmd); std::cout << "SatGraphicsComm: Starting graphics server using: \"" << syscmd << "\"" << std::endl; tc_error( &connection, 0); num_attempts = 0; while(1) { ret = tc_connect( &connection); if (ret == TC_SUCCESS) { std::cerr << "SatGraphicsComm: CONNECT." << std::endl; break; } else { num_attempts ++; if ( num_attempts == 30 ) { std::cerr << "SatGraphicsComm: Couldn't connect to graphics server." << std::endl; return 1; } } sleep(1); } return 0; }
/* ref_type -- find type of a reference */ PUBLIC type ref_type(sym x, tree p, env e, tree cxt) { def d = find_def(x, e); frame f; if (d == NULL) { #ifdef ASSUME type t; if (qflag && p == nil && (t = assume_type(x)) != NULL) return t; #endif if (! partial_env(e)) { tc_error(cxt->x_loc, "Identifier %n is not declared", x); if (cxt->x_kind != REF) tc_e_etc("Expression: %z", cxt); tc_e_end(); } return err_type; } f = new_frame(d->d_nparams, cxt); if (p != nil) switch (d->d_kind) { case GSET: case VAR: tc_error(cxt->x_loc, "%s %n cannot have parameters", d->d_kind == GSET ? "Basic type" : "Variable", x); tc_e_etc("Expression: %z", cxt); tc_e_end(); return err_type; case GENCONST: get_params("Generic constant", x, p, e, f, cxt->x_loc); break; default: bad_tag("ref_type", d->d_kind); } if (! aflag && d->d_abbrev) return mk_power(mk_abbrev(d, (p != nil ? f : alias(f)))); else return seal(d->d_type, f); }
static void tc_connect(void) { /* allocating stream */ tc.net = tnt_net(NULL); if (tc.net == NULL) tc_error("stream allocation error"); /* initializing network stream */ tnt_set(tc.net, TNT_OPT_HOSTNAME, tc.opt.host); tnt_set(tc.net, TNT_OPT_PORT, tc.opt.port); tnt_set(tc.net, TNT_OPT_SEND_BUF, 0); tnt_set(tc.net, TNT_OPT_RECV_BUF, 0); if (tnt_init(tc.net) == -1) tc_error("%s", tnt_strerror(tc.net)); /* connecting to server */ if (tnt_connect(tc.net) == -1) tc_error("%s", tnt_strerror(tc.net)); }
TEST_F( TCErrorTest, testNoErrorHandler ) { device->error_handler = NULL; int error_status = tc_error( device, 0 ); EXPECT_EQ( error_status, 0 ); }
static char *tc_query_error(char *fmt, ...) { char msg[256]; va_list args; va_start(args, fmt); vsnprintf(msg, sizeof(msg), fmt, args); va_end(args); char *ptr = strdup(msg); if (ptr == NULL) tc_error("memory allocation failed"); return ptr; }
void tc_import_threads_create(vob_t *vob) { int ret; tc_thread_init(&audio_imdata.th_handle, "audio import"); tc_import_thread_start(&audio_imdata); ret = tc_thread_start(&audio_imdata.th_handle, audio_import_loop, &audio_imdata); if (ret != 0) tc_error("failed to start audio stream import thread"); tc_thread_init(&video_imdata.th_handle, "video import"); tc_import_thread_start(&video_imdata); ret = tc_thread_start(&video_imdata.th_handle, video_import_loop, &video_imdata); if (ret != 0) tc_error("failed to start video stream import thread"); return; }
Trick::JSONVariableServer::JSONVariableServer() : Trick::ThreadBase("JSONVarServLis"), enabled(true), port(0), user_port_requested(false), listen_dev() { char hname[80]; gethostname(hname , (size_t) 80 ) ; source_address = std::string(hname) ; strcpy(listen_dev.client_tag, "<empty>"); tc_error(&listen_dev, 0); }
static void tc_connect(void) { tb_sesset(&tc.console, TB_HOST, tc.opt.host); tb_sesset(&tc.console, TB_PORT, tc.opt.port_console); tb_sesset(&tc.console, TB_SENDBUF, 0); tb_sesset(&tc.console, TB_READBUF, 0); int rc = tb_sesconnect(&tc.console); if (rc == -1) tc_error("console connection failed"); if (tc.opt.port == 0) tc.opt.port = tc_primaryport(); }
static int test_alloc(int size) { int ret = 0; uint8_t *mem = tc_bufalloc(size); if (mem == NULL) { tc_error("test_alloc(%i): FAILED (mem == NULL)", size); ret = 1; } else { tc_info("test_alloc(%i): PASSED", size); ret = 1; } tc_buffree(mem); return ret; }
/* check_rename -- check that all renamed components exist */ PUBLIC void check_rename(schema s, tok dec, tree rename, tree cxt) { tree r; int i; for (r = rename; r != nil; r = cdr(r)) { sym x = (sym) car(r)->x_rename_from; for (i = 0; i < s->z_ncomps; i++) if (paint(s->z_comp[i].z_name, dec) == x) goto ok; tc_error(cxt->x_loc, "Renamed component %n does not exist", x); tc_e_etc("Expression: %z", cxt); tc_e_end(); ok: ; } }
/* comp_type -- get component type in a schema */ PUBLIC type comp_type(type t, sym x, tree cxt, int loc) { type tt = t; frame f = arid; schema s; int i; unpack(&t, &f, TRUE); if (t->t_kind != SPRODUCT) panic("comp_type"); s = t->t_schema; for (i = 0; i < s->z_ncomps; i++) if (s->z_comp[i].z_name == x) return seal(s->z_comp[i].z_type, f); tc_error(loc, "Selecting non-existent component %z", x); if (cxt != nil) { tc_e_etc("Expression: %z", cxt); tc_e_etc("Arg type: %t", tt); } tc_e_end(); mark_error(); return err_type; }
int cannon_init_graphics( CANNON* C ) { int ret, num_attempts ; /* Launch graphics server */ system("cd $HOME/trick_models/cannon/graphics ; cannon &"); /* Initialize clien't connection to server */ C->connection.port = 9000 ; C->connection.hostname = (char*) malloc( 16 ) ; strcpy( C->connection.hostname, "localhost"); /* Shutup status messages */ tc_error( &C->connection, 0 ) ; /* Client connect to server : try for 5 seconds */ num_attempts = 0 ; while ( 1 ) { ret = tc_connect( &C->connection ) ; if ( ret == TC_SUCCESS ) { break ; } else { num_attempts++ ; if ( num_attempts == 500000 ) { fprintf(stderr, "Couldn't connect to " "server...\n"); exit(-1); } RELEASE_1(); /* Pause a microsecond */ } } return 0 ; }
int main( int narg, char** args ) { TCDevice listen_device ; TCDevice connection ; int verbose ; int nbytes ; int num_packets ; char *msg ; int msg_len ; int i ; #if __WIN32__ FILETIME start, stop; LARGE_INTEGER temp_start, temp_stop, total ; #else struct timeval tp ; double time1, time2; #endif double sum_time ; #if __WIN32__ memset(&total,0,sizeof(LARGE_INTEGER)); #endif /* Parse args */ verbose = 0 ; if ( narg < 3 || narg > 4 ) { fprintf(stderr, "USAGE: tc_server <num_packets> <packet_size> [-v]\n"); exit(-1); } if ( narg == 4 ) { verbose = 1 ; } num_packets = atoi(args[1]) ; msg_len = atoi(args[2]) ; if ( msg_len < 1 || num_packets < 1 ) { fprintf(stderr, "USAGE: tc_server <num_packets> <packet_size> [-v]\n"); } /* Create message */ msg = (char*) malloc ( msg_len * sizeof(char)) ; for ( i = 0 ; i < msg_len ; i++ ) { msg[i] = '#' ; } /* Zero out devices */ memset(&listen_device, '\0', sizeof(TCDevice)); memset(&connection, '\0', sizeof(TCDevice)); /* Get an error handler */ if ( verbose ) { tc_error(&connection, 1) ; tc_error(&listen_device, 1) ; } /* Accept connection */ listen_device.port = 7000 ; tc_init(&listen_device) ; tc_accept(&listen_device, &connection); sum_time = 0 ; for ( i = 0 ; i < num_packets ; i++ ) { /* Get initial time */ #if __WIN32__ GetSystemTimeAsFileTime(&start); #else gettimeofday( &tp , (struct timezone *)NULL ) ; time1 = (double)(tp.tv_sec) + ( (double)(tp.tv_usec) / 1000000.0 ) ; #endif nbytes = tc_read(&connection, msg, msg_len) ; nbytes = tc_write(&connection, msg, msg_len) ; /* Get final time */ #if __WIN32__ GetSystemTimeAsFileTime(&stop); temp_start.LowPart = start.dwLowDateTime ; temp_start.HighPart = start.dwHighDateTime ; temp_stop.LowPart = stop.dwLowDateTime ; temp_stop.HighPart = stop.dwHighDateTime ; total.QuadPart = total.QuadPart + temp_stop.QuadPart - temp_start.QuadPart ; #else gettimeofday( &tp , (struct timezone *)NULL ) ; time2 = (double)(tp.tv_sec) + ((double)(tp.tv_usec) / 1000000.0 ) ; time2 = (double)(tp.tv_sec) + ((double)(tp.tv_usec) / 1000000.0 ) ; sum_time = sum_time + ( time2 - time1 ) ; #endif } #if __WIN32__ sum_time = (double)(total.QuadPart * 0.0000001 ) ; #endif fprintf(stderr, "Avg packet round trip : %lf \n", sum_time/(double)num_packets ); return 0 ; }
PUBLIC type tc_expr(tree t, env e) #endif { switch (t->x_kind) { case REF: return ref_type((sym) t->x_tag, t->x_params, e, t); case INGEN: return ref_type((sym) t->x_tag, list2(t->x_param1, t->x_param2), e, t); case PREGEN: return ref_type((sym) t->x_tag, list1(t->x_param), e, t); case NUMBER: return nat_type; case SEXPR: { def d; frame params; if (! open_sref(t->x_ref, e, &d, ¶ms)) return err_type; if ((tok) t->x_ref->x_sref_decor != empty) { tc_error(t->x_loc, "Decoration ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (t->x_ref->x_sref_renames != nil) { tc_error(t->x_loc, "Renaming ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (! aflag && d->d_abbrev) return mk_power(mk_abbrev(d, params)); else return mk_power(seal(mk_sproduct(d->d_schema), params)); } case POWER: { type tt1, tt2; if (! anal_power(tt1 = tc_expr(t->x_arg, e), &tt2, t->x_arg)) { tc_error(t->x_loc, "Argument of \\power must be a set"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", tt1); tc_e_end(); } return mk_power(mk_power(tt2)); } case TUPLE : { type a[MAX_ARGS]; int n = 0; tree u; for (u = t->x_elements; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - tuple too big"); a[n++] = tc_expr(car(u), e); } return mk_cproduct(n, a); } case CROSS: { type a[MAX_ARGS]; type tt1, tt2; int n = 0; tree u; for (u = t->x_factors; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - product too big"); tt1 = tc_expr(car(u), e); if (! anal_power(tt1, &tt2, car(u))) { tc_error(t->x_loc, "Argument %d of \\cross must be a set", n+1); tc_e_etc("Expression: %z", t); tc_e_etc("Arg %d type: %t", n+1, tt1); tc_e_end(); } a[n++] = tt2; } return mk_power(mk_cproduct(n, a)); } case EXT: case SEQ: case BAG: { type elem_type; type tt; tree u; if (t->x_elements == nil) elem_type = new_typevar(t); else { elem_type = tc_expr(car(t->x_elements), e); for (u = cdr(t->x_elements); u != nil; u = cdr(u)) { if (unify(elem_type, tt = tc_expr(car(u), e))) elem_type = type_union(elem_type, arid, tt, arid); else { tc_error(t->x_loc, "Type mismatch in %s display", (t->x_kind == EXT ? "set" : t->x_kind == SEQ ? "sequence" : "bag")); tc_e_etc("Expression: %z", car(u)); tc_e_etc("Has type: %t", tt); tc_e_etc("Expected: %t", elem_type); tc_e_end(); } } } switch (t->x_kind) { case EXT: return mk_power(elem_type); case SEQ: return (aflag ? rel_type(num_type, elem_type) : mk_seq(elem_type)); case BAG: return (aflag ? rel_type(elem_type, num_type) : mk_bag(elem_type)); } } case THETA: return theta_type(t, e, (type) NULL, t); case BINDING: { tree u; env e1 = new_env(e); for (u = t->x_elements; u != nil; u = cdr(u)) add_def(VAR, (sym) car(u)->x_lhs, tc_expr(car(u)->x_rhs, e), e1); return mk_sproduct(mk_schema(e1)); } case SELECT: { type a = tc_expr(t->x_arg, e); if (type_kind(a) != SPRODUCT) { tc_error(t->x_loc, "Argument of selection must have schema type"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", a); tc_e_end(); mark_error(); return err_type; } switch (t->x_field->x_kind) { case IDENT: return (comp_type(a, (sym) t->x_field, t, t->x_loc)); case THETA: return (theta_type(t->x_field, e, a, t)); default: bad_tag("tc_expr.SELECT", t->x_field->x_kind); return (type) NULL; } } case APPLY: return tc_apply(APPLY, t, t->x_arg1, t->x_arg2, e); case INOP: return tc_apply(INOP, t, simply(t->x_op, t->x_loc), pair(t->x_rand1, t->x_rand2), e); case POSTOP: return tc_apply(POSTOP, t, simply(t->x_op, t->x_loc), t->x_rand, e); case LAMBDA: { env e1 = tc_schema(t->x_bvar, e); type dom = tc_expr(char_tuple(t->x_bvar), e1); type ran = tc_expr(t->x_body, e1); return (aflag ? rel_type(dom, ran) : mk_pfun(dom, ran)); } case COMP: case MU: { env e1 = tc_schema(t->x_bvar, e); type a = tc_expr(exists(t->x_body) ? the(t->x_body) : char_tuple(t->x_bvar), e1); return (t->x_kind == COMP ? mk_power(a) : a); } case LETEXPR: return tc_expr(t->x_body, tc_letdefs(t->x_defs, e)); case IF: { type a, b; tc_pred(t->x_if, e); a = tc_expr(t->x_then, e); b = tc_expr(t->x_else, e); if (unify(a, b)) return type_union(a, arid, b, arid); else { tc_error(t->x_loc, "Type mismatch in conditional expression"); tc_e_etc("Expression: %z", t); tc_e_etc("Then type: %t", a); tc_e_etc("Else type: %t", b); tc_e_end(); return err_type; } } default: bad_tag("tc_expr", t->x_kind); /* dummy */ return (type) NULL; } }
/* tc_apply -- check a function application */ PRIVATE type tc_apply(int kind, tree t, tree fun, tree arg, env e) { type actual = tc_expr(arg, e); type fun_type, formal, result; type formarg[MAX_ARGS], actarg[MAX_ARGS]; int n_formals, n_actuals, i; frame param = arid; def d; if (! aflag && fun->x_kind == REF && (d = find_def((sym) fun->x_tag, e)) != NULL && d->d_tame && fun->x_params == nil) /* A tame function */ fun_type = seal(d->d_type, param = new_frame(d->d_nparams, fun)); else fun_type = tc_expr(fun, e); if (! anal_rel_type(fun_type, &formal, &result, fun)) { if (fun_type != err_type) { if (kind == APPLY) tc_error(t->x_loc, "Application of a non-function"); else tc_error(t->x_loc, "%s operator %n is not a function", (kind == INOP ? "Infix" : "Postfix"), fun->x_tag); tc_e_etc("Expression: %z", t); tc_e_etc("Found type: %t", fun_type); tc_e_end(); } mark_error(); return err_type; } if (arg->x_kind == TUPLE && anal_cproduct(formal, formarg, &n_formals)) { /* Special case: actual parameter is a tuple, and formal parameter type is a cproduct. Check args one by one. */ if (! anal_cproduct(actual, actarg, &n_actuals)) panic("tc_apply"); if (n_actuals != n_formals) { tc_error(t->x_loc, "Function expects %d arguments", n_formals); tc_e_etc("Expression: %z", t); tc_e_end(); mark_error(); return err_type; } for (i = 0; i < n_actuals; i++) { if (param_unify(actarg[i], formarg[i], param)) continue; if (kind == INOP) tc_error(t->x_loc, "%s argument of operator %n has wrong type", (i == 0 ? "Left" : "Right"), fun->x_tag); else tc_error(t->x_loc, "Argument %d has wrong type", i+1); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", actarg[i]); tc_e_etc("Expected: %t", formarg[i]); tc_e_end(); } } else if (! param_unify(actual, formal, param)) { /* General case: check the single arg as a whole. */ tc_error(t->x_loc, "Argument of %s has wrong type", (kind == POSTOP ? "postfix operator" : "application")); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", actual); tc_e_etc("Expected: %t", formal); tc_e_end(); } return result; }
TEST_F( TCErrorTest, testNoDevice ) { int error_status = tc_error( NULL, 0 ); EXPECT_EQ( error_status, -1 ); }