void reset_event_masks(SaHpiSessionIdT sessionId, SaHpiResourceIdT resourceId, SaHpiSensorNumT s_num, SaHpiEventStateT mask, SaHpiEventStateT assertMask, SaHpiEventStateT deassertMask) { SaErrorT status; // clear all of the bits status = saHpiSensorEventMasksSet(sessionId, resourceId, s_num, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, mask, mask); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); } else { status = saHpiSensorEventMasksSet(sessionId, resourceId, s_num, SAHPI_SENS_ADD_EVENTS_TO_MASKS, assertMask, deassertMask); if (status != SA_OK) { e_print(saHpiSensorEventMasksGet, SA_OK, status); } } }
void restoreSensors(SaHpiSessionIdT sessionId) { int i; SaErrorT status; for (i = 0; i < sensorCount; i++) { status = saHpiSensorThresholdsSet(sessionId, sensorData[i].resourceId, sensorData[i].sensorNum, &sensorData[i].thresholds); if (status != SA_OK) { e_print(saHpiSensorThresholdsSet, SA_OK, status); } if (sensorData[i].restoreMasks) { // restore event masks if (!(sensorData[i].assertEventMask & SAHPI_ES_UPPER_MINOR)) { status = saHpiSensorEventMasksSet(sessionId, sensorData[i].resourceId, sensorData[i].sensorNum, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, SAHPI_ES_UPPER_MINOR, 0x0); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); } } if (!(sensorData[i].deassertEventMask & SAHPI_ES_UPPER_MINOR)) { status = saHpiSensorEventMasksSet(sessionId, sensorData[i].resourceId, sensorData[i].sensorNum, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, 0x0, SAHPI_ES_UPPER_MINOR); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); } } } if (sensorData[i].origEventEnable == SAHPI_FALSE) { // restore EventEnabled state status = saHpiSensorEventEnableSet(sessionId, sensorData[i].resourceId, sensorData[i].sensorNum, SAHPI_FALSE); if (status != SA_OK) { e_print(saHpiSensorEventEnableSet, SA_OK, status); } } } }
int Test_Rdr(SaHpiSessionIdT session, SaHpiResourceIdT resourceId, SaHpiRdrT rdr) { SaErrorT status; int retval = SAF_TEST_NOTSUPPORT; SaHpiSensorNumT s_num = 0; SaHpiEventStateT AssertEventMask = 0x0000; SaHpiEventStateT DeassertEventMask = 0x0000; if (rdr.RdrType == SAHPI_SENSOR_RDR) { s_num = rdr.RdrTypeUnion.SensorRec.Num; // // Call saHpiSensorEventMasksSet passing in a bad ResourceId // status = saHpiSensorEventMasksSet(session, INVALID_RESOURCE_ID, s_num, SAHPI_SENS_ADD_EVENTS_TO_MASKS, AssertEventMask, DeassertEventMask); if (status != SA_ERR_HPI_INVALID_RESOURCE) { e_print(saHpiSensorEventMasksSet, SA_ERR_HPI_INVALID_RESOURCE, status); retval = SAF_TEST_FAIL; } else retval = SAF_TEST_PASS; } return (retval); }
int change_event_masks(SaHpiSessionIdT sessionId, SaHpiResourceIdT resourceId, SaHpiSensorNumT sensorNum, SaHpiSensorEventMaskActionT action) { SaErrorT status; int retval = SAF_TEST_PASS; status = saHpiSensorEventMasksSet(sessionId, resourceId, sensorNum, action, SAHPI_ALL_EVENT_STATES, SAHPI_ALL_EVENT_STATES); if (status != SA_OK) { retval = SAF_TEST_UNRESOLVED; e_print(saHpiSensorEventMasksSet, SA_OK, status); } return retval; }
int main(int argc, char **argv) { int number_resources=0, val; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiResourceIdT resourceid; SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0}; SaHpiSensorNumT sensor_num; SaHpiSensorDataFormatT format; SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_SENSOR; SaHpiEventStateT assert; SaHpiEventStateT deassert; SaHpiSensorEventMaskActionT action; int choice=0; unsigned int choice1=0; memset(&format, 0, sizeof(format)); printf("saHpiSensorReadingGet: Test for hpi sensor reading " "get function\n"); rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL); if (rv != SA_OK) { printf("saHpiSessionOpen failed with error: %s\n", oh_lookup_error(rv)); return rv; } /* Discover the resources with sensor capability */ printf("\nListing the resource with sensor capability \n"); rv = discover_resources(sessionid, capability, resourceid_list, &number_resources); if (rv != SA_OK) { exit(-1); } printf("\nPlease enter the resource id: "); scanf("%d", &resourceid); printf("Press 1 for TEMPERATURE sensor\n"); printf("Press 2 for POWER sensor\n"); printf("Press 3 for FAN SPEED sensor\n"); printf("Enter your choice: "); scanf("%d", &sensor_num); switch (sensor_num) { case 1: sensor_num = OA_SOAP_RES_SEN_TEMP_NUM; format.BaseUnits = SAHPI_SU_DEGREES_C; break; case 2: sensor_num = OA_SOAP_RES_SEN_POWER_NUM; format.BaseUnits = SAHPI_SU_WATTS; break; case 3: sensor_num = OA_SOAP_RES_SEN_FAN_NUM; format.BaseUnits = SAHPI_SU_RPM; break; default : printf("Wrong choice. Exiting"); exit (-1); } format.ReadingType = SAHPI_SENSOR_READING_TYPE_FLOAT64; printf("Enter the masks for deassert mask: "); scanf("%d", &choice); deassert=(SaHpiEventStateT)choice; printf("Enter the masks for assert mask: "); scanf("%x",&choice1); assert=(SaHpiEventStateT)choice1; printf("Please specify the action whether you want to " "add/remove the bits from mask\n"); printf("1 for adding\n2 for removing\n"); printf("Enter your choice: "); scanf("%d", &val); if (val == 1) { action = SAHPI_SENS_ADD_EVENTS_TO_MASKS; } else if (val == 2) { action = SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS; } else { printf("Invalid selection\ntaking add option as default\n"); action = SAHPI_SENS_ADD_EVENTS_TO_MASKS; } rv = saHpiSensorEventMasksSet(sessionid, resourceid, sensor_num, action, assert, deassert); if (rv != SA_OK) { printf("saHpiSensorEventEnableGet failed with error: %s\n", oh_lookup_error(rv)); printf("Test case - FAIL\n"); exit(-1); } printf("\nTest case - PASS\n"); rv = saHpiSessionClose(sessionid); return 0; }
int main(int argc, char **argv) { /* ************************ * Local variables * ***********************/ int testfail = 0; SaErrorT err; SaErrorT expected_err; SaHpiRptEntryT rptentry; SaHpiRdrT rdr; SaHpiResourceIdT id; SaHpiSessionIdT sessionid; SaHpiSensorNumT sid = 0; SaHpiSensorEventMaskActionT act = SAHPI_SENS_ADD_EVENTS_TO_MASKS; SaHpiEventStateT assertMask = SAHPI_ES_UPPER_MINOR; SaHpiEventStateT deassertMask = SAHPI_ES_UPPER_CRIT; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiBoolT foundSensor; /* ************************************* * Find a resource with Sensor type rdr * ************************************* */ err = tsetup(&sessionid); if (err != SA_OK) { printf("Error! Can not open session for test environment\n"); printf(" File=%s, Line=%d\n", __FILE__, __LINE__); return -1; } err = tfind_resource(&sessionid,SAHPI_CAPABILITY_SENSOR,SAHPI_FIRST_ENTRY, &rptentry, SAHPI_TRUE); if (err != SA_OK) { printf("Error! Can not find resources for test environment\n"); printf(" File=%s, Line=%d\n", __FILE__, __LINE__); err = tcleanup(&sessionid); return SA_OK; } id = rptentry.ResourceId; /************************** * Test: find a sensor with desired property **************************/ entryid = SAHPI_FIRST_ENTRY; foundSensor = SAHPI_FALSE; do { err = saHpiRdrGet(sessionid,id,entryid,&nextentryid, &rdr); if (err == SA_OK) { if ((rdr.RdrType == SAHPI_SENSOR_RDR) && (rdr.RdrTypeUnion.SensorRec.EventCtrl != SAHPI_SEC_PER_EVENT)) { foundSensor = SAHPI_TRUE; break; } entryid = nextentryid; } } while ((err == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) ; if (!foundSensor) { dbg("Did not find desired resource for test\n"); return(SA_OK); } else { sid = rdr.RdrTypeUnion.SensorRec.Num; } /************************** * Test: Sensor with !SAHPI_SEC_PER_EVENT **************************/ expected_err = SA_ERR_HPI_READ_ONLY; err = saHpiSensorEventMasksSet(sessionid, id, sid, act, assertMask, deassertMask); checkstatus(err, expected_err, testfail); /*************************** * Cleanup after all tests ***************************/ err = tcleanup(&sessionid); return testfail; }
int Test_Case_Rdr(SaHpiSessionIdT session, SaHpiResourceIdT resourceId, SaHpiRdrT rdr) { int ret = SAF_TEST_UNKNOWN; SaErrorT status; SaHpiSensorNumT sensorNum; SaHpiEventStateT assertMaskOld, assertMaskNew; SaHpiEventStateT deassertMaskOld, deassertMaskNew; SaHpiEventStateT assertSaved, deassertSaved; // -------- Restore the default values -------- status = saHpiParmControl(session, resourceId, SAHPI_DEFAULT_PARM); if (status != SA_OK) // The function works abnormally { e_print(saHpiParmControl, SA_OK, status); ret = SAF_TEST_FAIL; return ret; } if (rdr.RdrType == SAHPI_SENSOR_RDR) { if (rdr.RdrTypeUnion.SensorRec.EventCtrl != SAHPI_SEC_PER_EVENT) { ret = SAF_TEST_NOTSUPPORT; return ret; } sensorNum = rdr.RdrTypeUnion.SensorRec.Num; // ------ Get the state of the sensor ------ status = saHpiSensorEventMasksGet(session, resourceId, sensorNum, &assertMaskOld, &deassertMaskOld); if (status != SA_OK) { e_print(saHpiSensorEventMasksGet, SA_OK, status); ret = SAF_TEST_UNRESOLVED; return ret; } assertSaved = assertMaskOld + 5; deassertSaved = deassertMaskOld + 5; status = saHpiSensorEventMasksSet(session, resourceId, sensorNum, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, assertSaved, deassertSaved); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); ret = SAF_TEST_UNRESOLVED; return ret; } // ------- Call saHpiParmControl with valid parameters ------- status = saHpiParmControl(session, resourceId, SAHPI_DEFAULT_PARM); if (status != SA_OK) { e_print(saHpiParmControl, SA_OK, status); ret = SAF_TEST_FAIL; return ret; } // ------ Get the state of the sensor ------ status = saHpiSensorEventMasksGet(session, resourceId, sensorNum, &assertMaskNew, &deassertMaskNew); if (status != SA_OK) { e_print(saHpiSensorEventMasksGet, SA_OK, status); ret = SAF_TEST_UNRESOLVED; return ret; } // -------- Compare the old values with the new values -------- if ((assertMaskOld != assertMaskNew) || (deassertMaskOld != deassertMaskNew)) ret = SAF_TEST_FAIL; else ret = SAF_TEST_PASS; } else { ret = SAF_TEST_NOTSUPPORT; } return ret; }
int run_test(SaHpiSessionIdT sessionId, SaHpiResourceIdT resourceId, SaHpiSensorRecT * sensorRec) { SaErrorT status; int retval; SaHpiEventStateT assertEventMask; SaHpiEventStateT deassertEventMask; status = saHpiSensorEventMasksGet(sessionId, resourceId, sensorRec->Num, &assertEventMask, &deassertEventMask); if (status == SA_ERR_HPI_ENTITY_NOT_PRESENT) { retval = SAF_TEST_NOTSUPPORT; } else if (status != SA_OK) { retval = SAF_TEST_UNRESOLVED; e_print(saHpiSensorEnableGet, SA_OK, status); } else if (assertEventMask & SAHPI_ES_UPPER_MINOR && deassertEventMask & SAHPI_ES_UPPER_MINOR) { retval = generateAssertEvents(sessionId, resourceId, sensorRec); } else if (sensorRec->EventCtrl == SAHPI_SEC_PER_EVENT) { status = saHpiSensorEventMasksSet(sessionId, resourceId, sensorRec->Num, SAHPI_SENS_ADD_EVENTS_TO_MASKS, SAHPI_ES_UPPER_MINOR, SAHPI_ES_UPPER_MINOR); if (status != SA_OK) { retval = SAF_TEST_UNRESOLVED; e_print(saHpiSensorEventMasksSet, SA_OK, status); } else { retval = generateAssertEvents(sessionId, resourceId, sensorRec); if (retval == SAF_TEST_PASS) { sensorData[sensorCount-1].restoreMasks = SAHPI_TRUE; sensorData[sensorCount-1].assertEventMask = assertEventMask; sensorData[sensorCount-1].deassertEventMask = deassertEventMask; } else { // restore event masks if (!(assertEventMask & SAHPI_ES_UPPER_MINOR)) { status = saHpiSensorEventMasksSet(sessionId, resourceId, sensorRec->Num, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, SAHPI_ES_UPPER_MINOR, 0x0); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); } } if (!(deassertEventMask & SAHPI_ES_UPPER_MINOR)) { status = saHpiSensorEventMasksSet(sessionId, resourceId, sensorRec->Num, SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS, 0x0, SAHPI_ES_UPPER_MINOR); if (status != SA_OK) { e_print(saHpiSensorEventMasksSet, SA_OK, status); } } } } } else { retval = SAF_TEST_NOTSUPPORT; } return retval; }