blob: 3ba4b98b889ba32663396ea0701fd8531ae16500 [file] [log] [blame]
robbiewa6d58a12003-07-02 18:43:40 +00001/* -*- 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
robbiewd9972f62003-07-15 21:03:30 +000022void set_data(SaHpiSensorReadingT *reading, SaHpiSensorReadingT *reading_old)
robbiewa6d58a12003-07-02 18:43:40 +000023{
robbiewd9972f62003-07-15 21:03:30 +000024 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
62void value_init(SaHpiSensorThresholdsT *thresholds, SaHpiSensorThresholdsT
63 *thresholds_old, SaHpiSensorThdDefnT defn)
64{
65 SaHpiSensorThdMaskT read_thold = defn.ReadThold;
66 SaHpiSensorThdMaskT write_thold = defn.WriteThold;
robbiewa6d58a12003-07-02 18:43:40 +000067
68 if (read_thold & SAHPI_STM_LOW_CRIT &&
robbiewd9972f62003-07-15 21:03:30 +000069 write_thold & SAHPI_STM_LOW_CRIT)
70 set_data(&thresholds->LowCritical,
71 &thresholds_old->LowCritical);
robbiewa6d58a12003-07-02 18:43:40 +000072
73 if (read_thold & SAHPI_STM_LOW_MAJOR &&
robbiewd9972f62003-07-15 21:03:30 +000074 write_thold & SAHPI_STM_LOW_MAJOR)
75 set_data(&thresholds->LowMajor, &thresholds_old->LowMajor);
robbiewa6d58a12003-07-02 18:43:40 +000076
77 if (read_thold & SAHPI_STM_LOW_MINOR &&
robbiewd9972f62003-07-15 21:03:30 +000078 write_thold & SAHPI_STM_LOW_MINOR)
79 set_data(&thresholds->LowMinor, &thresholds_old->LowMinor);
robbiewa6d58a12003-07-02 18:43:40 +000080
81 if (read_thold & SAHPI_STM_UP_CRIT &&
robbiewd9972f62003-07-15 21:03:30 +000082 write_thold & SAHPI_STM_UP_CRIT)
83 set_data(&thresholds->UpCritical, &thresholds_old->UpCritical);
robbiewa6d58a12003-07-02 18:43:40 +000084
85 if (read_thold & SAHPI_STM_UP_MAJOR &&
robbiewd9972f62003-07-15 21:03:30 +000086 write_thold & SAHPI_STM_UP_MAJOR)
87 set_data(&thresholds->UpMajor, &thresholds_old->UpMajor);
robbiewa6d58a12003-07-02 18:43:40 +000088
89 if (read_thold & SAHPI_STM_UP_MINOR &&
robbiewd9972f62003-07-15 21:03:30 +000090 write_thold & SAHPI_STM_UP_MINOR)
91 set_data(&thresholds->UpMinor, &thresholds_old->UpMinor);
robbiewa6d58a12003-07-02 18:43:40 +000092
93 if (read_thold & SAHPI_STM_UP_HYSTERESIS &&
robbiewd9972f62003-07-15 21:03:30 +000094 write_thold & SAHPI_STM_UP_HYSTERESIS)
95 set_data(&thresholds->PosThdHysteresis,
96 &thresholds_old->PosThdHysteresis);
robbiewa6d58a12003-07-02 18:43:40 +000097
98 if (read_thold & SAHPI_STM_LOW_HYSTERESIS &&
robbiewd9972f62003-07-15 21:03:30 +000099 write_thold & SAHPI_STM_LOW_HYSTERESIS)
100 set_data(&thresholds->NegThdHysteresis,
101 &thresholds_old->NegThdHysteresis);
robbiewa6d58a12003-07-02 18:43:40 +0000102}
103
104int 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
185int 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;
robbiewd9972f62003-07-15 21:03:30 +0000196
197 if (defn.IsThreshold == SAHPI_FALSE)
198 goto out;
robbiewa6d58a12003-07-02 18:43:40 +0000199 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));
robbiewd9972f62003-07-15 21:03:30 +0000214 value_init(&thresholds, &thresholds_old, defn);
robbiewa6d58a12003-07-02 18:43:40 +0000215 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
241out1:
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
252out:
253 return ret;
254}
255
256int 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
286out:
287 return ret;
288}