Пример #1
0
int processCtrlRdr(SaHpiSessionIdT sessionId,
		   SaHpiResourceIdT resourceId,
		   SaHpiRdrT * rdr, SaHpiCtrlRecT * ctrlRec)
{
	SaErrorT status;
	int retval = SAF_TEST_NOTSUPPORT;
	SaHpiCtrlNumT ctrlNum = ctrlRec->Num;
	int maxBytes;
	ControlData controlData;

	maxBytes = getMaxBytes(ctrlRec);
	if (!ctrlRec->WriteOnly && isTextControl(ctrlRec)
	    && canSetControlState(ctrlRec) && maxBytes >= 4) {

		// Save the original mode and state data so that it can be restored.

		status =
		    readControlData(sessionId, resourceId, ctrlRec,
				    &controlData);

		if (status != SA_OK) {
			retval = SAF_TEST_UNRESOLVED;
			e_print(saHpiControlGet, SA_OK, status);
		} else {
			retval = run_test(sessionId, resourceId, ctrlRec);

			// Restore the original mode and state data.
			restoreControlData(sessionId, resourceId, ctrlNum,
					   &controlData);
		}
	}

	return retval;
}
Пример #2
0
bool passesJitHeuristics(Node *root_node) {
    if (!evalFlag()) return true;
    if (root_node->getHeight() >= (int)getMaxJitSize()) { return false; }

    size_t alloc_bytes, alloc_buffers;
    size_t lock_bytes, lock_buffers;

    deviceMemoryInfo(&alloc_bytes, &alloc_buffers, &lock_bytes, &lock_buffers);

    // Check if approaching the memory limit
    if (lock_bytes > getMaxBytes() || lock_buffers > getMaxBuffers()) {
        NodeIterator<jit::Node> it(root_node);
        NodeIterator<jit::Node> end_node;
        size_t bytes = accumulate(it, end_node, size_t(0),
                                  [=](const size_t prev, const Node &n) {
                                      // getBytes returns the size of the data
                                      // Array. Sub arrays will be represented
                                      // by their parent size.
                                      return prev + n.getBytes();
                                  });

        if (2 * bytes > lock_bytes) { return false; }
    }
    return true;
}
Пример #3
0
SaErrorT verifyTextBuffers(SaHpiSessionIdT sessionId,
			   SaHpiResourceIdT resourceId,
			   SaHpiCtrlRecT * ctrlRec,
			   int numBytesFirstLine, SaHpiBoolT * success)
{
	SaErrorT status;
	SaHpiCtrlNumT ctrlNum = ctrlRec->Num;
	int lineNum;
	int maxLines = ctrlRec->TypeUnion.Text.MaxLines;
	SaHpiCtrlStateT ctrlState;
	int maxBytes = getMaxBytes(ctrlRec);

	*success = SAHPI_FALSE;

	// Get the first text buffer line.

	ctrlState.StateUnion.Text.Line = 1;
	status =
	    saHpiControlGet(sessionId, resourceId, ctrlNum, NULL, &ctrlState);
	if (status != SA_OK) {
		e_print(saHpiControlGet, SA_OK, status);
	} else {

		// Verify that the text buffer matches what we expect.

		*success =
		    matchesTextBuffer(&(ctrlState.StateUnion.Text.Text),
				      maxBytes, BYTE_VALUE_2,
				      numBytesFirstLine);
		if (!(*success)) {
			m_print("First line does match expected value!");
		} else {

			// Verify that all of the other lines are empty.

			for (lineNum = 2; lineNum <= maxLines && *success;
			     lineNum++) {
				ctrlState.StateUnion.Text.Line = lineNum;
				status =
				    saHpiControlGet(sessionId, resourceId,
						    ctrlNum, NULL, &ctrlState);
				if (status != SA_OK) {
					e_print(saHpiControlGet, SA_OK, status);
					break;
				} else if (ctrlState.StateUnion.Text.Text.DataLength == maxBytes &&
					       isBlanks(&(ctrlState.StateUnion.Text.Text), 0, maxBytes)) {
					// okay; do nothing
				} else if (ctrlState.StateUnion.Text.Text.DataLength == 0) {
					// okay; do nothing;
				} else {
					m_print("Text line %d is not blank!", lineNum);
					*success = SAHPI_FALSE;
				}
			}
		}
	}

	return status;
}
Пример #4
0
int run_test(SaHpiSessionIdT sessionId,
	     SaHpiResourceIdT resourceId, SaHpiCtrlRecT * ctrlRec)
{
	SaErrorT status;
	int retval = SAF_TEST_PASS;
	int lineNum;
	int maxLines = ctrlRec->TypeUnion.Text.MaxLines;
	SaHpiCtrlNumT ctrlNum = ctrlRec->Num;
	int maxBytes = getMaxBytes(ctrlRec);
	SaHpiCtrlStateT ctrlState;

	for (lineNum = 1; lineNum <= maxLines && retval == SAF_TEST_PASS;
	     lineNum++) {

		// Write the initial "long" string in the first line.

		status =
		    setControlTextBuffer(sessionId, resourceId, ctrlRec,
					 lineNum, 4, BYTE_VALUE_1);
		if (status != SA_OK) {
			e_trace();
			retval = SAF_TEST_UNRESOLVED;
		} else {

			// Write a "shorter" string with a different character.

			status =
			    setControlTextBuffer(sessionId, resourceId, ctrlRec,
						 lineNum, 2, BYTE_VALUE_2);
			if (status != SA_OK) {
				e_trace();
				retval = SAF_TEST_UNRESOLVED;
			} else {

				// Retrieve the latest text buffer and verify that it
				// corresponds to the "shorter" string.

				ctrlState.StateUnion.Text.Line = lineNum;
				status =
				    saHpiControlGet(sessionId, resourceId,
						    ctrlNum, NULL, &ctrlState);
				if (status != SA_OK) {
					retval = SAF_TEST_UNRESOLVED;
					e_print(saHpiControlGet, SA_OK, status);
				} else
				    if (!matchesTextBuffer
					(&(ctrlState.StateUnion.Text.Text),
					 maxBytes, BYTE_VALUE_2, 2)) {
					retval = SAF_TEST_FAIL;
					m_print("Text Buffer does not match!");
				}
			}
		}
	}

	return retval;
}
Пример #5
0
Array<T>
createNodeArray(const dim4 &dims, Node_ptr node)
{
    Array<T> out =  Array<T>(dims, node);

    if (evalFlag()) {
        if (node->getHeight() >= (int)getMaxJitSize()) {
            out.eval();
        } else {
            size_t alloc_bytes, alloc_buffers;
            size_t lock_bytes, lock_buffers;

            deviceMemoryInfo(&alloc_bytes, &alloc_buffers,
                             &lock_bytes, &lock_buffers);

            // Check if approaching the memory limit
            if (lock_bytes > getMaxBytes() ||
                lock_buffers > getMaxBuffers()) {

                Node *n = node.get();

                TNJ::Node_map_t nodes_map;
                vector<TNJ::Node *> full_nodes;
                n->getNodesMap(nodes_map, full_nodes);
                unsigned length =0, buf_count = 0, bytes = 0;
                for(auto &entry : nodes_map) {
                    Node *node = entry.first;
                    node->getInfo(length, buf_count, bytes);
                }

                if (2 * bytes > lock_bytes) {
                    out.eval();
                }
            }
        }
    }

    return out;
}
Пример #6
0
int processCtrlRdr(SaHpiSessionIdT sessionId,
		   SaHpiResourceIdT resourceId,
		   SaHpiRdrT * rdr, SaHpiCtrlRecT * ctrlRec)
{
	SaErrorT status;
	int retval = SAF_TEST_NOTSUPPORT;
	SaHpiCtrlNumT ctrlNum = ctrlRec->Num;
	ControlData controlData;
	int numBytes;
	SaHpiBoolT success;

	if (!ctrlRec->WriteOnly && isTextControl(ctrlRec)
	    && canSetControlState(ctrlRec)) {

		// Read the mode and all of the text buffers for later restoration.

		status =
		    readControlData(sessionId, resourceId, ctrlRec,
				    &controlData);
		if (status != SA_OK) {
			e_trace();
			retval = SAF_TEST_UNRESOLVED;
		} else {

			// Fill up the text buffers so that we know we really have something to clear.

			status =
			    setControlAllTextBuffers(sessionId, resourceId,
						     ctrlRec, BYTE_VALUE_1);
			if (status != SA_OK) {
				e_trace();
				retval = SAF_TEST_UNRESOLVED;
			} else {

				// Clear all of the text buffers and overwrite half of the first line.

				numBytes = getMaxBytes(ctrlRec) / 2;
				status =
				    setControlTextBuffer(sessionId, resourceId,
							 ctrlRec,
							 SAHPI_TLN_ALL_LINES,
							 numBytes,
							 BYTE_VALUE_2);
				if (status != SA_OK) {
					e_trace();
					retval = SAF_TEST_FAIL;
				} else {

					// Verify that the text buffers contain what we expect.

					status =
					    verifyTextBuffers(sessionId,
							      resourceId,
							      ctrlRec, numBytes,
							      &success);
					if (status != SA_OK) {
						retval = SAF_TEST_UNRESOLVED;
					} else if (success) {
						retval = SAF_TEST_PASS;
					} else {
						retval = SAF_TEST_FAIL;
					}
				}
			}

			// Restore the mode and text data.

			restoreControlData(sessionId, resourceId, ctrlNum,
					   &controlData);
		}
	}

	return retval;
}
Пример #7
0
int processCtrlRdr(SaHpiSessionIdT sessionId,
		   SaHpiResourceIdT resourceId,
		   SaHpiRdrT * rdr, SaHpiCtrlRecT * ctrlRec)
{
	SaErrorT status;
	int retval = SAF_TEST_NOTSUPPORT;
	int lineNum;
	int maxLines;
	int maxBytes;
	SaHpiCtrlNumT ctrlNum = ctrlRec->Num;
	SaHpiCtrlModeT ctrlMode;
	SaHpiCtrlStateT ctrlState;
	ControlData controlData;

	if (!ctrlRec->WriteOnly && isTextControl(ctrlRec)
	    && canSetControlState(ctrlRec)) {

		status =
		    readControlData(sessionId, resourceId, ctrlRec,
				    &controlData);
		if (status != SA_OK) {
			e_trace();
			retval = SAF_TEST_UNRESOLVED;
		} else {

			// Change the return value if anything goes wrong.

			retval = SAF_TEST_PASS;

			maxLines = ctrlRec->TypeUnion.Text.MaxLines;
			maxBytes = getMaxBytes(ctrlRec);

			// Initialize the ctrl state information that is the same
			// for each invocation of saHpiControlSet().

			status =
			    setControlAllTextBuffers(sessionId, resourceId,
						     ctrlRec, BYTE_VALUE_1);
			if (status != SA_OK) {
				e_trace();
				retval = SAF_TEST_FAIL;
			} else {

				// If we succesfully change each line of text, then read the
				// text data to verify that the change really did occur.

				for (lineNum = 1; lineNum <= maxLines;
				     lineNum++) {

					ctrlState.StateUnion.Text.Line =
					    lineNum;
					status =
					    saHpiControlGet(sessionId,
							    resourceId, ctrlNum,
							    &ctrlMode,
							    &ctrlState);
					if (status != SA_OK) {
						retval = SAF_TEST_UNRESOLVED;
						e_print(saHpiControlGet, SA_OK,
							status);
						break;
					} else
					    if (!matchesTextBuffer
						(&ctrlState.StateUnion.Text.
						 Text, maxBytes, BYTE_VALUE_1,
						 maxBytes)) {
						retval = SAF_TEST_FAIL;
						m_print
						    ("Text Buffers do not match!");
						break;
					}
				}
			}

			restoreControlData(sessionId, resourceId, ctrlNum,
					   &controlData);
		}
	}

	return retval;
}