Esempio n. 1
0
static void
init_model(char *file)
{
    Warning(info, "opening %s", file);
    model = GBcreateBase();
    GBsetChunkMap (model, HREgreyboxTableFactory());

    HREbarrier(HREglobal());
    GBloadFile(model, file, &model);

    HREbarrier(HREglobal());

    if (HREme(HREglobal())==0 && !PINS_USE_GUARDS && no_soundness_check) {
        Abort("Option --no-soundness-check is incompatible with --pins-guards=false");
    }

    if (HREme(HREglobal())==0 && log_active(infoLong) && !no_matrix) {
        fprintf(stderr, "Dependency Matrix:\n");
        GBprintDependencyMatrixCombined(stderr, model);
    }

    ltstype = GBgetLTStype(model);
    N = lts_type_get_state_length(ltstype);
    eLbls = lts_type_get_edge_label_count(ltstype);
    sLbls = GBgetStateLabelInfo(model) == NULL ? 0 : dm_nrows(GBgetStateLabelInfo(model));
    nGrps = dm_nrows(GBgetDMInfo(model));
    max_sat_levels = (N / sat_granularity) + 1;
    if (PINS_USE_GUARDS) {
        nGuards = GBgetStateLabelGroupInfo(model, GB_SL_GUARDS)->count;
        if (HREme(HREglobal())==0) {
            Warning(info, "state vector length is %d; there are %d groups and %d guards", N, nGrps, nGuards);
        }
    } else {
        if (HREme(HREglobal())==0) {
            Warning(info, "state vector length is %d; there are %d groups", N, nGrps);
        }
    }

    int id=GBgetMatrixID(model,"inhibit");
    if (id>=0){
        inhibit_matrix=GBgetMatrix(model,id);
        if (HREme(HREglobal())==0) {
            Warning(infoLong,"inhibit matrix is:");
            if (log_active(infoLong)) dm_print(stderr,inhibit_matrix);
        }
    }
    id = GBgetMatrixID(model,LTSMIN_EDGE_TYPE_ACTION_CLASS);
    if (id>=0){
        class_matrix=GBgetMatrix(model,id);
        if (HREme(HREglobal())==0) {
            Warning(infoLong,"inhibit class matrix is:");
            if (log_active(infoLong)) dm_print(stderr,class_matrix);
        }
    }

    HREbarrier(HREglobal());
}
Esempio n. 2
0
model_t
GBaddCheck (model_t model)
{
    HREassert (model != NULL, "No model");
    if (!PINS_CORRECTNESS_CHECK) return model;

    Print1 (info, "Matrix checking layer activated.");

    model_t             check = GBcreateBase ();

    check_ctx_t        *ctx = RTmalloc (sizeof(check_ctx_t));
    ctx->N = pins_get_state_variable_count (model);
    ctx->K = pins_get_group_count (model);
    ctx->L = pins_get_edge_label_count (model);
    ctx->S = pins_get_state_label_count (model);
    ctx->src2 = RTmalloc(sizeof(int[ctx->N]));
    ctx->check_must = ci_create (ctx->N);
    ctx->read = (ci_list **) dm_rows_to_idx_table (GBgetDMInfoRead(model));
    ctx->must = (ci_list **) dm_rows_to_idx_table (GBgetDMInfoMustWrite(model));
    ctx->may = GBgetDMInfoMayWrite(model);
    ctx->stack = isba_create (ctx->N);
    ctx->parent = model;
    ctx->magic[0] = RTmalloc(sizeof(int[ctx->N]));
    ctx->magic[1] = RTmalloc(sizeof(int[ctx->N]));
    for (int i = 0; i < ctx->N; i++) {
        int         max = type_max (ctx, i);
        int         min = type_min (ctx, i);
        int         c = max - min;
        HREassert (c > 0, "Empty type range for slot: %d -- %s", i, str_slot(ctx, NULL, i));
        ctx->magic[0][i] = min;
        ctx->magic[1][i] = min + 1;
    }
    ctx->reentrent = 0;

    GBsetContext (check, ctx);
    GBsetNextStateAll (check, check_all);
    GBsetNextStateLong (check, check_long);
    GBsetNextStateShort (check, check_short);
    //GBsetActionsLong (check, check_long);
    //GBsetActionsShort (check, check_short);

    GBinitModelDefaults (&check, model);

    return check;
}
Esempio n. 3
0
int main(int argc, char *argv[]){
	char *files[2];
	RTinitPopt(&argc,&argv,options,1,2,files,NULL,"<model> [<lts>]",
		"Perform an enumerative reachability analysis of <model>\n"
		"Run the TorX remote procedure call protocol on <model> (--torx).\n\n"
		"Options");
	if (files[1]) {
		Warning(info,"Writing output to %s",files[1]);
		write_lts=1;
	} else {
		Warning(info,"No output, just counting the number of states");
		write_lts=0;
	}
	if (application==RunTorX && write_lts) Fatal(1,error,"A TorX server does not write to a file");
	Warning(info,"loading model from %s",files[0]);
	model_t model=GBcreateBase();
	GBsetChunkMethods(model,new_string_index,NULL,
		(int2chunk_t)SIgetC,(chunk2int_t)SIputC,(get_count_t)SIgetCount);

	GBloadFile(model,files[0],&model);

	if (RTverbosity >=2) {
	  fprintf(stderr,"Dependency Matrix:\n");
	  GBprintDependencyMatrix(stderr,model);
	}
	if (matrix) {
	  GBprintDependencyMatrix(stdout,model);
	  exit(0);
	}
	lts_type_t ltstype=GBgetLTStype(model);
	N=lts_type_get_state_length(ltstype);
	edge_info_t e_info=GBgetEdgeInfo(model);
	K=e_info->groups;
	Warning(info,"length is %d, there are %d groups",N,K);
	state_labels=lts_type_get_state_label_count(ltstype);
	edge_labels=lts_type_get_edge_label_count(ltstype);
	Warning(info,"There are %d state labels and %d edge labels",state_labels,edge_labels);
	if (state_labels&&write_lts&&!write_state) {
		Fatal(1,error,"Writing state labels, but not state vectors unsupported. "
			"Writing of state vector is enabled with the option --write-state");
	}
	int src[N];
	GBgetInitialState(model,src);
	Warning(info,"got initial state");
	int level=0;
	switch(application){
	case ReachVset:
		domain=vdom_create_default(N);
		visited_set=vset_create(domain,0,NULL);
		next_set=vset_create(domain,0,NULL);
		if (write_lts){
			output=lts_output_open(files[1],model,1,0,1,"viv",NULL);
			lts_output_set_root_vec(output,(uint32_t*)src);
			lts_output_set_root_idx(output,0,0);
			output_handle=lts_output_begin(output,0,0,0);	
		}
		vset_add(visited_set,src);
		vset_add(next_set,src);
		vset_t current_set=vset_create(domain,0,NULL);
		while (!vset_is_empty(next_set)){
		  if (RTverbosity >= 1)
		    Warning(info,"level %d has %d states, explored %d states %d trans",
			    level,(visited-explored),explored,trans);
		  level++;
		  vset_copy(current_set,next_set);
		  vset_clear(next_set);
		  vset_enum(current_set,explore_state_vector,model);
		}
		long long size;
		long nodes;
		vset_count(visited_set,&nodes,&size);
	    	Warning(info,"%lld reachable states represented symbolically with %ld nodes",size,nodes);
		break;
	case ReachTreeDBS:
		dbs=TreeDBScreate(N);
		if(TreeFold(dbs,src)!=0){
			Fatal(1,error,"expected 0");
		}
		if (write_lts){
			output=lts_output_open(files[1],model,1,0,1,write_state?"vsi":"-ii",NULL);
			if (write_state) lts_output_set_root_vec(output,(uint32_t*)src);
			lts_output_set_root_idx(output,0,0);
			output_handle=lts_output_begin(output,0,0,0);	
		}
		int limit=visited;
		while(explored<visited){
		  if (limit==explored){
		    if (RTverbosity >= 1)
		      Warning(info,"level %d has %d states, explored %d states %d trans",
			      level,(visited-explored),explored,trans);
		    limit=visited;
		    level++;
		  }
		  TreeUnfold(dbs,explored,src);
		  explore_state_index(model,explored,src);
		}
		break;
	case RunTorX:
		{
		torx_struct_t context = { model, ltstype };
		torx_ui(&context);
		return 0;
		}
	}
	if (write_lts){
		lts_output_end(output,output_handle);
		Warning(info,"finishing the writing");
		lts_output_close(&output);
		Warning(info,"state space has %d levels %d states %d transitions",level,visited,trans);
	} else {
		printf("state space has %d levels %d states %d transitions\n",level,visited,trans);
	}
	return 0;
}
Esempio n. 4
0
void CAESAR_INIT_GRAPH(void) {
	char *opencaesar_args, *opencaesar_prog,*ltsmin_options;
	 int argc;
	 char **argv;

	opencaesar_prog = getenv ("OPEN_CAESAR_PROG");
	if (opencaesar_prog == NULL)
		CAESAR_ERROR ("undefined environment variable $OPEN_CAESAR_PROG");
	opencaesar_args = getenv ("OPEN_CAESAR_FILE");
	if (opencaesar_args == NULL)
		CAESAR_ERROR ("undefined environment variable $OPEN_CAESAR_FILE");
	ltsmin_options = getenv ("LTSMIN_OPTIONS");
	if (ltsmin_options == NULL)
		CAESAR_ERROR ("undefined environment variable $LTSMIN_OPTIONS");
	
	
	int len=strlen(opencaesar_prog)+strlen(ltsmin_options)+strlen(opencaesar_args);
	char cmdline[len+6];
	sprintf(cmdline,"%s %s %s",opencaesar_prog,ltsmin_options,opencaesar_args);

	int res=poptParseArgvString(cmdline,&argc,(void*)(&argv));
	if (res){
		Abort("could not parse %s: %s",opencaesar_args,poptStrerror(res));
	}

 	char *files[2];
    HREinitBegin(argv[0]);
    HREaddOptions(options,"Options");
    HREinitStart(&argc,&argv,1,1,(char**)files,"<model>");

	Warning(info,"loading model from %s",files[0]);
	model=GBcreateBase();
	GBsetChunkMethods(model,new_string_index,NULL,
	                  (int2chunk_t)SIgetC,
	                  (chunk2int_t)SIputC,
	                  (chunkatint_t)SIputCAt,
	                  (get_count_t)SIgetCount);

	GBloadFile(model,files[0],&model);

	ltstype=GBgetLTStype(model);
	N = lts_type_get_state_length(ltstype);
	K = dm_nrows(GBgetDMInfo(model));
	Warning(info,"length is %d, there are %d groups",N,K);
	state_labels=lts_type_get_state_label_count(ltstype);
	edge_labels=lts_type_get_edge_label_count(ltstype);
	Warning(info,"There are %d state labels and %d edge labels",state_labels,edge_labels);
        if (edge_encode){
            edge_size=edge_labels+N+state_labels;
            Warning(info,"encoding state information on edges");
        } else {
            edge_size=edge_labels;
            Warning(info,"state information is hidden");
        } 
	CAESAR_HINT_SIZE_STATE = N*sizeof(int);
	CAESAR_HINT_HASH_SIZE_STATE = CAESAR_HINT_SIZE_STATE;
	CAESAR_HINT_SIZE_LABEL = edge_size*sizeof(int);
	CAESAR_HINT_HASH_SIZE_LABEL = CAESAR_HINT_SIZE_LABEL;
	Warning(info,"CAESAR_HINT_SIZE_STATE=%lu CAESAR_HINT_SIZE_LABEL=%lu",
	        (unsigned long)CAESAR_HINT_SIZE_STATE,(unsigned long)CAESAR_HINT_SIZE_LABEL);
}
Esempio n. 5
0
int main(int argc, char *argv[]){
	char* files[2];
	RTinitPopt(&argc,&argv,options,2,2,files,NULL,"<input> <output>","Stream based file format conversion\n\nOptions");
	model_t model=GBcreateBase();
	GBsetChunkMethods(model,new_string_index,NULL,
		(int2chunk_t)SIgetC,(chunk2int_t)SIputC,(get_count_t)SIgetCount);
	Warning(info,"copying %s to %s",files[0],files[1]);
	lts_input_t input=lts_input_open(files[0],model,0,1);
	if (segments==0) {
		segments=lts_input_segments(input);
	}
	char*input_mode=lts_input_mode(input);
	if (input_mode) {
		Warning(debug,"input was written in %s mode",input_mode);
		if (!strcmp(input_mode,"viv") || !strcmp(input_mode,"vsi")){
			if (segments!=1) Fatal(1,error,"cannot write more than one segment");
			lts_type_t ltstype=GBgetLTStype(model);
			int N=lts_type_get_state_length(ltstype);
			Warning(info,"state length is %d",N);
			treedbs_t dbs=TreeDBScreate(N);
			// we should convert the GB not and not hack the ltstype.
			lts_type_set_state_label_count(ltstype,0);
			lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL);
			lts_output_set_root_idx(output,0,0);
			lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments);
			// We should have two passes (if the file is not in BFS order then the state numbers are wrong!)
			// pass 1: states with labels.
			// pass 2: edges with labels.
			// Currently the viv reader illegally does two passes.
			N=lts_input_segments(input);
			uint32_t begin[N];
			lts_count_t *count=lts_input_count(input);
			begin[0]=0;
			for(int i=1;i<N;i++) begin[i]=begin[i-1]+count->state[i-1];
			struct dbs_ctx ctx;
			ctx.dbs=dbs;
			ctx.begin=begin;
			lts_input_enum(input,N,N,N,lts_enum_convert(ecb,&ctx,dbs_fold,dbs_unfold,1));
			lts_output_end(output,ecb);
			lts_output_close(&output);
			uint32_t* root=lts_input_root(input);
			uint32_t root_no=TreeFold(dbs,(int*)root);
			if (root_no!=0){
				Fatal(1,error,"root is %u rather than 0",root_no);
			}
		} else {
			Warning(info,"input mode %s not supported",input_mode);
		}
	} else if (segments==lts_input_segments(input)){
		Warning(debug,"undefined input mode");
		lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL);
		lts_output_set_root_idx(output,lts_root_segment(input),lts_root_offset(input));
		lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments);
		lts_input_enum(input,segments,segments,segments,ecb);
		lts_output_end(output,ecb);
		lts_output_close(&output);
	} else {
		Warning(debug,"undefined input mode with segment conversion");
		int N=lts_input_segments(input);
		uint64_t offset[N+1];
		lts_count_t *count=lts_input_count(input);
		offset[0]=segments;
		offset[1]=0;
		for(int i=1;i<N;i++){
			offset[i+1]=offset[i]+count->state[i-1];
		}
		uint64_t root=offset[lts_root_segment(input)+1]+lts_root_offset(input);
		lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL);
		lts_output_set_root_idx(output,root%segments,root/segments);
		lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments);
		lts_input_enum(input,N,N,N,lts_enum_convert(ecb,offset,convert_div_mod,copy_seg_ofs,1));
		lts_output_end(output,ecb);
		lts_output_close(&output);
	}
	lts_input_close(&input);
	return 0;
}