blob: 60cfb42f9037b2b70a21fd3d88caeaeef4f074de [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 SAHPI_SRF_UNPRESENT 0
21#define THRESHOLDS_TEST_DATA 2
22
23void value_init(SaHpiSensorThresholdsT *thresholds, SaHpiSensorThdDefnT defn)
24{
25 SaHpiSensorThdMaskT read_thold = defn.ReadThold;
26 SaHpiSensorThdMaskT write_thold = defn.WriteThold;
27
28 if (read_thold & SAHPI_STM_LOW_CRIT &&
29 write_thold & SAHPI_STM_LOW_CRIT) {
30 thresholds->LowCritical.ValuesPresent = SAHPI_SRF_UNPRESENT;
31 thresholds->LowCritical.Interpreted.Type =
32 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
33 thresholds->LowCritical.Interpreted.Value.SensorUint32 =
34 THRESHOLDS_TEST_DATA;
35 }
36
37 if (read_thold & SAHPI_STM_LOW_MAJOR &&
38 write_thold & SAHPI_STM_LOW_MAJOR) {
39 thresholds->LowMajor.ValuesPresent = SAHPI_SRF_UNPRESENT;
40 thresholds->LowMajor.Interpreted.Type =
41 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
42 thresholds->LowMajor.Interpreted.Value.SensorUint32 =
43 THRESHOLDS_TEST_DATA;
44 }
45
46 if (read_thold & SAHPI_STM_LOW_MINOR &&
47 write_thold & SAHPI_STM_LOW_MINOR) {
48 thresholds->LowMinor.ValuesPresent = SAHPI_SRF_UNPRESENT;
49 thresholds->LowMinor.Interpreted.Type =
50 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
51 thresholds->LowMinor.Interpreted.Value.SensorUint32 =
52 THRESHOLDS_TEST_DATA;
53 }
54
55 if (read_thold & SAHPI_STM_UP_CRIT &&
56 write_thold & SAHPI_STM_UP_CRIT) {
57 thresholds->UpCritical.ValuesPresent = SAHPI_SRF_UNPRESENT;
58 thresholds->UpCritical.Interpreted.Type =
59 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
60 thresholds->UpCritical.Interpreted.Value.SensorUint32 =
61 THRESHOLDS_TEST_DATA;
62 }
63
64 if (read_thold & SAHPI_STM_UP_MAJOR &&
65 write_thold & SAHPI_STM_UP_MAJOR) {
66 thresholds->UpMajor.ValuesPresent = SAHPI_SRF_UNPRESENT;
67 thresholds->UpMajor.Interpreted.Type =
68 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
69 thresholds->UpMajor.Interpreted.Value.SensorUint32 =
70 THRESHOLDS_TEST_DATA;
71 }
72
73 if (read_thold & SAHPI_STM_UP_MINOR &&
74 write_thold & SAHPI_STM_UP_MINOR) {
75 thresholds->UpMinor.ValuesPresent = SAHPI_SRF_UNPRESENT;
76 thresholds->UpMinor.Interpreted.Type =
77 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
78 thresholds->UpMinor.Interpreted.Value.SensorUint32 =
79 THRESHOLDS_TEST_DATA;
80 }
81
82 if (read_thold & SAHPI_STM_UP_HYSTERESIS &&
83 write_thold & SAHPI_STM_UP_HYSTERESIS) {
84 thresholds->PosThdHysteresis.ValuesPresent =
85 SAHPI_SRF_UNPRESENT;
86 thresholds->PosThdHysteresis.Interpreted.Type =
87 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
88 thresholds->PosThdHysteresis.Interpreted.Value.SensorUint32 =
89 THRESHOLDS_TEST_DATA;
90 }
91
92 if (read_thold & SAHPI_STM_LOW_HYSTERESIS &&
93 write_thold & SAHPI_STM_LOW_HYSTERESIS) {
94 thresholds->NegThdHysteresis.ValuesPresent =
95 SAHPI_SRF_UNPRESENT;
96 thresholds->NegThdHysteresis.Interpreted.Type =
97 SAHPI_SENSOR_INTERPRETED_TYPE_UINT32;
98 thresholds->NegThdHysteresis.Interpreted.Value.SensorUint32 =
99 THRESHOLDS_TEST_DATA;
100 }
101}
102
103int do_sensor(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id, SaHpiRdrT rdr)
104{
105 SaHpiSensorThresholdsT thresholds, thresholds_old, thresholds_new;
106 SaHpiSensorNumT num;
robbiewd9972f62003-07-15 21:03:30 +0000107 SaHpiSensorThdDefnT defn;
robbiewa6d58a12003-07-02 18:43:40 +0000108 SaErrorT val;
109 int ret = HPI_TEST_UNKNOW;
110
111 if (rdr.RdrType == SAHPI_SENSOR_RDR) {
robbiewa6d58a12003-07-02 18:43:40 +0000112 num = rdr.RdrTypeUnion.SensorRec.Num;
robbiewd9972f62003-07-15 21:03:30 +0000113 defn = rdr.RdrTypeUnion.SensorRec.ThresholdDefn;
114
115 if (defn.IsThreshold == SAHPI_FALSE)
116 goto out;
117 if (!defn.ReadThold || !defn.WriteThold)
118 goto out;
119
120 ret = HPI_TEST_PASS;
robbiewa6d58a12003-07-02 18:43:40 +0000121 val = saHpiSensorThresholdsGet(session_id, resource_id, num,
122 &thresholds_old);
123 if (val != SA_OK) {
124 printf(" Does not conform the expected behaviors!\n");
125 printf(" Cannot get the old thresholds!\n");
126 printf(" Return value: %s\n", get_error_string(val));
127 ret = HPI_TEST_FAIL;
128 goto out;
129 }
130
131 memset(&thresholds, 0, sizeof(thresholds));
132 value_init(&thresholds,
133 rdr.RdrTypeUnion.SensorRec.ThresholdDefn);
134 val = saHpiSensorThresholdsSet(session_id, resource_id,
135 num, &thresholds);
136 if (val != SA_OK) {
137 printf(" Does not conform the expected behaviors!\n");
138 printf(" Cannot set the specified thresholds!\n");
139 printf(" Return value: %s\n", get_error_string(val));
140 ret = HPI_TEST_FAIL;
141 goto out;
142 }
143
144 val = saHpiSensorThresholdsGet(session_id, resource_id, num,
145 &thresholds_new);
146 if (val != SA_OK) {
147 printf(" Does not conform the expected behaviors!\n");
148 printf(" Cannot get the new thresholds!\n");
149 printf(" Return value: %s\n", get_error_string(val));
150 ret = HPI_TEST_FAIL;
151 goto out1;
152 }
153
154 if (memcmp(&thresholds_new, &thresholds_old,
155 sizeof(thresholds))) {
156 printf(" Does not conform the expected behaviors!\n");
157 printf(" The new thresholds is invalid!\n");
158 ret = HPI_TEST_FAIL;
159 }
160
161out1:
162 val = saHpiSensorThresholdsSet(session_id, resource_id,
163 num, &thresholds_old);
164 if (val != SA_OK) {
165 printf(" Does not conform the expected behaviors!\n");
166 printf(" Cannot set the old thresholds!\n");
167 printf(" Return value: %s\n", get_error_string(val));
168 ret = HPI_TEST_FAIL;
169 }
170 }
171
172out:
173 return ret;
174}
175
176int main()
177{
178 SaHpiVersionT version;
179 SaErrorT val;
180 int ret = HPI_TEST_PASS;
181
182 val = saHpiInitialize(&version);
183 if (val != SA_OK) {
184 printf(" Function \"saHpiInitialize\" works abnormally!\n");
185 printf(" Cannot initialize HPI!\n");
186 printf(" Return value: %s\n", get_error_string(val));
187 ret = HPI_TEST_FAIL;
188 goto out;
189 }
190
191 ret = process_domain(SAHPI_DEFAULT_DOMAIN_ID, &do_resource, &do_sensor,
192 NULL);
193 if (ret == HPI_TEST_UNKNOW) {
194 printf(" No Sensor in SAHPI_DEFAULT_DOMAIN_ID!\n");
195 ret = HPI_TEST_FAIL;
196 }
197
198 val = saHpiFinalize();
199 if (val != SA_OK) {
200 printf(" Function \"saHpiFinalize\" works abnormally!\n");
201 printf(" Cannot cleanup HPI");
202 printf(" Return value: %s\n", get_error_string(val));
203 ret = HPI_TEST_FAIL;
204 }
205
206out:
207 return ret;
208}