blob: 37bb146531e9c3c406c54e1cc3825004a99ccf10 [file] [log] [blame]
Chris Austen2fb11732015-10-15 00:50:25 -05001
2#include <stdio.h>
3#include <string.h>
4#include <stdint.h>
5
6
7unsigned char g_sensortype [][2] = {
Chris Austen0012e9b2015-10-22 01:37:46 -05008 {0xC3, 0x01},
9 {0x07, 0x02},
10 {0x0F, 0x05},
11 {0x0c, 0x1F},
12 {0xFF ,0xff}
Chris Austen2fb11732015-10-15 00:50:25 -050013};
14
Emily Shaffer391f3302017-04-03 10:27:08 -070015uint8_t find_type_for_sensor_number(uint8_t sensor_number) {
Chris Austen2fb11732015-10-15 00:50:25 -050016
17 int i=0;
Aditya Saripalli5fb14602017-11-09 14:46:27 +053018 uint8_t rc;
Chris Austen2fb11732015-10-15 00:50:25 -050019
Chris Austen2fb11732015-10-15 00:50:25 -050020 while (g_sensortype[i][0] != 0xff) {
21 if (g_sensortype[i][1] == sensor_number) {
22 break;
23 } else {
24 i++;
25 }
Chris Austen2fb11732015-10-15 00:50:25 -050026 }
27
Chris Austen0012e9b2015-10-22 01:37:46 -050028 rc = g_sensortype[i][0];
Chris Austen2fb11732015-10-15 00:50:25 -050029
Chris Austen0012e9b2015-10-22 01:37:46 -050030 if (rc == 0xFF) {
31 rc = 0;
32 }
33 return rc;
Chris Austen2fb11732015-10-15 00:50:25 -050034}
35
Chris Austen0012e9b2015-10-22 01:37:46 -050036char g_results_method[64];
37char g_results_value[64];
38
Chris Austen2fb11732015-10-15 00:50:25 -050039
Chris Austen10ccc0f2015-12-10 18:27:04 -060040int set_sensor_dbus_state_s(unsigned char number, const char *member, const char *value) {
Chris Austen10ccc0f2015-12-10 18:27:04 -060041 strcpy(g_results_method, member);
Chris Austen0012e9b2015-10-22 01:37:46 -050042 strcpy(g_results_value, value);
43
44 return 0;
Chris Austen0130d6e2015-10-15 22:32:36 -050045}
46
Chris Austen10ccc0f2015-12-10 18:27:04 -060047int set_sensor_dbus_state_y(unsigned char number, char const* member, uint8_t value) {
Aditya Saripalli5fb14602017-11-09 14:46:27 +053048
Chris Austen10ccc0f2015-12-10 18:27:04 -060049 char val[2];
Chris Austen2fb11732015-10-15 00:50:25 -050050
Chris Austen2fb11732015-10-15 00:50:25 -050051
Chris Austen10ccc0f2015-12-10 18:27:04 -060052 snprintf(val, 2, "%d", value);
53
54 strcpy(g_results_method, member);
55 strcpy(g_results_value, val);
56
57 return 0;
Chris Austen2fb11732015-10-15 00:50:25 -050058}
59
60
61extern int updateSensorRecordFromSSRAESC(const void *record);
62
63
64
Chris Austen2fb11732015-10-15 00:50:25 -050065// DIMM Present
Chris Austen0012e9b2015-10-22 01:37:46 -050066uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050067
68// DIMM Not present
Chris Austen0012e9b2015-10-22 01:37:46 -050069uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00};
70
71// DIMM Not present
72uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
73
74// Virtual Sensor 5, setting a Value of 0h
75uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00};
76
Aditya Saripalli5fb14602017-11-09 14:46:27 +053077// Virtual Sensor setting a boot count
Chris Austen0012e9b2015-10-22 01:37:46 -050078uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
79
80// Invalid sensor number
81uint8_t testrec_invalidnumber[]= {0x35, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050082
83
Chris Austen0012e9b2015-10-22 01:37:46 -050084int check_results(int rc, const char *method, const char *value) {
Aditya Saripalli5fb14602017-11-09 14:46:27 +053085 if (strcmp(g_results_method, method)) {
86 log<level::ERR>("Method Failed",
87 entry("EXPECT=%s", method),
88 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -050089 return -1;
90 }
91 if (strcmp(g_results_value, value)) {
Aditya Saripalli5fb14602017-11-09 14:46:27 +053092 log<level::ERR>("Value failed",
93 entry("EXPECT=%s", value),
94 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -050095 return -2;
96 }
97
98 return 0;
99}
100
101void testprep(void) {
102 memset(g_results_method, 0, sizeof(g_results_method));
103 memset(g_results_value, 0, sizeof(g_results_value));
104}
105
Chris Austen2fb11732015-10-15 00:50:25 -0500106
107int main() {
108
Chris Austen18641552015-12-10 18:44:07 -0600109 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), "setValue", "FW Progress, Docking station attachment");
110 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", "True");
111 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", "False");
112 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", "False");
113 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", "3");
Chris Austen0012e9b2015-10-22 01:37:46 -0500114 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
Chris Austen2fb11732015-10-15 00:50:25 -0500115
116 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700117}