Exemple #1
0
void ndmca_test_fail(struct ndm_session* sess, char* fail_msg)
{
  static char fail_msg_buf[512];

  ndmca_test_open(sess, "UNKNOWN FAIL", 0);

  strcpy(fail_msg_buf, fail_msg);
  sess->control_acb->active_test_failed = fail_msg_buf;
}
Exemple #2
0
void ndmca_test_warn(struct ndm_session* sess, char* warn_msg)
{
  static char warn_msg_buf[512];

  ndmca_test_open(sess, "UNKNOWN WARN", 0);

  strcpy(warn_msg_buf, warn_msg);
  sess->control_acb->active_test_warned = warn_msg_buf;
}
Exemple #3
0
int
ndmca_test_call (struct ndmconn *conn,
  struct ndmp_xa_buf *xa, ndmp9_error expect_err)
{
	struct ndm_session *sess = conn->context;
	int		protocol_version = conn->protocol_version;
	unsigned	msg = xa->request.header.message;
	char *		msgname = ndmp_message_to_str (protocol_version, msg);
	unsigned	reply_error;
	int		rc;

	/* close previous test if there is one */
	ndmca_test_close (sess);

	/* open new 'test' */
	ndmca_test_open (sess, msgname, ndmp9_error_to_str (expect_err));

	rc = ndma_call_no_tattle (conn, xa);

	reply_error = ndmnmb_get_reply_error (&xa->reply);

	if (rc >= 0) {
		/* Call succeeded. Body valid */
		if (reply_error == expect_err) {
			/* Worked exactly as expected */
			rc = 0;
		} else if (reply_error != NDMP9_NO_ERR
		        && expect_err != NDMP9_NO_ERR) {
			/* both are errors, don't be picky about the codes */
			rc = 2;
		} else {
			/* intolerable mismatch */
			rc = 1;
		}
	}

	if (rc != 0) {
	    char tmpbuf[128];
	    sprintf(tmpbuf, "got %s (call)", ndmp9_error_to_str (reply_error));
	    if (rc == 2)
		ndmca_test_warn (sess, tmpbuf);
	    else
		ndmca_test_fail (sess, tmpbuf);

	    ndma_tattle (conn, xa, rc);

	    if (rc == 2)
		rc = 0;
	}

	return rc;
}
Exemple #4
0
/*
 * Assumes tt_write() passed
 */
