Beispiel #1
0
int Fact::isTrue(Fact* fact, Time time)
{
   if((fact->getType() == getType()) && 
      ((time > (starttime())) || (time == starttime())) &&
      (time < endTime()))
      {
         return 1;
      }
   else
      {
         return 0;
      }
}
Beispiel #2
0
static void cont_catcher(int signo UNUSED)
{
    noecho();
    raw();
    clearok(stdscr, 1);
    move(crow, ccol);
    refresh();
    starttime();
}
Beispiel #3
0
 void show(bool on)
 {
     if(!showing && on)
     {
         menupos = menuinfrontofplayer();
         menustart = starttime();
     }
     showing = on;
 }
Beispiel #4
0
 void show(int n)
 {
     if((time && n==which) || !n)
         time = 0;
     else
     {
         time = starttime();
         pos  = menuinfrontofplayer();        
         which = n;
     }
 }
Beispiel #5
0
int main(void)
{
   int n=400, noisy=0, i,j;
   int nr=10, ir, TimeSquare=10, algorithm; /* TimeSquare should be larger for large t */
   double t=5, *Q, *pi, *space, s;
   char timestr[96], *AlgStr[2]={"repeated squaring", "eigensolution"};
   
   if((Q=(double*)malloc(n*n*5*sizeof(double))) ==NULL) error2("oom");
   pi=Q+n*n; space=pi+n;

   for(algorithm=0; algorithm<2; algorithm++) {
      starttime();
      SetSeed(1234567);
      for (i=0; i<n; i++)  pi[i]=rndu();
      s=sum(pi,n);
      for (i=0; i<n; i++)  pi[i]/=s;

      for(ir=0; ir<nr; ir++) {
         printf("Replicate %d/%d ", ir+1,nr);

   	   for (i=0; i<n; i++)  
            for (j=0,Q[i*n+i]=0; j<i; j++)
               Q[i*n+j]=Q[j*n+i] = square(rndu());
         for (i=0; i<n; i++)
            for (j=0; j<n; j++)
               Q[i*n+j] *= pi[j];
         for(i=0,s=0; i<n; i++)  {  /* rescaling Q so that average rate is 1 */
            Q[i*n+i]=0; Q[i*n+i]=-sum(Q+i*n, n); 
            s-=pi[i]*Q[i*n+i];
         }

         if(noisy) {
            matout(stdout, pi, 1, n);
            matout(stdout, Q, n, n);
         }

         if(algorithm==0) 
            matexp(Q, 1, n, TimeSquare, space);
         else 
            PMatQRev(Q, pi, 1, n, space);
         printf("%s, time: %s\n", AlgStr[algorithm], printtime(timestr));
         if(noisy) 
            matout(stdout, Q, n, n);
      }
   }
   return (0);
}
Beispiel #6
0
int
main(int argc, char *argv[])
{
	struct timeval etim;
	float elapsed;

	if (argc != 2) {
		fprintf(stderr, "usage: %s dir\n", argv[0]);
		exit(1);
	}

	starttime();
	statit(argv[1]);
	endtime(&etim);
	elapsed = (float)etim.tv_sec + (float)etim.tv_usec / 1000000.0;
	fprintf(stdout, "%d calls in %f seconds (%f calls/sec)\n",
	    stats, elapsed, (float)stats / elapsed);
	return (0);
}
void CDlgHistoryLogUser::OnBnClickedButtonHlQuery()
{
	UpdateData(true);

	int i = 0, j = 0;
	char s_starttime[128]={0};
	char s_stoptime[128]={0};

	CTime starttime(m_StartDay.GetYear(), m_StartDay.GetMonth(), m_StartDay.GetDay(),
		m_StartTime.GetHour(), m_StartTime.GetMinute(), m_StartTime.GetSecond());
	CTime stoptime(m_StopDay.GetYear(), m_StopDay.GetMonth(), m_StopDay.GetDay(),
		m_StopTime.GetHour(), m_StopTime.GetMinute(), m_StopTime.GetSecond());

	if (stoptime <= starttime)
	{
		MessageBox("时间选择错误:开始时间大于结束时间","视频监视");
		return;
	}

	sprintf(s_starttime, "%04d-%02d-%02d %02d:%02d:%02d",
		m_StartDay.GetYear(), m_StartDay.GetMonth(), m_StartDay.GetDay(),
		m_StartTime.GetHour(), m_StartTime.GetMinute(), m_StartTime.GetSecond());
	sprintf(s_stoptime, "%04d-%02d-%02d %02d:%02d:%02d",
		m_StopDay.GetYear(), m_StopDay.GetMonth(), m_StopDay.GetDay(),
		m_StopTime.GetHour(), m_StopTime.GetMinute(), m_StopTime.GetSecond());

	//鼠标为等待状态
	AfxGetApp()->DoWaitCursor(1); 

	m_ListCtrl_UserLog.DeleteAllItems();

	int nSelectIndex = m_ComboType.GetCurSel();

	if (nSelectIndex == 0)    //管理端操作
		SearchAndSetHistoryListInfo(s_starttime,s_stoptime,(char *)(LPCTSTR)m_strNodeName);
	else if(nSelectIndex == 1)    //客户端操作
		SearchAndSetHistoryListInfo2(s_starttime,s_stoptime,(char *)(LPCTSTR)m_strNodeName);
	else if(nSelectIndex == 2)    //辅助系统管理端操作
		SearchAndSetHistoryListInfo3(s_starttime,s_stoptime,(char *)(LPCTSTR)m_strNodeName);
	//恢复鼠标为正常状态
	AfxGetApp()->DoWaitCursor(0);
}
Beispiel #8
0
void test2()
{
    int i;
    long long int cost = 0;
    struct timeval tv;
    starttime(&tv);

    for(i = 0; i < TIMES; i++)
    {
        p[i] = (test *)malloc(sizeof(test));

    }
    //cost = stoptime(tv);
    for(i = 0; i < TIMES; i++)
    {
        free(p[i]);
    }
    cost = stoptime(tv);
    printf("%lld\n", cost/1000);
}
Beispiel #9
0
HRESULT FlvStream::Start(UINT64 nanosec, BOOL isseek) {
  SourceLock lock(source);
  _prop_variant_t starttime(nanosec);
  auto hr = CheckShutdown();
  if (ok(hr) && isseek) {
    samples.clear();// abandon previsou cached samples, but keep tokens
    QueueEvent(MEStreamSeeked, GUID_NULL, hr, &starttime);
  } else if (ok(hr)) {// Queue the stream-started event.
    hr = QueueEvent(MEStreamStarted, GUID_NULL, S_OK, &starttime);
  }

  if (ok(hr)) {
    m_state = SourceState::STATE_STARTED;
  }

  // If we are restarting from paused, there may be
  // queue sample requests. Dispatch them now.
  if (ok(hr)) {
    hr = DispatchSamples();
  }
  return hr;
}
Beispiel #10
0
int main()
{
    fp = fopen("log.txt","w+");

    long long int cost = 0;
    struct timeval tv;
    starttime(&tv);

    thread_pool_t *pool = threadpool_create(2, 4, 10000);
    int i;
    for(i = 0; i < 1000; i++)
    {
        dispatch(pool, test_fun, (void *)i);
    }
    //sleep(5);
    dispatch(pool, test_fun, (void *)i, EMG_PRI);
    threadpool_destroy(pool, 1);

    cost = stoptime(tv);
    printf("%lld\n", cost/1000);

    return 0;
}
//**************************************************************************
// ApptDialog :: command - Process Commands                               *
//**************************************************************************
Boolean ApptDialog :: command(ICommandEvent& cmdevt)
{
  Environment *ev = somGetGlobalEnvironment();
  ITime starttime(fldStarthr.value(), fldStartmin.value());
  ITime stoptime(fldStophr.value(), fldStopmin.value());

  switch(cmdevt.commandId()) {
    case DID_OK:
      switch (apptType) {
         case MEETING:
           apptObject->_set_start(ev,starttime.asSeconds());
           apptObject->_set_end(ev,stoptime.asSeconds());
           apptObject->_set_subject(ev,mleSubj.text());
           ((Meeting *)apptObject)->_set_location(ev,fldLoc.text());
           break;
         case CCALL:
           apptObject->_set_start(ev,starttime.asSeconds());
           apptObject->_set_end(ev,stoptime.asSeconds());
           apptObject->_set_subject(ev,mleSubj.text());
           ((ConferenceCall *)apptObject)->_set_phoneNumber(ev,fldPhone.text());
           break;
         default:
           break;
      } /* End switch*/
      dismiss(DID_OK);
      return(true);
      break;

    case DID_CANCEL:
      dismiss(DID_CANCEL);
      return(true);
      break;
  }/* end switch */

  return(false);  //Allow Default Processing to occur
}
Beispiel #12
0
void test1()
{
    fix_mpool_t *pool = fmem_create(TIMES, sizeof(test));
    int i;
    long long int cost = 0;
    struct timeval tv;
    starttime(&tv);
    //pool_t *pool = mem_init(TIMES, sizeof(test));

    for(i = 0; i < TIMES; i++)
    {
        p[i] = (test *)fmem_alloc(pool);
        //memset(p[i], 0, sizeof(test));
    }
    for(i = 0; i < TIMES; i++)
    {
        fmem_free(pool, p[i]);
    }
    // mem_info(pool);
    cost = stoptime(tv);
    fmem_destroy(pool);
    printf("%lld\n", cost/1000);

}
Beispiel #13
0
bool MythTimeInputDialog::Create()
{
    if (!CopyWindowFromBase("MythTimeInputDialog", this))
        return false;

    MythUIText *messageText = NULL;
    MythUIButton *okButton = NULL;

    bool err = false;
    UIUtilE::Assign(this, messageText, "message", &err);
    UIUtilE::Assign(this, m_dateList, "dates", &err);
    UIUtilE::Assign(this, m_timeList, "times", &err);
    UIUtilE::Assign(this, okButton, "ok", &err);

    if (err)
    {
        LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
        return false;
    }

    m_dateList->SetVisible(false);
    m_timeList->SetVisible(false);

    MythUIButtonListItem *item;
    // Date
    if (kNoDate != (m_resolution & 0xF))
    {
        const QDate startdate(m_startTime.toLocalTime().date());
        QDate date(startdate);

        int limit = 0;
        if (m_resolution & kFutureDates)
        {
            limit += m_rangeLimit;
        }
        if (m_resolution & kPastDates)
        {
            limit += m_rangeLimit;
            date = date.addDays(0-m_rangeLimit);
        }

        QString text;
        int flags;
        bool selected = false;
        for (int x = 0; x <= limit; x++)
        {
            selected = false;
            if (m_resolution & kDay)
            {
                date = date.addDays(1);
                flags = MythDate::kDateFull | MythDate::kSimplify;
                if (m_rangeLimit >= 356)
                    flags |= MythDate::kAddYear;
                text = MythDate::toString(date, flags);

                if (date == startdate)
                    selected = true;
            }
            else if (m_resolution & kMonth)
            {
                date = date.addMonths(1);
                text = date.toString("MMM yyyy");

                if ((date.month() == startdate.month()) &&
                    (date.year() == startdate.year()))
                    selected = true;
            }
            else if (m_resolution & kYear)
            {
                date = date.addYears(1);
                text = date.toString("yyyy");
                if (date.year() == startdate.year())
                    selected = true;
            }

            item = new MythUIButtonListItem(m_dateList, text, NULL, false);
            item->SetData(QVariant(date));

            if (selected)
                m_dateList->SetItemCurrent(item);
        }
        m_dateList->SetVisible(true);
    }

    // Time
    if (kNoTime != (m_resolution & 0xF0))
    {
        QDate startdate(m_startTime.toLocalTime().date());
        QTime starttime(m_startTime.toLocalTime().time());
        QTime time(0,0,0);
        QString text;
        bool selected = false;

        int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;

        for (int x = 0; x < limit; x++)
        {
            selected = false;
            if (m_resolution & kMinutes)
            {
                time = time.addSecs(60);
                QDateTime dt = QDateTime(startdate, time, Qt::LocalTime);
                text = MythDate::toString(dt, MythDate::kTime);

                if (time == starttime)
                    selected = true;
            }
            else if (m_resolution & kHours)
            {
                time = time.addSecs(60*60);
                text = time.toString("hh:00");

                if (time.hour() == starttime.hour())
                    selected = true;
            }

            item = new MythUIButtonListItem(m_timeList, text, NULL, false);
            item->SetData(QVariant(time));

            if (selected)
                m_timeList->SetItemCurrent(item);
        }
        m_timeList->SetVisible(true);
    }

    if (messageText && !m_message.isEmpty())
        messageText->SetText(m_message);

    connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));

    BuildFocusList();

    return true;
}
Beispiel #14
0
int main(int argc, char *argv[])
{
  int files;                    /* number of files in each dir */
  int totfiles = 0;
  int dirs;                     /* directories in each dir */
  int totdirs = 0;
  int levels;                   /* levels deep */
  char *fname;
  char *dname;
  struct timeval time;
  char *opts;
  struct testparam *param;
  struct btest *b;
  char *config_file;
  char *test_dir;
  char *log_file;
  FILE *log;

  setbuf(stdout, NULL);
  Myname = *argv++;
  argc--;
  while(argc && **argv == '-')
    {
      for(opts = &argv[0][1]; *opts; opts++)
        {
          switch (*opts)
            {
            case 'h':          /* help */
              usage();
              exit(1);
              break;

            case 's':          /* silent */
              Sflag++;
              break;

            case 't':          /* time */
              Tflag++;
              break;

            case 'f':          /* funtionality */
              Fflag++;
              break;

            case 'n':          /* No Test Directory create */
              Nflag++;
              break;

            default:
              error("unknown option '%c'", *opts);
              usage();
              exit(1);
            }
        }
      argc--;
      argv++;
    }

  if(argc)
    {
      config_file = *argv;
      argc--;
      argv++;
    }
  else
    {
      fprintf(stderr, "Missing config_file");
      exit(1);
    }

  if(argc != 0)
    {
      fprintf(stderr, "too many parameters");
      usage();
      exit(1);
    }

  param = readin_config(config_file);
  if(param == NULL)
    {
      fprintf(stderr, "Nothing built\n");
      exit(1);
    }

  b = get_btest_args(param, ONE);
  if(b == NULL)
    {
      fprintf(stderr, "Missing basic test number 1 in the config file '%s'\n",
              config_file);
      free_testparam(param);
      exit(1);
    }

  if(b->levels == -1)
    {
      fprintf(stderr,
              "Missing 'levels' parameter in the config file '%s' for the basic test number 1\n",
              config_file);
      free_testparam(param);
      exit(1);
    }
  if(b->files == -1)
    {
      fprintf(stderr,
              "Missing 'files' parameter in the config file '%s' for the basic test number 1\n",
              config_file);
      free_testparam(param);
      exit(1);
    }
  if(b->dirs == -1)
    {
      fprintf(stderr,
              "Missing 'dirs' parameter in the config file '%s' for the basic test number 1\n",
              config_file);
      free_testparam(param);
      exit(1);
    }
  levels = b->levels;
  files = b->files;
  dirs = b->dirs;
  fname = b->fname;
  dname = b->dname;
  test_dir = get_test_directory(param);
  log_file = get_log_file(param);

  free_testparam(param);

  if(!Fflag)
    {
      Tflag = 0;
      levels = 2;
      files = 2;
      dirs = 2;
    }

  if(!Sflag)
    {
      fprintf(stdout, "%s: File and directory creation test\n", Myname);
    }

  if(!Nflag)
    testdir(test_dir);
  else
    mtestdir(test_dir);

  starttime();
  dirtree(levels, files, dirs, fname, dname, &totfiles, &totdirs);
  endtime(&time);

  if(!Sflag)
    {
      fprintf(stdout,
              "\tcreated %d files %d directories %d levels deep",
              totfiles, totdirs, levels);
    }
  if(Tflag && !Sflag)
    {
      fprintf(stdout, " in %ld.%02ld seconds",
              (long)time.tv_sec, (long)time.tv_usec / 10000);
    }
  if(!Sflag)
    {
      fprintf(stdout, "\n");
    }

  if((log = fopen(log_file, "a")) == NULL)
    {
      printf("Enable to open the file '%s'\n", log_file);
      complete();
    }
  fprintf(log, "b1\t%d\t%d\t%d\t%ld.%02ld\n", totfiles, totdirs, levels,
          (long)time.tv_sec, (long)time.tv_usec / 10000);
  fclose(log);

  complete();
}
Beispiel #15
0
QString Robot::handleTrainSchedule_step2(const QString& info,
                                         QString& icon, QString& detailurl)
{
    QString traininfo;
    int pos = info.indexOf(QStringLiteral("trainnum"));
    QString trainnum("");

    for(int i = pos + 11; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        trainnum += info.at(i);
    }

    pos = info.indexOf(QStringLiteral("start"));
    QString start("");

    for(int i = pos + 8; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        start += info.at(i);
    }

    pos = info.indexOf(QStringLiteral("terminal"));
    QString terminal("");
    for(int i = pos + 11; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        terminal += info.at(i);
    }
    pos = info.indexOf(QStringLiteral("starttime"));
    QString starttime("");
    for(int i = pos + 12; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        starttime += info.at(i);
    }
    pos = info.indexOf(QStringLiteral("endtime"));
    QString endtime("");
    for(int i = pos + 10; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        endtime += info.at(i);
    }
    //icon图标的地址
    pos = info.indexOf(QStringLiteral("icon"));

    for(int i = pos + 7; i < info.size(); i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        icon += info.at(i);
    }
    //detailurl
    pos = info.indexOf(QStringLiteral("detailurl"));
    for(int i = pos + 12; i < info.size();  i++)
    {
        if(info.at(i) == QChar('"'))
        {
            break;
        }
        detailurl += info.at(i);
    }
    traininfo.append(QStringLiteral("列车车次:") + trainnum + "\n");
    traininfo.append(QStringLiteral("起点:") + start + "\n");
    traininfo.append(QStringLiteral("终点:") + terminal + "\n");
    traininfo.append(QStringLiteral("开始时间:") + starttime + "\n");
    traininfo.append(QStringLiteral("到达时间:") + endtime);
    return traininfo;
}
Beispiel #16
0
// Main input routine
// - doesn't accept words longer than MAXWORDLEN or containing caps
char *boggle_getline(char *q)
{
    int ch, done;
    char *p;
    int row, col;

    p = q;
    done = 0;
    while (!done) {
	ch = timerch();
	switch (ch) {
	    case '\n':
	    case '\r':
	    case ' ':
		done = 1;
		break;
	    case '\033':
		findword();
		break;
	    case '\177':      // <del>
	    case '\010':      // <bs>
		if (p == q)
		    break;
		p--;
		getyx(stdscr, row, col);
		move(row, col - 1);
		clrtoeol();
		refresh();
		break;
	    case '\025':      // <^u>
	    case '\027':      // <^w>
		if (p == q)
		    break;
		getyx(stdscr, row, col);
		move(row, col - (int) (p - q));
		p = q;
		clrtoeol();
		refresh();
		break;
#ifdef SIGTSTP
	    case '\032':      // <^z>
		stop_catcher(0);
		break;
#endif
	    case '\023':      // <^s>
		stoptime();
		printw("<PAUSE>");
		refresh();
		while ((ch = inputch()) != '\021' && ch != '\023');
		move(crow, ccol);
		clrtoeol();
		refresh();
		starttime();
		break;
	    case '\003':      // <^c>
		cleanup();
		exit(0);
	     /*NOTREACHED*/ case '\004':	// <^d>
		done = 1;
		ch = EOF;
		break;
	    case '\014':      // <^l>
	    case '\022':      // <^r>
		redraw();
		break;
	    case '?':
		stoptime();
		if (help() < 0)
		    showstr("Can't open help file", 1);
		starttime();
		break;
	    default:
		if (!islower(ch))
		    break;
		if ((int) (p - q) == MAXWORDLEN) {
		    p = q;
		    badword();
		    break;
		}
		*p++ = ch;
		addch(ch);
		refresh();
		break;
	}
    }
    *p = '\0';
    if (ch == EOF)
	return (char *) NULL;
    return q;
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
	int files = 10;		/* number of files in each dir */
	int fi;
	int count = 50;	/* times to do each file */
	int ct;
	int totfiles = 0;
	int totdirs = 0;
	char *fname = FNAME;
	struct timeval time;
	char str[MAXPATHLEN];
	struct stat statb;
	char *opts;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);
					break;

				case 't':	/* time */
					Tflag++;
					break;

				case 'f':	/* funtionality */
					Fflag++;
					break;

				case 'n':	/* suppress initial directory */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argc--;
		argv++;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	fprintf(stdout, "%s: getattr and lookup\n", Myname);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		for (fi = 0; fi < files; fi++) {
			sprintf(str, "%s%d", fname, fi);
			if (stat(str, &statb) < 0) {
				error("can't stat %s", str);
				exit(1);
			}
		}
	}

	if (Tflag) {
		endtime(&time);
	}
	fprintf(stdout, "\t%d stats on %d files",
		files * count * 2, files);
	if (Tflag) {
		fprintf(stdout, " in %ld.%-2ld seconds",
		    (long)time.tv_sec, (long)time.tv_usec / 10000);
	}
	fprintf(stdout, "\n");
	/* XXX REMOVE DIRECTORY TREE? */
	complete();
	return 0;
}
Beispiel #18
0
int
main(int argc, char *argv[])
{
#ifdef use_directs
	struct direct *dp;
#else
	struct dirent *dp;
#endif
	char *fname = FNAME;
	int files = 200;	/* number of files in each dir */
	int fi;
	int count = 200;	/* times to read dir */
	int ct;
	int entries = 0;
	int totfiles = 0;
	int totdirs = 0;
	DIR *dir;
	struct timeval time;
	char *p, str[MAXPATHLEN];
	char *opts;
	int err, i, dot, dotdot;
	int nmoffset;

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);
					break;

				case 't':	/* time */
					Tflag++;
					break;
				
				case 'f':	/* funtionality */
					Fflag++;
					break;
				
				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				case 'i':	/* ignore spurious files */
					Iflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		files = getparm(*argv, 1, "files");
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		argv++;
		argc--;
	}
	if (argc) {
		fname = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	nmoffset = strlen(fname);

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	if (count > files) {
		error("count (%d) can't be greater than files (%d)",
			count, files);
		exit(1);
	}

	if (files > MAXFILES) {
		error("too many files requested (max is %d)", MAXFILES);
		exit(1);
	}

	fprintf(stdout, "%s: readdir\n", Myname);

	if (!Nflag)
		testdir(NULL);
	else
		mtestdir(NULL);

	dirtree(1, files, 0, fname, DNAME, &totfiles, &totdirs);

	if (Tflag) {
		starttime();
	}

	if ((dir = opendir(".")) == NULL) {
		error("can't opendir %s", ".");
		exit(1);
	}

	for (ct = 0; ct < count; ct++) {
		rewinddir(dir);
		dot = 0;
		dotdot = 0;
		err = 0;
		for (i = 0; i < sizeof(bitmap); i++)
			bitmap[i] = 0;
		while ((dp = readdir(dir)) != NULL) {
			entries++;
			if (strcmp(".", dp->d_name) == 0) {
				if (dot) {
					/* already read dot */
					error("'.' dir entry read twice");
					exit(1);
				}
				dot++;
				continue;
			} else if (strcmp("..", dp->d_name) == 0) {
				if (dotdot) {
					/* already read dotdot */
					error("'..' dir entry read twice");
					exit(1);
				}
				dotdot++;
				continue;
			}

			/*
			 * at this point, should have entry of the form
			 *  fname%d
			 */
			/* If we don't have our own directory, ignore
			   such errors (if Iflag set). */
			if (strncmp(dp->d_name, fname, nmoffset)) {
				if (Iflag)
					continue;
				else {
					error("unexpected dir entry '%s'",
						dp->d_name);
					exit(1);
				}
			}

			/* get ptr to numeric part of name */
			p = dp->d_name + nmoffset;
			fi = atoi(p);
			if (fi < 0 || fi >= MAXFILES) {
				error("unexpected dir entry '%s'",
					dp->d_name);
				exit(1);
			}
			if (BIT(fi)) {
				error("duplicate '%s' dir entry read",
					dp->d_name);
				err++;
			} else
				SETBIT(fi);
		}	/* end readdir loop */
		if (!dot) {
			error("didn't read '.' dir entry, pass %d", ct);
			err++;
		}
		if (!dotdot) {
			error("didn't read '..' dir entry, pass %d", ct);
			err++;
		}
		for (fi = 0; fi < ct; fi++) {
			if (BIT(fi)) {
				sprintf(str, "%s%d", fname, fi);
				error("unlinked '%s' dir entry read pass %d",
					str, ct);
				err++;
			}
		}
		for (fi = ct; fi < files; fi++) {
			if (!BIT(fi)) {
				sprintf(str, "%s%d", fname, fi);
				error("\
didn't read expected '%s' dir entry, pass %d", str, ct);
				err++;
			}
		}
		if (err) {
			error("Test failed with %d errors", err);
			exit(1);
		}
		sprintf(str, "%s%d", fname, ct);
		if (unlink(str) < 0) {
			error("can't unlink %s", str);
			exit(1);
		}
	}
Beispiel #19
0
int
main(int argc, char *argv[])
{
	int count = DCOUNT;	/* times to do each file */
	int ct;
	off_t size = DSIZE;
	off_t si;
	int fd;
	off_t bytes = 0;
	int roflags;			/* open read-only flags */
	char *bigfile = "bigfile";
	struct timeval time;
	char *opts;
	char buf[BUFSZ];
	double etime;
#ifdef MMAP
	caddr_t maddr;
#endif

	umask(0);
	setbuf(stdout, NULL);
	Myname = *argv++;
	argc--;
	while (argc && **argv == '-') {
		for (opts = &argv[0][1]; *opts; opts++) {
			switch (*opts) {
				case 'h':	/* help */
					usage();
					exit(1);
					break;

				case 't':	/* time */
					Tflag++;
					break;

				case 'f':	/* funtionality */
					Fflag++;
					break;

				case 'n':	/* No Test Directory create */
					Nflag++;
					break;

				default:
					error("unknown option '%c'", *opts);
					usage();
					exit(1);
			}
		}
		argc--;
		argv++;
	}

	if (argc) {
		size = getparm(*argv, 1, "size");
		if (size <= 0) {
			usage();
			exit(1);
		}
		argv++;
		argc--;
	}
	if (argc) {
		count = getparm(*argv, 1, "count");
		if (count <= 0) {
			usage();
			exit(1);
		}
		argv++;
		argc--;
	}
	if (argc) {
		bigfile = *argv;
		argv++;
		argc--;
	}
	if (argc) {
		usage();
		exit(1);
	}

	if (Fflag) {
		Tflag = 0;
		count = 1;
	}

	roflags = O_RDONLY;
#ifdef DOSorWIN32
	roflags |= O_BINARY;
#endif

	fprintf(stdout, "%s: read\n", Myname);

	mtestdir(NULL);

	if (Tflag) {
		starttime();
	}

	for (ct = 0; ct < count; ct++) {
		if ((fd = open(bigfile, roflags)) < 0) {
			error("can't open '%s'", bigfile);
			exit(1);
		}
#ifdef MMAP
		maddr = mmap((caddr_t)0, (size_t)size, PROT_READ,
				MAP_PRIVATE, fd, (off_t)0);
		if (maddr == MAP_FAILED) {
			error("can't mmap '%s'", bigfile);
			exit(1);
		}
		if (msync(maddr, (size_t)size, MS_INVALIDATE) < 0) {
			error("can't invalidate pages for '%s'", bigfile);
			exit(1);
		}
		if (munmap(maddr, (size_t)size) < 0) {
			error("can't munmap '%s'", bigfile);
			exit(1);
		}
#endif
		for (si = size; si > 0; si -= bytes) {
			bytes = MIN(BUFSZ, si);
			if (read(fd, buf, bytes) != bytes) {
				error("'%s' read failed", bigfile);
				exit(1);
			}
		}
		close(fd);
	}

	if (Tflag) {
		endtime(&time);
	}

	fprintf(stdout, "\tread %ld byte file %d times", (long)size, count);

	if (Tflag) {
		etime = (double)time.tv_sec + (double)time.tv_usec / 1000000.0;
		if (etime != 0.0) {
			fprintf(stdout, " in %ld.%-2ld seconds (%ld bytes/sec)",
				(long)time.tv_sec, (long)time.tv_usec / 10000,
				(long)((double)size * ((double)count / etime)));
		} else {
			fprintf(stdout, " in %ld.%-2ld seconds (> %ld bytes/sec)",
				(long)time.tv_sec, (long)time.tv_usec / 10000,
				(long)size * count);
		}
	}
	fprintf(stdout, "\n");

	if (unlink(bigfile) < 0) {
		error("can't unlink '%s'", bigfile);
		exit(1);
	}
	complete();
	return 0;
}