Пример #1
0
static int create_shm(void)
{
	shm = alloc_shared(sizeof(struct shm_s));
	if (shm == NULL) {
		perror("mmap");
		return -1;
	}

	memset(shm, 0, sizeof(struct shm_s));

	shm->total_syscalls_done = 1;
	shm->regenerate = 0;

	if (user_specified_children != 0)
		shm->max_children = user_specified_children;
	else
		shm->max_children = sysconf(_SC_NPROCESSORS_ONLN);

	if (shm->max_children > MAX_NR_CHILDREN) {
		printf("Increase MAX_NR_CHILDREN!\n");
		exit(EXIT_FAILURE);
	}
	memset(shm->pids, EMPTY_PIDSLOT, sizeof(shm->pids));

	shm->parentpid = getpid();

	shm->seed = init_seed(seed);

	return 0;
}
Пример #2
0
void init_shm(void)
{
	unsigned int i;

	output(2, "shm is at %p\n", shm);

	shm->total_syscalls_done = 1;

	if (user_set_seed == TRUE)
		shm->seed = init_seed(seed);
	else
		shm->seed = new_seed();
	/* Set seed in parent thread */
	set_seed(0);

	for (i = 0; i < max_children; i++) {

		shm->pids[i] = EMPTY_PIDSLOT;

		shm->previous[i].nr = shm->syscall[i].nr = -1;

		shm->previous[i].a1 = shm->syscall[i].a1 = -1;
		shm->previous[i].a2 = shm->syscall[i].a2 = -1;
		shm->previous[i].a3 = shm->syscall[i].a3 = -1;
		shm->previous[i].a4 = shm->syscall[i].a4 = -1;
		shm->previous[i].a5 = shm->syscall[i].a5 = -1;
		shm->previous[i].a6 = shm->syscall[i].a6 = -1;
	}
}
/*---------------------------------------------------------------------------*/
RandomGenerator::RandomGenerator() :
    uni_dist(0.0,1.0),
    uni_gen(generator ,uni_dist) {
    if (!seed_flag_) {
        generator.seed(static_cast<unsigned int>(init_seed()));
        seed_flag_ = true;
    }
}
/*
 * Load complete dataset into memory
 */
void DataSet::load_complete_dataset(const string& x_filename,
        const string& y_filename) {
    /* Try to open files */
    ifstream xfp(x_filename.c_str(), ios::binary);
    if (!xfp) {
        cout << "Could not open input file " << x_filename << endl;
        exit(EXIT_FAILURE);
    }
    ifstream yfp(y_filename.c_str(), ios::binary);
    if (!yfp) {
        cout << "Could not open input file " << y_filename << endl;
        exit(EXIT_FAILURE);
    }
    cout << endl;
    cout << "Loading data file: " << x_filename << " ... " << endl;
    cout << "Loading data file: " << y_filename << " ... " << endl;

    /* Reading the header (first line of file)*/
    int tmp;
    long int tmp_samples;
    xfp >> tmp_samples;
    num_samples_ = tmp_samples;
    xfp >> feature_dim_;
    yfp >> tmp;
    if (tmp != tmp_samples) {
        cout << "Number of samples in data and labels file is different" << endl;
        exit(EXIT_FAILURE);
    }
    yfp >> tmp;
    /* Delete list with data points */
    if (!add_points_)
        samples_.clear();
    set<int> labels;
    /* Going through complete files */
    for (int n_samp = 0; n_samp < num_samples_; n_samp++) {
        Sample sample;
        sample.x = arma::fvec(feature_dim_);
        yfp >> sample.y;
        labels.insert(sample.y);
        for (int n_feat = 0; n_feat < feature_dim_; n_feat++) {
            xfp >> sample.x(n_feat);
        }
        samples_.push_back(sample);
    }
    xfp.close();
    yfp.close();
    num_classes_ = labels.size();

    if (random_) {
        srand(init_seed());
        random_shuffle(samples_.begin(), samples_.end());
    }
}
Пример #5
0
void init_shm(void)
{
	unsigned int i;
	unsigned int childptrslen;

	output(2, "shm is at %p\n", shm);

	if (set_debug == TRUE)
		shm->debug = TRUE;

	shm->stats.total_syscalls_done = 1;

	if (user_set_seed == TRUE)
		shm->seed = init_seed(seed);
	else
		shm->seed = new_seed();
	/* Set seed in parent thread */
	set_seed(NULL);

	childptrslen = max_children * sizeof(struct childdata *);
	/* round up to page size */
	childptrslen += page_size - 1;
	childptrslen &= PAGE_MASK;

	shm->children = memalign(page_size, childptrslen);
	if (shm->children == NULL) {
		printf("Failed to allocate child structures.\n");
		exit(EXIT_FAILURE);
	}

	memset(shm->children, 0, childptrslen);

	/* We allocate the childdata structs as shared mappings, because
	 * the watchdog process needs to peek into each childs syscall records
	 * to make sure they are making progress.
	 */
	for_each_child(i) {
		struct childdata *child;

		child = alloc_shared(sizeof(struct childdata));
		shm->children[i] = child;

		memset(&child->syscall, 0, sizeof(struct syscallrecord));

		child->pid = EMPTY_PIDSLOT;

		child->num = i;

		init_child_logging(child);
	}
	mprotect(shm->children, childptrslen, PROT_READ);
}
Пример #6
0
static void setup_shm_postargs(void)
{
	if (user_set_seed == TRUE) {
		shm->seed = init_seed(seed);
		/* Set seed in parent thread */
		set_seed(0);
	}

	if (user_specified_children != 0)
		shm->max_children = user_specified_children;
	else
		shm->max_children = sysconf(_SC_NPROCESSORS_ONLN);

	if (shm->max_children > MAX_NR_CHILDREN) {
		outputerr("Increase MAX_NR_CHILDREN!\n");
		exit(EXIT_FAILURE);
	}
}
Пример #7
0
bldbuf(unsigned short *wbuf, unsigned int dlen, int buf_size,
       char *pattern_id, int *blkno)
{
   int            i, j = 1, k, dlen_static, a, b, c;
   long           nrand48();
   unsigned short xsubi[3];

   dlen_static = dlen;
   init_seed(xsubi);
   a = xsubi[0];
   b = xsubi[1];
   c = xsubi[2];
   dlen = dlen / 512;
   i = 0;
   if ( (strcmp(pattern_id, "#001") == 0) ||
        (strcmp(pattern_id, "#002") == 0) ) {
      for ( ; dlen != 0; --dlen, j++ ) {
         wbuf[i]   = blkno[0] >> 16;
         wbuf[i+1] = blkno[0];
         wbuf[i+2] = a;
         wbuf[i+3] = b;
         wbuf[i+4] = c;
         wbuf[i+5] = nrand48(xsubi) % 65536;
         for ( k = 6; k <= 256; ) {
            wbuf[i+k] = (i + k) / 2;
            if ( strcmp(pattern_id, "#001") == 0 )
               wbuf[i+k+1] = j * 0x101;
            else
               wbuf[i+k+1] = nrand48(xsubi) % 65536;
            k += 2;
         }
         i += 256;
      }
      while ( (buf_size - dlen_static) >=0 ) {
          wbuf[i] = 0xffff;
          i++;
          buf_size -= 2;
      }
   }
}
/*
 * Load complete dataset into memory
 */