int
ndmca_tt_mtio (struct ndm_session *sess)
{
	int		rc;
	unsigned	n_rec;
	unsigned	recsize;
	unsigned	fileno, recno;
	u_long		count, resid;
	char *		what;
	char		note[128];
	char		pbuf[64*1024];
	char		buf[64*1024];

	ndmca_test_phase (sess, "T-MTIO", "Tape MTIO");

	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	for (fileno = 0; tt_series[fileno].n_rec > 0; fileno++) {
		n_rec = tt_series[fileno].n_rec;
		recsize = tt_series[fileno].recsize;

		sprintf (note, "Seek around tape file %d", fileno+1);
		ndmca_test_open (sess, note, 0);

		sprintf (note, "file #%d, %d records, %d bytes/rec",
				fileno+1, n_rec, recsize);
		ndmca_test_log_note (sess, 2, note);

		what = "rew";
		count = 1;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_REW, count, &resid);
		if (rc) goto fail;

		what = "rew resid";
		if (resid != 0)
			goto fail;

		CHECK_FILENO_RECNO ("rew", 0, 0);


		what = "fsf(n)";
		count = fileno;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, count, &resid);
		if (rc) goto fail;

		what = "fsf(n) resid";
		if (resid != 0)
			goto fail;

		CHECK_FILENO_RECNO ("fsf", fileno, 0);


		what = "fsr(1m)";
		count = 1000000;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(1m) resid";
		if (n_rec + resid != count)
			goto fail;

		if (sess->plumb.tape->protocol_version < 4) {
		    CHECK_FILENO_RECNO ("fsr(1m)", fileno + 1, 0);

		    what = "bsf 1 after fsr(1m)";
		    count = 1;
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSF, count, 0);
		    if (rc) goto fail;

		    CHECK_FILENO_RECNO (what, fileno, -1);

		    recno = n_rec;
		} else {
		    /* EOT side of EOF marker */
		    recno = n_rec;
		    CHECK_FILENO_RECNO ("fsr(1m)", fileno, recno);
		}

		what = "bsr(1m)";
		count = 1000000;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSR, count, &resid);
		if (rc) goto fail;

		what = "bsr(1m) resid";
		if (n_rec + resid != count)
			goto fail;

		if ((fileno > 0) && (sess->plumb.tape->protocol_version < 4)) {
		    /* at BOT side of EOF marker (not BOT) */
		    CHECK_FILENO_RECNO ("bsr(1m)", fileno - 1, -1);

		    what = "fsf 1 after bsr(1m)";
		    count = 1;
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, count, 0);
		    if (rc) goto fail;
		}

		recno = 0;
		CHECK_FILENO_RECNO ("bsr(1m)", fileno, recno);

		what = "fsr(0)";
		count = 0;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(0) resid";
		if (resid != 0)
			goto fail;

		recno = 0;
		CHECK_FILENO_RECNO ("fsr(0)", fileno, recno);


		what = "fsr(x)";
		count = n_rec / 2;
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSR, count, &resid);
		if (rc) goto fail;

		what = "fsr(x) resid";
		if (resid != 0)
			goto fail;

		recno = n_rec / 2;
		CHECK_FILENO_RECNO ("fsr(x)", fileno, recno);

		what = "fsr(x) read";
		rc = ndmca_tape_read (sess, buf, recsize);
		if (rc) goto fail;

		what = "fsr(x) compare";
		ndmca_test_fill_data (pbuf, recsize, recno, fileno);
		if (bcmp (buf, pbuf, recsize) != 0)
			goto fail;

		recno++;	/* caused by tape_read */

		if (recno > 1) {
			what = "bsr(2)";
			count = 2;
			rc = ndmca_tape_mtio (sess, NDMP9_MTIO_BSR,
						count, &resid);
			if (rc) goto fail;

			what = "bsr(2) resid";
			if (resid != 0)
				goto fail;

			recno -= count;
			CHECK_FILENO_RECNO ("bsr(2)", fileno, recno);

			what = "bsr(2) read";
			rc = ndmca_tape_read (sess, buf, recsize);
			if (rc) goto fail;

			what = "bsr(2) compare";
			ndmca_test_fill_data (pbuf, recsize, recno, fileno);
			if (bcmp (buf, pbuf, recsize) != 0)
				goto fail;
		}

		sprintf (buf, "Passed %s", note);
		ndmca_test_log_step (sess, 2, buf);
	}

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;

  fail:
	sprintf (buf, "Failed %s: %s", what, note);
	ndmca_test_fail (sess, buf);
	return -1;
}
Exemple #5
0
/*
 * Assumes tt_write() passed
 */
