robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 1 | /* -*- linux-c -*- |
| 2 | * |
| 3 | * Copyright (c) 2003 by Intel Corp. |
| 4 | * |
| 5 | * This program is distributed in the hope that it will be useful, |
| 6 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This |
| 8 | * file and program are licensed under a BSD style license. See |
| 9 | * the Copying file included with the OpenHPI distribution for |
| 10 | * full licensing terms. |
| 11 | * |
| 12 | * Authors: |
| 13 | * Kevin Gao <kevin.gao@intel.com> |
| 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <string.h> |
| 18 | #include <hpitest.h> |
| 19 | |
| 20 | #define THRESHOLDS_TEST_DATA 2 |
| 21 | |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 22 | void set_data(SaHpiSensorReadingT *reading, SaHpiSensorReadingT *reading_old) |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 23 | { |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 24 | SaHpiSensorInterpretedTypeT type; |
| 25 | |
| 26 | type = reading_old->Interpreted.Type; |
| 27 | reading->ValuesPresent = SAHPI_SRF_INTERPRETED; |
| 28 | reading->Interpreted.Type = type; |
| 29 | |
| 30 | switch(type) { |
| 31 | case SAHPI_SENSOR_INTERPRETED_TYPE_UINT8: |
| 32 | reading->Interpreted.Value.SensorUint8 = THRESHOLDS_TEST_DATA; |
| 33 | break; |
| 34 | case SAHPI_SENSOR_INTERPRETED_TYPE_UINT16: |
| 35 | reading->Interpreted.Value.SensorUint16 = THRESHOLDS_TEST_DATA; |
| 36 | break; |
| 37 | case SAHPI_SENSOR_INTERPRETED_TYPE_UINT32: |
| 38 | reading->Interpreted.Value.SensorUint32 = THRESHOLDS_TEST_DATA; |
| 39 | break; |
| 40 | case SAHPI_SENSOR_INTERPRETED_TYPE_INT8: |
| 41 | reading->Interpreted.Value.SensorInt8 = THRESHOLDS_TEST_DATA; |
| 42 | break; |
| 43 | case SAHPI_SENSOR_INTERPRETED_TYPE_INT16: |
| 44 | reading->Interpreted.Value.SensorInt16 = THRESHOLDS_TEST_DATA; |
| 45 | break; |
| 46 | case SAHPI_SENSOR_INTERPRETED_TYPE_INT32: |
| 47 | reading->Interpreted.Value.SensorInt32 = THRESHOLDS_TEST_DATA; |
| 48 | break; |
| 49 | case SAHPI_SENSOR_INTERPRETED_TYPE_FLOAT32: |
| 50 | reading->Interpreted.Value.SensorFloat32 = THRESHOLDS_TEST_DATA; |
| 51 | break; |
| 52 | case SAHPI_SENSOR_INTERPRETED_TYPE_BUFFER: |
| 53 | memset(reading->Interpreted.Value.SensorBuffer, 0, |
| 54 | sizeof(reading->Interpreted |
| 55 | .Value.SensorBuffer)); |
| 56 | reading->Interpreted.Value.SensorBuffer[0] = |
| 57 | THRESHOLDS_TEST_DATA; |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void value_init(SaHpiSensorThresholdsT *thresholds, SaHpiSensorThresholdsT |
| 63 | *thresholds_old, SaHpiSensorThdDefnT defn) |
| 64 | { |
| 65 | SaHpiSensorThdMaskT read_thold = defn.ReadThold; |
| 66 | SaHpiSensorThdMaskT write_thold = defn.WriteThold; |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 67 | |
| 68 | if (read_thold & SAHPI_STM_LOW_CRIT && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 69 | write_thold & SAHPI_STM_LOW_CRIT) |
| 70 | set_data(&thresholds->LowCritical, |
| 71 | &thresholds_old->LowCritical); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 72 | |
| 73 | if (read_thold & SAHPI_STM_LOW_MAJOR && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 74 | write_thold & SAHPI_STM_LOW_MAJOR) |
| 75 | set_data(&thresholds->LowMajor, &thresholds_old->LowMajor); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 76 | |
| 77 | if (read_thold & SAHPI_STM_LOW_MINOR && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 78 | write_thold & SAHPI_STM_LOW_MINOR) |
| 79 | set_data(&thresholds->LowMinor, &thresholds_old->LowMinor); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 80 | |
| 81 | if (read_thold & SAHPI_STM_UP_CRIT && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 82 | write_thold & SAHPI_STM_UP_CRIT) |
| 83 | set_data(&thresholds->UpCritical, &thresholds_old->UpCritical); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 84 | |
| 85 | if (read_thold & SAHPI_STM_UP_MAJOR && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 86 | write_thold & SAHPI_STM_UP_MAJOR) |
| 87 | set_data(&thresholds->UpMajor, &thresholds_old->UpMajor); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 88 | |
| 89 | if (read_thold & SAHPI_STM_UP_MINOR && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 90 | write_thold & SAHPI_STM_UP_MINOR) |
| 91 | set_data(&thresholds->UpMinor, &thresholds_old->UpMinor); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 92 | |
| 93 | if (read_thold & SAHPI_STM_UP_HYSTERESIS && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 94 | write_thold & SAHPI_STM_UP_HYSTERESIS) |
| 95 | set_data(&thresholds->PosThdHysteresis, |
| 96 | &thresholds_old->PosThdHysteresis); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 97 | |
| 98 | if (read_thold & SAHPI_STM_LOW_HYSTERESIS && |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 99 | write_thold & SAHPI_STM_LOW_HYSTERESIS) |
| 100 | set_data(&thresholds->NegThdHysteresis, |
| 101 | &thresholds_old->NegThdHysteresis); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int thrd_cmp(SaHpiSensorThresholdsT thresholds, SaHpiSensorThresholdsT thresholds_new, SaHpiSensorThdDefnT defn) |
| 105 | { |
| 106 | SaHpiSensorThdMaskT read_thold = defn.ReadThold; |
| 107 | SaHpiSensorThdMaskT write_thold = defn.WriteThold; |
| 108 | |
| 109 | if (read_thold & SAHPI_STM_LOW_CRIT && |
| 110 | write_thold & SAHPI_STM_LOW_CRIT) { |
| 111 | if (memcmp(&thresholds.LowCritical, &thresholds_new.LowCritical, |
| 112 | sizeof(thresholds.LowCritical))) |
| 113 | return -1; |
| 114 | else |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | if (read_thold & SAHPI_STM_LOW_MAJOR && |
| 119 | write_thold & SAHPI_STM_LOW_MAJOR) { |
| 120 | if (memcmp(&thresholds.LowMajor, &thresholds_new.LowMajor, |
| 121 | sizeof(thresholds.LowMajor))) |
| 122 | return -1; |
| 123 | else |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | if (read_thold & SAHPI_STM_LOW_MINOR && |
| 128 | write_thold & SAHPI_STM_LOW_MINOR) { |
| 129 | if (memcmp(&thresholds.LowMinor, &thresholds_new.LowMinor, |
| 130 | sizeof(thresholds.LowMinor))) |
| 131 | return -1; |
| 132 | else |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | if (read_thold & SAHPI_STM_UP_CRIT && |
| 137 | write_thold & SAHPI_STM_UP_CRIT) { |
| 138 | if (memcmp(&thresholds.UpCritical, &thresholds_new.UpCritical, |
| 139 | sizeof(thresholds.UpCritical))) |
| 140 | return -1; |
| 141 | else |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | if (read_thold & SAHPI_STM_UP_MAJOR && |
| 146 | write_thold & SAHPI_STM_UP_MAJOR) { |
| 147 | if (memcmp(&thresholds.UpMajor, &thresholds_new.UpMajor, |
| 148 | sizeof(thresholds.UpMajor))) |
| 149 | return -1; |
| 150 | else |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | if (read_thold & SAHPI_STM_UP_MINOR && |
| 155 | write_thold & SAHPI_STM_UP_MINOR) { |
| 156 | if (memcmp(&thresholds.UpMinor, &thresholds_new.UpMinor, |
| 157 | sizeof(thresholds.UpMinor))) |
| 158 | return -1; |
| 159 | else |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | if (read_thold & SAHPI_STM_UP_HYSTERESIS && |
| 164 | write_thold & SAHPI_STM_UP_HYSTERESIS) { |
| 165 | if (memcmp(&thresholds.PosThdHysteresis, |
| 166 | &thresholds_new.PosThdHysteresis, |
| 167 | sizeof(thresholds.PosThdHysteresis))) |
| 168 | return -1; |
| 169 | else |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | if (read_thold & SAHPI_STM_LOW_HYSTERESIS && |
| 174 | write_thold & SAHPI_STM_LOW_HYSTERESIS) { |
| 175 | if (memcmp(&thresholds.NegThdHysteresis, |
| 176 | &thresholds_new.NegThdHysteresis, |
| 177 | sizeof(thresholds.NegThdHysteresis))) |
| 178 | return -1; |
| 179 | else |
| 180 | return 0; |
| 181 | } |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | int do_sensor(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id, SaHpiRdrT rdr) |
| 186 | { |
| 187 | SaHpiSensorThresholdsT thresholds, thresholds_old, thresholds_new; |
| 188 | SaHpiSensorThdDefnT defn; |
| 189 | SaHpiSensorNumT num; |
| 190 | SaErrorT val; |
| 191 | int ret = HPI_TEST_UNKNOW; |
| 192 | |
| 193 | if (rdr.RdrType == SAHPI_SENSOR_RDR) { |
| 194 | num = rdr.RdrTypeUnion.SensorRec.Num; |
| 195 | defn = rdr.RdrTypeUnion.SensorRec.ThresholdDefn; |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 196 | |
| 197 | if (defn.IsThreshold == SAHPI_FALSE) |
| 198 | goto out; |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 199 | if (!defn.ReadThold || !defn.WriteThold) |
| 200 | goto out; |
| 201 | |
| 202 | ret = HPI_TEST_PASS; |
| 203 | val = saHpiSensorThresholdsGet(session_id, resource_id, |
| 204 | num, &thresholds_old); |
| 205 | if (val != SA_OK) { |
| 206 | printf(" Does not conform the expected behaviors!\n"); |
| 207 | printf(" Cannot get the old thresholds!\n"); |
| 208 | printf(" Return value: %s\n", get_error_string(val)); |
| 209 | ret = HPI_TEST_FAIL; |
| 210 | goto out; |
| 211 | } |
| 212 | |
| 213 | memset(&thresholds, 0, sizeof(thresholds)); |
robbiew | d9972f6 | 2003-07-15 21:03:30 +0000 | [diff] [blame^] | 214 | value_init(&thresholds, &thresholds_old, defn); |
robbiew | a6d58a1 | 2003-07-02 18:43:40 +0000 | [diff] [blame] | 215 | val = saHpiSensorThresholdsSet(session_id, resource_id, |
| 216 | num, &thresholds); |
| 217 | if (val != SA_OK) { |
| 218 | printf(" Does not conform the expected behaviors!\n"); |
| 219 | printf(" Cannot set the specified thresholds!\n"); |
| 220 | printf(" Return value: %s\n", get_error_string(val)); |
| 221 | ret = HPI_TEST_FAIL; |
| 222 | goto out; |
| 223 | } |
| 224 | |
| 225 | val = saHpiSensorThresholdsGet(session_id, resource_id, |
| 226 | num, &thresholds_new); |
| 227 | if (val != SA_OK) { |
| 228 | printf(" Does not conform the expected behaviors!\n"); |
| 229 | printf(" Cannot get the new thresholds!\n"); |
| 230 | printf(" Return value: %s\n", get_error_string(val)); |
| 231 | ret = HPI_TEST_FAIL; |
| 232 | goto out1; |
| 233 | } |
| 234 | |
| 235 | if (thrd_cmp(thresholds, thresholds_new, defn)) { |
| 236 | printf(" Does not conform the expected behaviors!\n"); |
| 237 | printf(" The new thresholds is invalid!\n"); |
| 238 | ret = HPI_TEST_FAIL; |
| 239 | } |
| 240 | |
| 241 | out1: |
| 242 | val = saHpiSensorThresholdsSet(session_id, resource_id, |
| 243 | num, &thresholds_old); |
| 244 | if (val != SA_OK) { |
| 245 | printf(" Does not conform the expected behaviors!\n"); |
| 246 | printf(" Cannot set the old thresholds!\n"); |
| 247 | printf(" Return value: %s\n", get_error_string(val)); |
| 248 | ret = HPI_TEST_FAIL; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | out: |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | int main() |
| 257 | { |
| 258 | SaHpiVersionT version; |
| 259 | SaErrorT val; |
| 260 | int ret = HPI_TEST_PASS; |
| 261 | |
| 262 | val = saHpiInitialize(&version); |
| 263 | if (val != SA_OK) { |
| 264 | printf(" Function \"saHpiInitialize\" works abnormally!\n"); |
| 265 | printf(" Cannot initialize HPI!\n"); |
| 266 | printf(" Return value: %s\n", get_error_string(val)); |
| 267 | ret = HPI_TEST_FAIL; |
| 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | ret = process_domain(SAHPI_DEFAULT_DOMAIN_ID, &do_resource, &do_sensor, |
| 272 | NULL); |
| 273 | if (ret == HPI_TEST_UNKNOW) { |
| 274 | printf(" No Sensor in SAHPI_DEFAULT_DOMAIN_ID!\n"); |
| 275 | ret = HPI_TEST_FAIL; |
| 276 | } |
| 277 | |
| 278 | val = saHpiFinalize(); |
| 279 | if (val != SA_OK) { |
| 280 | printf(" Function \"saHpiFinalize\" works abnormally!\n"); |
| 281 | printf(" Cannot cleanup HPI"); |
| 282 | printf(" Return value: %s\n", get_error_string(val)); |
| 283 | ret = HPI_TEST_FAIL; |
| 284 | } |
| 285 | |
| 286 | out: |
| 287 | return ret; |
| 288 | } |