void DataSet::load_dataset_iteratively(const string& x_filename,
        const string& y_filename) {
    /* Try to open files and read header */
    x_file_.open(x_filename.c_str(), ios::binary);
    if (!x_file_) {
        cout << "Could not open input file " << x_filename << endl;
        exit(EXIT_FAILURE);
    }
    y_file_.open(y_filename.c_str(), ios::binary);
    if (!y_file_) {
        cout << "Could not open input file " << y_filename << endl;
        exit(EXIT_FAILURE);
    }
    cout << endl;
    cout << "Loading data file: " << x_filename << " ... " << endl;
    cout << "Loading data file: " << y_filename << " ... " << endl;

    /* Reading the header (first line of file)*/
    int tmp;
    x_file_ >> num_samples_;
    x_file_ >> feature_dim_;
    y_file_ >> tmp;
    if (tmp != num_samples_) {
        cout << "Number of samples in data and labels file is different" << endl;
        exit(EXIT_FAILURE);
    }
    y_file_ >> tmp;
    /* Initialize random vector */
    if (random_) {
        for (long int i = 0; i < num_samples_; i++) {
            rand_vec_.push_back(i);
        }
        srand(init_seed());
        random_shuffle(rand_vec_.begin(), rand_vec_.end());
    }
}
std::string context_free_grammar_generator::generate() const {
    uint32_t seed[seed_size];
    init_seed(seed);
    return print_nonterminal("main", seed, 0);
}
Пример #10
0
int
get_rule(struct htx_data *phtx_info, struct ruleinfo *prule_info,
         char *rules_name)
{
  int          keywd_count, rc=0, i, d, k, found;
  int          first_line;
  char         *p, digit[3] = "   ", keywd[80], pipe_swtch[3], t[200];
  char         error, s[200], msg[221], tmp_msg[100];
  static int   line = 0;

    set_defaults(prule_info);
    keywd_count = 0;
    cnt = 0;
    error = 'n';
    first_line = line + 1;
    while ( (get_line(s, 200)) > 1 ) {     /* read in & process the next line */
      line = line + 1;
      if ( s[0] == '*' )
         continue;
      for ( i = 0; s[i] != '\n'; i++ ) {
         t[i] = s[i];
         s[i] = toupper(s[i]);
         if (s[i] == '=')
            s[i] = ' ';
      }
      keywd_count++;
      sscanf(s, "%s", keywd);
      if ( (strcmp(keywd, "RULE_ID")) == 0 ) {            /* Valid RULE_ID ? */
         sscanf(s, "%*s %s", prule_info->rule_id);
         if ( (strlen(prule_info->rule_id)) > 8 ) {
            sprintf(msg, "line# %d %s = %s (must be 8 characters or less) \n",
                    line, keywd, prule_info->rule_id);
            hxfmsg(phtx_info, 0, SYSERR, msg);
            error = 'y';
         } else {
            d = strlen(prule_info->rule_id);
            i = 0;
            found = 0;
            for ( k = 0; k < d; k++ ) {
               if ( isdigit(prule_info->rule_id[k]) ) {
                  digit[i] = prule_info->rule_id[k];
                  i++;
                  found = 1;
               }
            }
            if ( found ) {
               rule_stanza[cnt] = atoi(digit);
               for ( i = 0; i < cnt; i++ ) {
                  if ( rule_stanza[cnt] == rule_stanza[i] ) {
                     sprintf(msg, "line# %d %s = %s (Duplicate Stanza "
                                  "number found in RULE_ID) \n",
                              line, keywd, prule_info->rule_id);
                     hxfmsg(phtx_info, 0, SYSERR, msg);
                     error = 'y';
                  }
               }
            } else {
               sprintf(msg, "line# %d %s = %s (NO Stanza number found "
                            "in RULE_ID) \n",
                       line, keywd, prule_info->rule_id);
               hxfmsg(phtx_info, 0, SYSERR, msg);
               error = 'y';
            }
         }
      } else if ( (strcmp(keywd, "PATTERN_ID")) == 0 ) {/* Valid PATTERN_ID ? */
         sscanf(s, "%*s %s", prule_info->pattern_id);
         if ( (strlen(prule_info->pattern_id)) > 8 ) {
            sprintf(msg, "line# %d %s = %s (must be 8 characters or less) \n",
                    line, keywd, prule_info->pattern_id);
            hxfmsg(phtx_info, 0, SYSERR, msg);
            error = 'y';
         }
      } else if ( (strcmp(keywd, "NUM_OPER")) == 0 ) {   /* Valid NUM_OPER ? */
         sscanf(s, "%*s %d", &prule_info->num_oper);
         if ( prule_info->num_oper < 0 ) {
            sprintf(msg, "line# %d %s = %d (must be >= 0) \n",
                    line, keywd, prule_info->num_oper);
            hxfmsg(phtx_info, 0, SYSERR, msg);
            error = 'y';
         }
      } else if ( (strcmp(keywd, "OPER")) == 0 ) {           /* Valid OPER ? */
         sscanf(s, "%*s %s", prule_info->oper);
         if ( strcmp(prule_info->oper, "W") == 0     ||
              strcmp(prule_info->oper, "R") == 0     ||
              strcmp(prule_info->oper, "RC") == 0    ||
              strcmp(prule_info->oper, "D") == 0     ||
              strcmp(prule_info->oper, "RW") == 0    ||
              strcmp(prule_info->oper, "WEOF") == 0  ||
              strcmp(prule_info->oper, "S") == 0     ||
              strcmp(prule_info->oper, "E") == 0     ||
              strcmp(prule_info->oper, "SF") == 0    ||
              strcmp(prule_info->oper, "SR") == 0    ||
              strcmp(prule_info->oper, "CO") == 0    ||
              strcmp(prule_info->oper, "WEOT") == 0  ||
              strcmp(prule_info->oper, "C") == 0     ||
              strcmp(prule_info->oper, "O") == 0     ||
              strcmp(prule_info->oper, "RCEOT") == 0 ||
              strcmp(prule_info->oper, "REOT") == 0  ||          /* dgs */
              strcmp(prule_info->oper, "RS") == 0    ||
#ifndef __HTX_LINUX__
              strcmp(prule_info->oper, "DBUG") == 0  ||
              strcmp(prule_info->oper, "IE") == 0    ||
              strcmp(prule_info->oper, "RES") == 0   ||
              strcmp(prule_info->oper, "ML") == 0    ||
              strcmp(prule_info->oper, "MUL") == 0   ||
              strcmp(prule_info->oper, "ASF") == 0   ||
              strcmp(prule_info->oper, "ASR") == 0   ||
              strcmp(prule_info->oper, "LB") == 0    ||
              strcmp(prule_info->oper, "RP") == 0    ||
              strcmp(prule_info->oper, "ADUL") == 0  ||
              strcmp(prule_info->oper, "TWIE") == 0  ||
              strcmp(prule_info->oper, "TWPE") == 0  ||
              strcmp(prule_info->oper, "TWRE") == 0  ||
              strcmp(prule_info->oper, "TWUL") == 0  ||
              strcmp(prule_info->oper, "WUL") == 0   ||
              strcmp(prule_info->oper, "TWMM") == 0  ||
              strcmp(prule_info->oper, "CDRE") == 0  ||
              strcmp(prule_info->oper, "CDMM") == 0  ||
              strcmp(prule_info->oper, "HUNL") == 0  ||
              strcmp(prule_info->oper, "HINI") == 0  ||
              strcmp(prule_info->oper, "HREL") == 0  ||
              strcmp(prule_info->oper, "HWUN") == 0  ||
	          strcmp(prule_info->oper, "SPEC") == 0  ||
#endif
              strcmp(prule_info->oper, "VBSWR") == 0 ||
              strcmp(prule_info->oper, "VBSRD") == 0 ||
              strcmp(prule_info->oper, "VBSRDC") == 0||
                   strcmp(prule_info->oper, "XCMD") == 0 ) ;
         else {
           sprintf(msg, "ERROR in rules file %s:\n", rules_name);
           hxfmsg(phtx_info, 0, INFO, msg);
           sprintf(msg, " Line# %d %s = %s is an INVALID operation.\n",
                   line, keywd, prule_info->oper);
           hxfmsg(phtx_info, 0, INFO, msg);
#ifndef __HTX_LINUX__
           sprintf(msg, " Valid Operations are W,R,RC,D,RW,WEOF,S,E,SF,SR,CO"
                        "WEOT,C,O,RCEOT,\nRS,DBUG,IE,RES,ML,MUL,ASF,ASR,LB"
                        "RP,ADUL,TWIE,TWPE,TWRE,TWUL,\nWUL,TWMM,VBSWR,VBSRD, VBSRDC"
                        "SPEC, XCMD.\n");
#else
		   sprintf(msg, " Valid Operations are W,R,RC,D,RW,WEOF,S,E,SF,SR,CO"
						"WEOT,C,O,RCEOT,\nRS,VBSWR,VBSRD, VBSRDC, XCMD.\n");
#endif
           hxfmsg(phtx_info, 0, SYSERR, msg);
           error = 'y';
         }
      } else if ( (strcmp(keywd, "NUM_BLKS")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->num_blks);
         if ( strcmp(prule_info->oper,"SF") == 0 ||
              strcmp(prule_info->oper,"SR") == 0 )
            prule_info->pattern_id[0] = 0;
      } else if ( (strcmp(keywd, "#CLOSE_PIPE")) == 0 ) {
         sscanf(s, "%*s %s", pipe_swtch);
         if ( strcmp(pipe_swtch, "NO") == 0 )
            signal_flag = 'R';
         else {
            sprintf(msg, "rm %s", pipe_name);
            system(msg);
            sprintf(msg, "line# %d %s = %s (must be NO) \n",
                    line, keywd, pipe_swtch);
            hxfmsg(phtx_info, 0, SYSERR, msg);
            error = 'y';
         }
      } else if ((strcmp(keywd, "#CRASH_ON_MIS")) == 0) {
         char dummy[30];
		 if(crash_on_mis == 0) {
	         sscanf(s, "%*s %s", dummy);
    	     if      ( strcmp(dummy, "YES") == 0 ) crash_on_mis = 1;
        	 else if ( strcmp(dummy, "NO")  == 0 ) crash_on_mis = 0;
	         else {
    	        sprintf(msg, "rm %s", pipe_name);
        	    system(msg);
            	sprintf(msg,"line# %d %s = %s (must be YES or NO) \n",
                	    line, keywd, dummy);
	            hxfmsg(phtx_info, 0, SYSERR, msg);
    	        error = 'y';
        	 }
		 }
      } else if ( (strcmp(keywd, "#RULES_NAME")) == 0 ) {
         sscanf(s, "%*s %s", rules_name);
         sprintf(msg, "Using New Rules File > %s", rules_name);
         hxfmsg(phtx_info, 0, INFO, msg);
      } else if ( (strcmp(keywd, "UNLOAD_SLEEP")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->u_sleep);
      } else if ( (strcmp(keywd, "SOURCE_ID")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->source_id);
      } else if ( (strcmp(keywd, "DEST_ID")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->dest_id);
      } else if ( (strcmp(keywd, "CHS_FILE")) == 0 ) {
          for ( d = 0; s[d] != '\n'; d++ )
             s[d] = tolower(s[d]);
          sscanf(s, "%*s %s", prule_info->chs_file);
      } else if ( (strcmp(keywd, "SOURCE_ID1")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->source_id1);
      } else if ( (strcmp(keywd, "DEST_ID1")) == 0 ) {
         sscanf(s, "%*s %d", &prule_info->dest_id1);
      } else if ( strcmp(keywd, "CRASH_ON_MIS") == 0 ) {
         sscanf(s, "%*s %s", msg);
         crash_on_mis = (*msg == 'Y') ? 1 : 0;
      } else if ( strcmp(keywd, "VBS_SEED") == 0 ) {
         sscanf(s, "%*s %n", &i);
         while ( isspace(s[i]) ) i++;
         strcpy(msg, &s[i]);
         if ( strncmp(prule_info->oper, "VBS", 3) != 0 ) {
            sprintf(msg, "line# %d %s = %s (Only valid in VBSRD or VBSWR)",
                    line, keywd, msg);
            hxfmsg(phtx_info, 0, SYSERR, msg);
            error = 'y';
         } else if ( strncmp(msg, "RANDOM", 6) == 0 ) {
            init_seed(prule_info->seed);
            prule_info->VBS_seed_type = 'R';
            VBS_seed_initialized = 1;
         } else if ( strncmp(msg, "FIXED", 5) == 0 ) {
            VBS_seed_initialized = 1;
            prule_info->VBS_seed_type = 'F';
         } else {
            p = msg;
            i = 0;
            while ( *p && i < 4 )                   /* scan for first digit */
               if ( isdigit(*p) ) {
                  if ( i < 3 )
                     prule_info->seed[i++] = atoi(p);  /* convert the arg   */
                  else {
                     VBS_last_write = atoi(p);         /* convert the arg   */
                     i++;
                  }
                  while ( isdigit(*(++p)) ) ;          /* scan past the arg */
               } else
                  p++;
            if ( i != 4 ) {
               sprintf(tmp_msg,
                       "line# %d %s = %s (must be RANDOM or 4 integers)"
                       "/nThe last integer being the # of bytes in the last"
                       "Variable Write command",
                       line, keywd, msg);
               hxfmsg(phtx_info, 0, SYSERR, tmp_msg);
               error = 'y';
            } else {
               VBS_seed_initialized = 1;
               prule_info->VBS_seed_type = 'U';
            }
         }
      } else if ( (strcmp(keywd, "COMMAND")) == 0 ) {
         d = 0;
         for ( i = 10; s[i] != '\n' && s[i] != '\0'; i++, d++ ) {
             prule_info->cmd_list[d] = t[i];
         }
         prule_info->cmd_list[d] = '\0';
      } else {
         sprintf(msg, "line# %d keywd = %s (invalid) \n",
                 line, keywd);
         hxfmsg(phtx_info, 0, SYSERR, msg);
         error = 'y';
      }
    }

    line = line + 1;
    if ( keywd_count > 0 ) {
       if ( (htx_strcmp(prule_info->rule_id, "        ") == 0) &&
            (signal_flag != 'X') && (signal_flag != 'R') ) {
          sprintf(msg, "line# %d rule_id not specified \n",
                  first_line);
          hxfmsg(phtx_info, 0, SYSERR, msg);
          error = 'y';
       } else
          rc = 0;
    } else {
       rc = EOF;
       line = 0;
    }
    if ( error == 'y' )
       rc = 1;
    return(rc);
}
Пример #11
0
 MPIEnvironment(int &argc, char **&argv, bool abort_on_exception = true) :
     env_(argc, argv, abort_on_exception) {init_seed();}
