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; }
int ndmca_tape_get_state_no_tattle (struct ndm_session *sess) { struct ndmconn * conn = sess->plumb.tape; struct ndm_control_agent *ca = &sess->control_acb; struct ndmp9_tape_get_state_reply *state = &ca->tape_state; int rc; NDMC_WITH_VOID_REQUEST(ndmp9_tape_get_state, NDMP9VER) rc = ndma_call_no_tattle (conn, xa); if (rc) { NDMOS_MACRO_ZEROFILL (state); /* tape_state.state = -1; */ } else { *state = *reply; } if (rc < 0 || (reply->error != NDMP9_DEV_NOT_OPEN_ERR && reply->error != NDMP9_NO_ERR)) ndma_tattle (sess->plumb.tape, xa, rc); NDMC_ENDWITH return rc; }
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; }