blob: 2541915e026ce5d1585e1b57af5347bd5876d008 [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{
Chris Austen2fb11732015-10-15 00:50:25 -050011
Patrick Venture0b02be92018-08-31 11:55:55 -070012 int i = 0;
Aditya Saripalli5fb14602017-11-09 14:46:27 +053013 uint8_t rc;
Chris Austen2fb11732015-10-15 00:50:25 -050014
Patrick Venture0b02be92018-08-31 11:55:55 -070015 while (g_sensortype[i][0] != 0xff)
16 {
17 if (g_sensortype[i][1] == sensor_number)
18 {
Chris Austen2fb11732015-10-15 00:50:25 -050019 break;
Patrick Venture0b02be92018-08-31 11:55:55 -070020 }
21 else
22 {
Chris Austen2fb11732015-10-15 00:50:25 -050023 i++;
24 }
Chris Austen2fb11732015-10-15 00:50:25 -050025 }
26
Chris Austen0012e9b2015-10-22 01:37:46 -050027 rc = g_sensortype[i][0];
Chris Austen2fb11732015-10-15 00:50:25 -050028
Patrick Venture0b02be92018-08-31 11:55:55 -070029 if (rc == 0xFF)
30 {
Chris Austen0012e9b2015-10-22 01:37:46 -050031 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
Patrick Venture0b02be92018-08-31 11:55:55 -070039int set_sensor_dbus_state_s(unsigned char number, const char* member,
40 const char* value)
41{
Chris Austen10ccc0f2015-12-10 18:27:04 -060042 strcpy(g_results_method, member);
Chris Austen0012e9b2015-10-22 01:37:46 -050043 strcpy(g_results_value, value);
44
45 return 0;
Chris Austen0130d6e2015-10-15 22:32:36 -050046}
47
Patrick Venture0b02be92018-08-31 11:55:55 -070048int set_sensor_dbus_state_y(unsigned char number, char const* member,
49 uint8_t value)
50{
Aditya Saripalli5fb14602017-11-09 14:46:27 +053051
Chris Austen10ccc0f2015-12-10 18:27:04 -060052 char val[2];
Chris Austen2fb11732015-10-15 00:50:25 -050053
Chris Austen10ccc0f2015-12-10 18:27:04 -060054 snprintf(val, 2, "%d", value);
55
56 strcpy(g_results_method, member);
57 strcpy(g_results_value, val);
58
59 return 0;
Chris Austen2fb11732015-10-15 00:50:25 -050060}
61
Patrick Venture0b02be92018-08-31 11:55:55 -070062extern int updateSensorRecordFromSSRAESC(const void* record);
Chris Austen2fb11732015-10-15 00:50:25 -050063
Chris Austen2fb11732015-10-15 00:50:25 -050064// DIMM Present
Patrick Venture0b02be92018-08-31 11:55:55 -070065uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050067
68// DIMM Not present
Patrick Venture0b02be92018-08-31 11:55:55 -070069uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00,
70 0x40, 0x00, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050071
72// DIMM Not present
Patrick Venture0b02be92018-08-31 11:55:55 -070073uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00,
74 0x00, 0x01, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050075
76// Virtual Sensor 5, setting a Value of 0h
Patrick Venture0b02be92018-08-31 11:55:55 -070077uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00,
78 0x00, 0x00, 0x00, 0x0E, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050079
Aditya Saripalli5fb14602017-11-09 14:46:27 +053080// Virtual Sensor setting a boot count
Patrick Venture0b02be92018-08-31 11:55:55 -070081uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen0012e9b2015-10-22 01:37:46 -050083
84// Invalid sensor number
Patrick Venture0b02be92018-08-31 11:55:55 -070085uint8_t testrec_invalidnumber[] = {0x35, 0xa9, 0x00, 0x04, 0x00,
86 0x00, 0x00, 0x00, 0x03, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050087
Patrick Venture0b02be92018-08-31 11:55:55 -070088int check_results(int rc, const char* method, const char* value)
89{
90 if (strcmp(g_results_method, method))
91 {
92 log<level::ERR>("Method Failed", entry("EXPECT=%s", method),
Aditya Saripalli5fb14602017-11-09 14:46:27 +053093 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -050094 return -1;
95 }
Patrick Venture0b02be92018-08-31 11:55:55 -070096 if (strcmp(g_results_value, value))
97 {
98 log<level::ERR>("Value failed", entry("EXPECT=%s", value),
Aditya Saripalli5fb14602017-11-09 14:46:27 +053099 entry("GOT=%s", g_results_method));
Chris Austen0012e9b2015-10-22 01:37:46 -0500100 return -2;
101 }
102
103 return 0;
104}
105
Patrick Venture0b02be92018-08-31 11:55:55 -0700106void testprep(void)
107{
Chris Austen0012e9b2015-10-22 01:37:46 -0500108 memset(g_results_method, 0, sizeof(g_results_method));
109 memset(g_results_value, 0, sizeof(g_results_value));
110}
111
Patrick Venture0b02be92018-08-31 11:55:55 -0700112int main()
113{
Chris Austen2fb11732015-10-15 00:50:25 -0500114
Patrick Venture0b02be92018-08-31 11:55:55 -0700115 testprep();
116 check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress),
117 "setValue", "FW Progress, Docking station attachment");
118 testprep();
119 check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent",
120 "True");
121 testprep();
122 check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent",
123 "False");
124 testprep();
125 check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault",
126 "False");
127 testprep();
128 check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue",
129 "3");
130 testprep();
131 check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
Chris Austen2fb11732015-10-15 00:50:25 -0500132
Patrick Venture0b02be92018-08-31 11:55:55 -0700133 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700134}