Пример #12
0
 explicit MPIEnvironment (bool abort_on_exception = true) :
     env_(abort_on_exception) {init_seed();}
Пример #13
0
int
proc_rule(struct htx_data *phtx_info, struct ruleinfo *prule_info,
          char *wbuf, char *rbuf, struct blk_num_typ *pblk_num)
{
  int            dlen, loop, rc;                   
  char           msg[220], path[100];
  unsigned short seed[3];

  rc = 0;
  init_seed(seed);            /* initialize seed for random number generator */
  dlen = prule_info->num_blks * BLK_SIZE;       /* initialize length of data */
                                           /*-------------------------------*/
                                           /* initialize the write buffer   */
                                           /*-------------------------------*/
  if ( (prule_info->pattern_id[0] != '#') && 
       (prule_info->pattern_id[0] != 0) ) {
	 path[0] ='\0';	  
     if ( (int) htx_strlen((char *) htx_strcpy(path, getenv("HTXPATTERNS"))) == 0 )
        htx_strcpy(path, "../pattern/");         /* default ONLY */
     htx_strcat (path, prule_info->pattern_id);
     rc = hxfpat(path, wbuf, dlen);
     if ( rc == 1 ) {
        sprintf(msg, "cannot open pattern file - %s\n", path);
        hxfmsg(phtx_info, 0, SYSERR, msg);
        return(1);
     } 
     if ( rc == 2 ) {
        sprintf(msg, "cannot read pattern file - %s\n", path);
        hxfmsg(phtx_info, 0, SYSERR, msg);
        return(1);
     } 
  } else if ( prule_info->pattern_id[0] == '#' )
     bldbuf((unsigned short*)wbuf, dlen, prule_info->pattern_id, pblk_num);
  pblk_num->in_rule = 0;      /* initialize block number within current rule */
  rc = 0;
  tape_error_code = 0;
  for ( loop = 1; loop <= prule_info->num_oper; loop++ ) {
     if ( strcmp(prule_info->oper, "R") == 0 ) {     
        rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf);
     } else if ( strcmp(prule_info->oper, "W") == 0 ) {
        rc = write_tape(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "RC") == 0 ) {   
        rc = read_tape(phtx_info, prule_info, loop, pblk_num, rbuf);
        if ( rc >= 0 )     
           rc = cmpbuf(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "RW") == 0 ) {
        rc = rewind_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "WEOF") == 0 ) { 
        rc = weof_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "SF") == 0 ) {  
        rc = search_file(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "SR") == 0 ) {  
        rc = search_rec(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "D") == 0 ) { 
        rc = diag_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "E") == 0 ) { 
        rc = erase_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "S") == 0 ) { 
        rc = do_sleep(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "CO") == 0 ) { 
        rc = close_open(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "C") == 0 ) { 
        rc = tclose(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "O") == 0 ) {  
        rc = topen(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "WEOT") == 0 ) {
        rc = write_eot(phtx_info, prule_info,loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "RCEOT") == 0 ) {
        rc = read_eot(phtx_info, prule_info, loop,pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "REOT") == 0 ) {  
        rc = read_teot(phtx_info, prule_info, loop, pblk_num, wbuf, rbuf);
     } else if ( strcmp(prule_info->oper, "RS") == 0 ) {  
        rc = prt_req_sense(phtx_info, prule_info, loop, pblk_num);
	 }
