blob: 072b5d7ae4543d3704dea705e24d27e63692359d [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;
Chris Austen0012e9b2015-10-22 01:37:46 -050018 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) {
41 printf("Attempting to log 0x%02x via %s with a value of %s\n",
42 number, member, value);
Chris Austen0130d6e2015-10-15 22:32:36 -050043
Chris Austen10ccc0f2015-12-10 18:27:04 -060044 strcpy(g_results_method, member);
Chris Austen0012e9b2015-10-22 01:37:46 -050045 strcpy(g_results_value, value);
46
47 return 0;
Chris Austen0130d6e2015-10-15 22:32:36 -050048}
49
Chris Austen10ccc0f2015-12-10 18:27:04 -060050int set_sensor_dbus_state_y(unsigned char number, char const* member, uint8_t value) {
51
52 char val[2];
Chris Austen2fb11732015-10-15 00:50:25 -050053
Chris Austen2fb11732015-10-15 00:50:25 -050054
Chris Austen10ccc0f2015-12-10 18:27:04 -060055 printf("Attempting to log Variant Sensor 0x%02x via %s with a value of 0x%02x\n",
56 number, member, value);
Chris Austen0012e9b2015-10-22 01:37:46 -050057
Chris Austen10ccc0f2015-12-10 18:27:04 -060058
59 snprintf(val, 2, "%d", value);
60
61 strcpy(g_results_method, member);
62 strcpy(g_results_value, val);
63
64 return 0;
Chris Austen2fb11732015-10-15 00:50:25 -050065}
66
67
68extern int updateSensorRecordFromSSRAESC(const void *record);
69
70
71
Chris Austen2fb11732015-10-15 00:50:25 -050072// DIMM Present
Chris Austen0012e9b2015-10-22 01:37:46 -050073uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050074
75// DIMM Not present
Chris Austen0012e9b2015-10-22 01:37:46 -050076uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00};
77
78// DIMM Not present
79uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
80
81// Virtual Sensor 5, setting a Value of 0h
82uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00};
83
84// Virtual Sensor setting a boot count
85uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
86
87// Invalid sensor number
88uint8_t testrec_invalidnumber[]= {0x35, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050089
90
Chris Austen0012e9b2015-10-22 01:37:46 -050091int check_results(int rc, const char *method, const char *value) {
92 if (strcmp(g_results_method, method)) {
93 printf("ERROR: Method Failed, expect %s found %s\n", method, g_results_method);
94 return -1;
95 }
96 if (strcmp(g_results_value, value)) {
97 printf("ERROR: Value failed, expected %s found %s\n", value, g_results_value);
98 return -2;
99 }
100
101 return 0;
102}
103
104void testprep(void) {
105 memset(g_results_method, 0, sizeof(g_results_method));
106 memset(g_results_value, 0, sizeof(g_results_value));
107}
108
Chris Austen2fb11732015-10-15 00:50:25 -0500109
110int main() {
111
Chris Austen18641552015-12-10 18:44:07 -0600112 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), "setValue", "FW Progress, Docking station attachment");
113 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", "True");
114 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", "False");
115 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", "False");
116 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", "3");
Chris Austen0012e9b2015-10-22 01:37:46 -0500117 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
Chris Austen2fb11732015-10-15 00:50:25 -0500118
119 return 0;
Emily Shaffer391f3302017-04-03 10:27:08 -0700120}