blob: 0a703ab9ed2be54fd9db54332907c0d30782f810 [file] [log] [blame]
Chris Austen2fb11732015-10-15 00:50:25 -05001
Patrick Venture0b02be92018-08-31 11:55:55 -07002#include <stdint.h>
Chris Austen2fb11732015-10-15 00:50:25 -05003#include <stdio.h>
4#include <string.h>
Chris Austen2fb11732015-10-15 00:50:25 -05005
Patrick Venture0b02be92018-08-31 11:55:55 -07006unsigned char g_sensortype[][2] = {
7 {0xC3, 0x01}, {0x07, 0x02}, {0x0F, 0x05}, {0x0c, 0x1F}, {0xFF, 0xff}};
Chris Austen2fb11732015-10-15 00:50:25 -05008
Patrick Venture0b02be92018-08-31 11:55:55 -07009uint8_t find_type_for_sensor_number(uint8_t sensor_number)
10{
Patrick Venture0b02be92018-08-31 11:55:55 -070011 int i = 0;
Aditya Saripalli5fb14602017-11-09 14:46:27 +053012 uint8_t rc;
Chris Austen2fb11732015-10-15 00:50:25 -050013
Patrick Venture0b02be92018-08-31 11:55:55 -070014 while (g_sensortype[i][0] != 0xff)
15 {
16 if (g_sensortype[i][1] == sensor_number)
17 {
Chris Austen2fb11732015-10-15 00:50:25 -050018 break;
Patrick Venture0b02be92018-08-31 11:55:55 -070019 }
20 else
21 {
Chris Austen2fb11732015-10-15 00:50:25 -050022 i++;
23 }
Chris Austen2fb11732015-10-15 00:50:25 -050024 }
25
Chris Austen0012e9b2015-10-22 01:37:46 -050026 rc = g_sensortype[i][0];
Chris Austen2fb11732015-10-15 00:50:25 -050027
Patrick Venture0b02be92018-08-31 11:55:55 -070028 if (rc == 0xFF)
29 {
Chris Austen0012e9b2015-10-22 01:37:46 -050030 rc = 0;
31 }
32 return rc;
Chris Austen2fb11732015-10-15 00:50:25 -050033}
34
Chris Austen0012e9b2015-10-22 01:37:46 -050035char g_results_method[64];
36char g_results_value[64];
37
Patrick Venture0b02be92018-08-31 11:55:55 -070038int set_sensor_dbus_state_s(unsigned char number, const char* member,
39 const char* value)
40{
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
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050047int set_sensor_dbus_state_y(unsigned char number, const char* member,
Patrick Venture0b02be92018-08-31 11:55:55 -070048 uint8_t value)
49{
Chris Austen10ccc0f2015-12-10 18:27:04 -060050 char val[2];
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
Patrick Venture0b02be92018-08-31 11:55:55 -070060extern int updateSensorRecordFromSSRAESC(const void* record);
Chris Austen2fb11732015-10-15 00:50:25 -050061
Chris Austen2fb11732015-10-15 00:50:25 -050062// DIMM Present
Patrick Venture0b02be92018-08-31 11:55:55 -070063uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00,
64 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050065
66// DIMM Not present
Patrick Venture0b02be92018-08-31 11:55:55 -070067uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00,
68 0x40, 0x00, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050069
70// DIMM Not present
Patrick Venture0b02be92018-08-31 11:55:55 -070071uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00,
72 0x00, 0x01, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050073
74// Virtual Sensor 5, setting a Value of 0h
Patrick Venture0b02be92018-08-31 11:55:55 -070075uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00,
76 0x00, 0x00, 0x00, 0x0E, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050077
Aditya Saripalli5fb14602017-11-09 14:46:27 +053078// Virtual Sensor setting a boot count
Patrick Venture0b02be92018-08-31 11:55:55 -070079uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050081
82// Invalid sensor number
Patrick Venture0b02be92018-08-31 11:55:55 -070083uint8_t testrec_invalidnumber[] = {0x35, 0xa9, 0x00, 0x04, 0x00,
84 0x00, 0x00, 0x00, 0x03, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050085
Patrick Venture0b02be92018-08-31 11:55:55 -070086int check_results(int rc, const char* method, const char* value)
87{
88 if (strcmp(g_results_method, method))
89 {
90 log<level::ERR>("Method Failed", entry("EXPECT=%s", method),
Aditya Saripalli5fb14602017-11-09 14:46:27 +053091 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -050092 return -1;
93 }
Patrick Venture0b02be92018-08-31 11:55:55 -070094 if (strcmp(g_results_value, value))
95 {
96 log<level::ERR>("Value failed", entry("EXPECT=%s", value),
Aditya Saripalli5fb14602017-11-09 14:46:27 +053097 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -050098 return -2;
99 }
100
101 return 0;
102}
103
Patrick Venture0b02be92018-08-31 11:55:55 -0700104void testprep(void)
105{
Chris Austen0012e9b2015-10-22 01:37:46 -0500106 memset(g_results_method, 0, sizeof(g_results_method));
107 memset(g_results_value, 0, sizeof(g_results_value));
108}
109
Patrick Venture0b02be92018-08-31 11:55:55 -0700110int main()
111{
Patrick Venture0b02be92018-08-31 11:55:55 -0700112 testprep();
113 check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress),
114 "setValue", "FW Progress, Docking station attachment");
115 testprep();
116 check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent",
117 "True");
118 testprep();
119 check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent",
120 "False");
121 testprep();
122 check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault",
123 "False");
124 testprep();
125 check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue",
126 "3");
127 testprep();
128 check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
Chris Austen2fb11732015-10-15 00:50:25 -0500129
Patrick Venture0b02be92018-08-31 11:55:55 -0700130 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700131}