#ifndef __HTX_LINUX__		
     else if ( strcmp(prule_info->oper, "ML") == 0 ) { 
        rc = medium_load(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "MUL") == 0 ) {   
        rc = medium_unload(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "RES") == 0 ) {   
        rc = read_status(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "IE") == 0 ) {   
        rc = init_element(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "RP") == 0 ) {  
        rc = read_posit(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "LB") == 0 ) {   
        rc = loc_block(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ASF") == 0 ) { 
        rc = asearch_file(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ASR") == 0 ) { 
        rc = asearch_rec(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "ADUL") == 0 ) {  
        rc = write_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "TWIE") == 0 ) {  
        rc = twin_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWPE") == 0 ) {   
        rc = twps_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWRE") == 0 ) {  
        rc = twrd_stat(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWMM") == 0 ) { 
        rc = twmv_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "TWUL") == 0 ) {  
        rc = unload_write(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "WUL") == 0 ) {   
        rc = tape_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "CDRE") == 0 ) {
        rc = cdrd_stat(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "CDMM") == 0 ) {  
        rc = cdmv_tape(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HUNL") == 0 ) {
        rc = himove(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HINI") == 0 ) {
        rc = hiinit(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HREL") == 0 ) {
        rc = hielem(phtx_info, prule_info, loop, pblk_num);
     } else if ( strcmp(prule_info->oper, "HWUN") == 0 ) {
        rc = hidal_unload(phtx_info, prule_info, loop, pblk_num, wbuf);
     } else if ( strcmp(prule_info->oper, "DBUG") == 0 ) {  
       rc = set_dbug(phtx_info, prule_info, pblk_num);
     } 
#endif
	 else if ( strcmp(prule_info->oper, "XCMD") == 0 ) {
       rc = do_cmd(phtx_info, prule_info, pblk_num);
     } else {
        ;
     }
     hxfupdate(UPDATE, phtx_info);
     if ( phtx_info->run_type[0] == 'O' ) {
        info_msg(phtx_info, prule_info, loop, pblk_num, msg);
        hxfmsg(phtx_info, 0, INFO, msg);
     } 
     if ( rc != 0 )
        break;
  } 
  return(rc);
} 
Пример #14
0
int proc_rule(struct htx_data *ps, struct ruleinfo *pr, char *wbuf, char *rbuf, unsigned int *last_lba, unsigned int *pblk_size)
{
  int            blkno[3], blkno_save[3]; /* block # ptrs 0-curr,1-up,2-dwn */
  int            rc, i, rc_ptr, save_dlen, loop;
  unsigned short seed[3];
  char           path[100], msg[221], *tbuf, *tbuf_malloc;

  int read_res = -1;

  tbuf_malloc = malloc(TMP_BUF_SIZE + PAGE_SIZE);
  if(tbuf_malloc == NULL) { /* Out of memory? */
     sprintf(msg, "Cannot allocate memory for tbuf: %d bytes\n", TMP_BUF_SIZE + PAGE_SIZE);
     hxfmsg(ps, 0, SYSERR, msg);
     return(1);
  }

#ifndef __HTX_LINUX__     /* AIX */
  tbuf = tbuf_malloc;
#else                     /* Linux */
  /* Page align the tmp buffer for linux raw IO */
  tbuf = (char *)HTX_PAGE_ALIGN(tbuf_malloc);
#endif

  init_seed(seed);                /* init seed for random number generator */
  if ( strcmp(pr->addr_type, "SEQ") == 0 ||         /* init length of data */
       strcmp(pr->type_length, "FIXED") == 0)       /* to be transmitted   */
     pr->dlen = pr->num_blks * pr->bytpsec;
  else
     pr->dlen = random_dlen(pr->bytpsec, pr->tot_blks, seed);
  if ( strcmp(pr->oper, "RC") == 0 ) {      /* init write buff for oper RC */
                                   /* get HTXPATTERNS environment variable */
     strcpy(path, ""); /* Linux will need this initialization */
     if ((char *) getenv("HTXPATTERNS") != NULL) {
                 strcpy(path, (char *) getenv("HTXPATTERNS"));
     } else {
         strcpy(path, "../pattern/");                       /* default ONLY */
     }
     strcat (path, pr->pattern_id);
     rc = hxfpat(path, wbuf, pr->dlen);
     if ( rc == 1 ) {
        sprintf(msg, "Cannot open pattern file - %s\n", path);
        hxfmsg(ps, 0, SYSERR, msg);
        return(1);
     }
     if ( rc == 2 ) {
        sprintf(msg, "Cannot read pattern file - %s\n", path);
        hxfmsg(ps, 0, SYSERR, msg);
        return(1);
     }
  }
  if ( strcmp(pr->addr_type, "SEQ") == 0 )    /* init current block number */
     init_blkno(pr, blkno);
  else
     random_blkno(blkno, pr->dlen, pr->bytpsec, pr->max_blkno, seed,
                  pr->min_blkno);
  for ( i = 0; i < 3; i++ )
      blkno_save[i] = blkno[i];

  for ( loop = 1 ; loop <= pr->num_oper ; loop++ ) {
     if ( strcmp(pr->oper, "MS") == 0 ) {
        ms_get(pr, ps, last_lba, pblk_size);
    } else if ( strcmp(pr->oper, "R") == 0 ) {
        read_cdrom(ps, pr, loop, blkno, rbuf);
    } else if ( strcmp(pr->oper, "RWP") == 0 ) {
        read_write_pattern(ps, pr, loop, blkno, rbuf);
    } else if ( strcmp(pr->oper, "RRC") == 0 ) {
        /*read_cdrom(ps, pr, loop, blkno, wbuf);
        read_cdrom(ps, pr, loop, blkno, rbuf);*/

        if( (read_res = read_cdrom(ps, pr, loop, blkno, wbuf) ) == 0 ) {/* read success */
        	if( (read_res = read_cdrom(ps, pr, loop, blkno, rbuf) ) == 0 ) {/* read success, again */
        		cmpbuf(ps, pr, loop, blkno, wbuf, rbuf); /* safe to compare */
			} else { /* second read fail */
				 sprintf(msg, "read_cdrom() failed in Re-Read sequence of RRC oper\n"
				              "Skipping compare operation\n");
				 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
			}
		} else { /* first read fail */
			 sprintf(msg, "read_cdrom() failed in Read sequence of RRC oper\n"
						  "Skipping compare operation\n");
			 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
		}

    } else if ( strcmp(pr->oper, "RC") == 0 ) {
        for ( i = 0; i < 3; i++ )
           blkno[i] = blkno_save[i];      /* RC = always start at same blkno */
                       /******************************************************/
                       /*- First, read the successive data blocks into rbuf  -*/
                       /******************************************************/
        save_dlen = pr->dlen;
        rc_ptr = 0;                          /*- init read/compare pointer --*/
        pr->dlen = pr->bytpsec;      /*-- read 1 block at a time into rbuf --*/
        while ( rc_ptr <= pr->num_blks ) {
           /*read_cdrom(ps, pr, loop, blkno, tbuf);*/
           if( ( read_res = read_cdrom(ps, pr, loop, blkno, tbuf) ) != 0 ) /* read un-succesfull ?*/
           		break;

           for ( i = 0; i <= pr->dlen; i++ )
               rbuf[(pr->dlen*rc_ptr)+i] = tbuf[i];
           set_blkno(blkno, pr->direction, pr->increment, 1);
           rc_ptr++;
        }
        if( read_res == 0 ) {/* only if all reads are successful ... */
			pr->dlen = save_dlen;
			cmpbuf(ps, pr, loop, blkno_save, wbuf, rbuf);
		} else { /* read fail */
			 sprintf(msg, "read_cdrom() failed in Read sequence of RC oper\n"
						  "Skipping compare operation\n");
			 prt_msg(ps, pr, loop, blkno, 0, SOFT, msg);
		}

    } else if ( strcmp(pr->oper, "D") == 0 ) {
        diag_cdrom(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "A") == 0 ) {
      #ifndef __HTX_LINUX__
        audio_cdrom(ps, pr, loop, blkno);
      #endif
    } else if ( strcmp(pr->oper, "AMM") == 0 ) {
		if ( (0 != strncmp(device_subclass, "sata", 16)) && (0 != strncmp(device_subclass, "usbif", 16)) ) {
			/* PLAYUDIO MSF is not supported for SATA drives */
        	audio_mm(ps, pr, loop, blkno);
		}
		else {
			sprintf(msg, "Skipping AMM stanza for SATA/USB drive, rule_id = %s\n", pr->rule_id);
       		hxfmsg(ps, 0, INFO, msg);
		}
    } else if ( strcmp(pr->oper, "RS") == 0 ) {
        prt_req_sense(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "S") == 0 ) {
        do_sleep(ps, pr, loop, blkno);
    } else if ( strcmp(pr->oper, "XCMD") == 0 ) {
        rc = do_cmd(ps, pr);
    } else {
        ;
    }

    hxfupdate(UPDATE, ps);
    if ( ps->run_type[0] == 'O' ) {
       info_msg(ps, pr, loop, blkno, msg);
       hxfmsg(ps, 0, INFO, msg);
    }
    if ( strcmp(pr->type_length, "RANDOM") == 0 && /* set lgth of data trans */
         strcmp(pr->addr_type, "RANDOM") == 0 )    /* if random is specified */
       pr->dlen = random_dlen(pr->bytpsec, pr->tot_blks, seed);
    if ( strcmp(pr->addr_type, "RANDOM") == 0 ) /* set block # for next oper */
       random_blkno(blkno, pr->dlen, pr->bytpsec, pr->max_blkno, seed,
                    pr->min_blkno);
    else if ( (strcmp(pr->oper, "RC") != 0 ) /* set blkno if not RC or RWP */
		      && ( strcmp(pr->oper, "RWP") != 0 ))
       set_blkno(blkno, pr->direction, pr->increment, pr->num_blks);
    if ( strcmp(pr->addr_type, "SEQ") == 0 ) {
       rc = wrap(pr, blkno);
       if ( rc == 1 )
          init_blkno(pr,blkno);
    }
  }
  free(tbuf_malloc);
  return(0);
}
Пример #15
0
int main(int argc, char **argv)
{

	int ret, verbose = 0; unsigned int i;
	char *affix = NULL;
	char *prefix = NULL;
	int opt = 0;
	int len = 0;
	char *png_filename = NULL;
	unsigned int entries = DEFAULT_ENTRIES;
	unsigned int table_size = DEFAULT_HASHTABLE_SIZE;
	hi_handle_t *hi_handle;
	uint32_t (*hashf)(const uint8_t *, uint32_t);
	const char *hashfname;

	hashf = NULL;

	while ((opt = getopt(argc, argv, "hqn:l:p:t:a:g:f:v")) != -1) {
		switch (opt) {
		case 'q':
			{
			int max_fd, std_fd, j;
			if ((max_fd = (int) sysconf(_SC_OPEN_MAX)) < 0) {
				max_fd = 256;
			}
			for (j = max_fd - 1; j >= 0; --j) {
				close(j);
			}
			std_fd = open("/dev/null", O_RDWR);
			dup(std_fd);
			dup(std_fd);
			}
			break;
		case 'f':
			if (!(strcasecmp(optarg, "elf"))) {
				hashf = lhi_hash_elf;
				hashfname = "lhi_hash_elf";
			} else if (!(strcasecmp(optarg, "torek"))) {
				hashf = lhi_hash_torek;
				hashfname = "lhi_hash_torek";
			} else if (!(strcasecmp(optarg, "dumb1"))) {
				hashf = lhi_hash_dumb1;
				hashfname = "lhi_hash_dumb1";
			} else if (!(strcasecmp(optarg, "phong"))) {
				hashf = lhi_hash_phong;
				hashfname = "lhi_hash_phong";
			} else {
				fprintf(stderr, "Hashing function not supported: %s\n",
						optarg);
				usage(EXIT_FAILURE, argv[0]);
			}
			break;
		case 'h':
			usage(EXIT_SUCCESS, argv[0]);
			break;
		case 'n':
			entries = atoi(optarg);
			break;
		case 'l':
			len = atoi(optarg);
			break;
		case 'p':
			prefix = strdup(optarg);
			break;
		case 't':
			table_size = atoi(optarg);
			break;
		case 'v':
			verbose++;
			break;
		case 'a':
			affix = strdup(optarg);
			break;
		case 'g':
#ifdef HAVE_LIBGD
			png_filename = strdup(optarg);
# else
			fprintf(stderr, "sorry - you build without gd library support\n");
			usage(EXIT_FAILURE, argv[0]);
#endif
			break;
		case '?':
			fprintf(stderr, "No such option: `%c'\n\n", optopt);
			usage(EXIT_FAILURE, argv[0]);
			break;
		}
	}

	fputs("# String Distribution Hash Test\n", stderr);

	/* initialize secure[tm] rand() seed */
	init_seed();

	/* initialize hash table */
	ret = hi_init_str(&hi_handle, table_size);

	if (hashf != NULL) {
		lhi_sethashfunc(hi_handle, hashf);
		fprintf(stderr, "# take %s as hash function\n", hashfname);
	}

	/* fill hash table */
	for(i = 0; i < entries; i++) {

		char *key = NULL, *tmp_key;
		size_t key_len = 0;

		/* compound key */
		if (len == 0) {
			len = (rand() % (MAX_STRING_LEN - MIN_STRING_LEN + 1)) + MIN_STRING_LEN;
		}
		if (random_string(len, &tmp_key) < 0)
			exit(EXIT_FAILURE);

		if (prefix)
			key_len += strlen(prefix);
		key_len += strlen(tmp_key);
		if (affix)
			key_len += strlen(affix);


		key = malloc(key_len + 1);
		if (key == NULL) {
			fprintf(stderr, "malloc %s\n", strerror(errno));
			exit(1);
		}

		if (prefix != NULL) {
			sprintf(&key[0], "%s%s", prefix, tmp_key);
		} else {
			sprintf(key, "%s", tmp_key);
		}

		free(tmp_key);
		tmp_key = NULL;

		if (affix)
			strcat(key, affix);

		if (verbose >= 1)
			fprintf(stdout, "key: %s\n", key);

		ret = hi_insert_str(hi_handle, (void *) key, NULL);
		if (ret < 0)
			fprintf(stderr, "# WARNING: Can't insert key (maybe a duplicated key: %s)!\n", key);
	}

	/* print statistic */
	ret = hi_size(hi_handle);
	fprintf(stderr, "# hash table entries: %d\n", ret);

	if (png_filename) { /* grapical output */

#ifdef HAVE_LIBGD
# define RECT_SIZE 5
# define RECT_BODER_SIZE 1

		int j;
		uint32_t x, y;
		gdImagePtr im;
		FILE *pngout;
		int black, white, red, max_list_len = 0;


		/* calculate maximum listsize */
		for(i = 0; i < table_size; i++) {
			int tmp_bucket_size = hi_bucket_size(hi_handle, i);
			max_list_len = max(max_list_len, tmp_bucket_size);
		}


		/* create a image with max_list_len X table_size */
		im = gdImageCreate((max_list_len * (RECT_SIZE + RECT_BODER_SIZE * 2)) + 2,
				(table_size * ((RECT_SIZE + RECT_BODER_SIZE * 2)) + 2));

		black = gdImageColorAllocate(im, 255, 231, 186);
		white = gdImageColorAllocate(im, 255, 165, 79);
		red   = gdImageColorAllocate(im, 205, 102, 29);

		x = 1;
		y = 1;

		for (i = 0; i < table_size; i++) {
			int bucket_size =  hi_bucket_size(hi_handle, i);
			for (j = 0; j < bucket_size; j++) {
				gdImageFilledRectangle(im, x + 1, y + 1, x + RECT_SIZE, y + RECT_SIZE, white);
				gdImageRectangle(im, x, y, x + RECT_SIZE + (RECT_BODER_SIZE << 1), y + RECT_SIZE + (RECT_BODER_SIZE << 1), red);
				x += RECT_SIZE + (RECT_BODER_SIZE << 1);
			}
			x = 1;
			y += RECT_SIZE + (RECT_BODER_SIZE << 1);
		}

		pngout = fopen(png_filename, "wb");
		gdImagePng(im, pngout);
		fclose(pngout);
		gdImageDestroy(im);

# undef RECT_SIZE
# undef RECT_BODER_SIZE
#endif /* HAVE_LIBGD */

	}

	if (verbose >= 1) {  /* terminal output */
		for(i = 0; i < table_size; i++) {
			fprintf(stderr, "bucket no: %d bucket size: %d\n",
					i, hi_bucket_size(hi_handle, i));
		}

	}

	/* delete table */
	hi_fini(hi_handle);

	return 0;
}
Пример #16
0
void init_itemtypes(void)
{
  init_seed();
  init_mallornseed();
}