int
ndmca_tt_read (struct ndm_session *sess)
{
	int		rc;
	unsigned	n_rec;
	unsigned	recsize;
	unsigned	fileno, recno;
	char *		what;
	char		note[128];
	char		pbuf[64*1024];
	char		buf[64*1024];

	ndmca_test_phase (sess, "T-READ", "Tape Read Series");

	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_READ_MODE);
	if (rc) return rc;

	for (fileno = 0; tt_series[fileno].n_rec > 0; fileno++) {
		n_rec = tt_series[fileno].n_rec;
		recsize = tt_series[fileno].recsize;

		sprintf (note, "Read tape file %d", fileno+1);
		ndmca_test_open (sess, note, 0);

		sprintf (note, "file #%d, %d records, %d bytes/rec",
				fileno+1, n_rec, recsize);
		ndmca_test_log_note (sess, 2, note);

		for (recno = 0; recno < n_rec; recno++) {
			ndmca_test_fill_data (pbuf, recsize, recno, fileno);

			what = "read";
			rc = ndmca_tape_read (sess, buf, recsize);
			if (rc) goto fail;

			CHECK_FILENO_RECNO ("read", fileno, recno+1);

			what = "compare";
#if 0
			if (bcmp (buf, pbuf, recsize) != 0)
				goto fail;
#else
			if (bcmp (buf, pbuf, recsize) != 0) {
				unsigned char *expect_p = (unsigned char *)pbuf;
				unsigned char *got_p = (unsigned char *)buf;
				unsigned int i, f;
				for(f = i = 0;
				    f < 64 && i < recsize;
				    i++, expect_p++, got_p++) {
				    if (*expect_p != *got_p) {
					char tmp[80];
					sprintf (tmp,
						 "%d: 0x%x => 0x%x",
						 i, *expect_p, *got_p);
					ndmalogf (sess, "DATA", 6, tmp);
					f++;
				    }
				}
				goto fail;
			}
#endif
		}

		what = "eof read";
		rc = ndmca_test_tape_read (sess, NDMP9_EOF_ERR, buf, recsize);
		if (rc) goto fail;

		if (sess->plumb.tape->protocol_version > 3) {
		    CHECK_FILENO_RECNO ("eof", fileno, -1);

		    what = "skip filemark";
		    rc = ndmca_tape_mtio (sess, NDMP9_MTIO_FSF, 1, 0);
		    if (rc) goto fail;

		    CHECK_FILENO_RECNO ("skip", fileno+1, 0);
		} else {
		    CHECK_FILENO_RECNO ("eof", fileno+1, 0);
		}

		sprintf (buf, "Passed tape read %s", note);
		ndmca_test_log_step (sess, 2, buf);
	}

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;

  fail:
	sprintf (buf, "Failed %s recno=%d; %s", what, recno, note);
	ndmca_test_fail (sess, buf);
	return -1;
}
Exemple #6
0
/*
 * Precedes tt_read() so that we can make a "known" tape.
 */
int
ndmca_tt_write (struct ndm_session *sess)
{
	int		rc;
	unsigned	n_rec;
	unsigned	recsize;
	unsigned	fileno, recno;
	char *		what;
	char		note[128];
	char		buf[64*1024];

	ndmca_test_phase (sess, "T-WRITE", "Tape Write Series");

	rc = ndmca_test_tape_open(sess,NDMP9_NO_ERR,0,NDMP9_TAPE_RDWR_MODE);
	if (rc) return rc;

	for (fileno = 0; tt_series[fileno].n_rec > 0; fileno++) {
		n_rec = tt_series[fileno].n_rec;
		recsize = tt_series[fileno].recsize;

		sprintf (note, "Write tape file %d", fileno+1);
		ndmca_test_open (sess, note, 0);

		sprintf (note, "file #%d, %d records, %d bytes/rec",
				fileno+1, n_rec, recsize);
		ndmca_test_log_note (sess, 2, note);

		for (recno = 0; recno < n_rec; recno++) {
			ndmca_test_fill_data (buf, recsize, recno, fileno);

			what = "write";
			rc = ndmca_tape_write (sess, buf, recsize);
			if (rc) goto fail;

			CHECK_FILENO_RECNO ("write", fileno, recno+1);
		}

		what = "write filemark";
		rc = ndmca_tape_mtio (sess, NDMP9_MTIO_EOF, 1, 0);
		if (rc) goto fail;

		CHECK_FILENO_RECNO ("wfm", fileno+1, 0);

		/* no test calls so the file operation is the test */
		sprintf (buf, "Passed tape write %s", note);
		ndmca_test_log_step (sess, 2, buf);
	}

	rc = ndmca_test_tape_mtio (sess, NDMP9_NO_ERR, NDMP9_MTIO_REW, 1, 0);
	if (rc) return rc;

	rc = ndmca_test_tape_close (sess, NDMP9_NO_ERR);
	if (rc) return rc;

	return 0;

  fail:
	sprintf (buf, "Failed %s recno=%d; %s", what, recno, note);
	ndmca_test_fail (sess, buf);
	return -1;
}
Exemple #7
0
int ndmca_test_check_expect_errs(struct ndmconn* conn,
                                 int rc,
                                 ndmp9_error expect_errs[])
{
  struct ndm_session* sess = conn->context;
  int protocol_version = conn->protocol_version;
  struct ndmp_xa_buf* xa = &conn->call_xa_buf;
  unsigned msg = xa->request.header.message;
  char* msgname = ndmp_message_to_str(protocol_version, msg);
  ndmp9_error reply_error = conn->last_reply_error;
  int i;

  /* make sure we have a 'test' active */
  ndmca_test_open(sess, msgname, ndmp9_error_to_str(expect_errs[0]));

  if (rc >= 0) {
    /* Call succeeded. Body valid */
    rc = 1;
    for (i = 0; (int)expect_errs[i] >= 0; i++) {
      if (reply_error == expect_errs[i]) {
        rc = 0;
        break;
      }
    }

    if (rc) {
      if (reply_error != NDMP9_NO_ERR && expect_errs[0] != NDMP9_NO_ERR) {
        /* both are errors, don't be picky */
        rc = 2;
      } else {
        /* intolerable mismatch */
      }
    } else {
      /* Worked as expected */
    }
  }

  if (rc != 0) {
    char tmpbuf[128];

    for (i = 0; (int)expect_errs[i] >= 0; i++) {
      ndmalogf(sess, "Test", 1, "%s #%d -- .... %s %s",
               sess->control_acb->test_phase, sess->control_acb->test_step,
               (i == 0) ? "expected" : "or",
               ndmp9_error_to_str(expect_errs[i]));
    }

    snprintf(tmpbuf, sizeof(tmpbuf), "got %s (error expected)",
             ndmp9_error_to_str(reply_error));

    if (rc == 2)
      ndmca_test_warn(sess, tmpbuf);
    else
      ndmca_test_fail(sess, tmpbuf);

    ndma_tattle(conn, xa, rc);

    if (rc == 2) rc = 0;
  }

  return rc;
}
Exemple #8
0
int
ndmca_test_check_data_state  (struct ndm_session *sess,
  ndmp9_data_state expected, int reason)
{
	struct ndm_control_agent *	ca = sess->control_acb;
	ndmp9_data_get_state_reply *	ds = &ca->data_state;
	int				rc;
	char *				what;
	char				errbuf[100];
	char				tmpbuf[256];

	/* close previous test if there is one */
	ndmca_test_close (sess);

	/* open new test */
	ndmca_test_open (sess,
			 "data check",
			 ndmp9_data_state_to_str (expected));

	strcpy (errbuf, "???");

	what = "get_state";
	rc = ndmca_data_get_state (sess);
	if (rc) goto fail;

	what = "state self-consistent";
	/* make sure the sensed state is self consistent */
	switch (ds->state) {
	case NDMP9_DATA_STATE_IDLE:
	case NDMP9_DATA_STATE_ACTIVE:
	case NDMP9_DATA_STATE_LISTEN:
	case NDMP9_DATA_STATE_CONNECTED:
		if (ds->halt_reason != NDMP9_DATA_HALT_NA) {
			strcpy (errbuf, "reason != NA");
			goto fail;
		}
		break;

	case NDMP9_DATA_STATE_HALTED:
		break;

	default:
		strcpy (errbuf, "bogus state");
		goto fail;
	}

	what = "state";
	if (ds->state != expected) {
		sprintf (errbuf, "expected %s got %s",
			ndmp9_data_state_to_str (expected),
			ndmp9_data_state_to_str (ds->state));
		goto fail;
	}

	what = "reason";
	switch (ds->state) {
	case NDMP9_DATA_STATE_HALTED:
		if (ds->halt_reason != (ndmp9_data_halt_reason)reason) {
			sprintf (errbuf, "expected %s got %s",
			    ndmp9_data_halt_reason_to_str (reason),
			    ndmp9_data_halt_reason_to_str (ds->halt_reason));
			goto fail;
		}
		break;

	default:
		break;
	}

	/* test passed */
	ndmca_test_close (sess);

	return 0;

  fail:
	/* test failed */
	sprintf(tmpbuf, "%s: %s", what, errbuf);
	ndmca_test_fail(sess, tmpbuf);

	ndmca_test_close (sess);

	return -1;
}