blob: bfd9334ad7d37309683b4bda77c8dfd63f7c0f55 [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
Chris Austen0012e9b2015-10-22 01:37:46 -050015uint8_t find_sensor(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 Austen0130d6e2015-10-15 22:32:36 -050040int set_sensor_dbus_state_v(uint8_t number, const char *method, char *value) {
Chris Austen0012e9b2015-10-22 01:37:46 -050041 printf("Attempting to log Variant Sensor 0x%02x via %s with a value of %s\n",
Chris Austen0130d6e2015-10-15 22:32:36 -050042 number, method, value);
43
Chris Austen0012e9b2015-10-22 01:37:46 -050044 strcpy(g_results_method, method);
45 strcpy(g_results_value, value);
46
47 return 0;
Chris Austen0130d6e2015-10-15 22:32:36 -050048}
49
Chris Austen2fb11732015-10-15 00:50:25 -050050int set_sensor_dbus_state(uint8_t number, const char *method, const char *value) {
51
Chris Austen0012e9b2015-10-22 01:37:46 -050052 printf("Attempting to log Sensor 0x%02x via %s with a value of %s\n",
Chris Austen2fb11732015-10-15 00:50:25 -050053 number, method, value);
54
Chris Austen0012e9b2015-10-22 01:37:46 -050055 strcpy(g_results_method, method);
56 strcpy(g_results_value, value);
57
Chris Austen2fb11732015-10-15 00:50:25 -050058 return 0;
59}
60
61
62extern int updateSensorRecordFromSSRAESC(const void *record);
63
64
65
Chris Austen2fb11732015-10-15 00:50:25 -050066// DIMM Present
Chris Austen0012e9b2015-10-22 01:37:46 -050067uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050068
69// DIMM Not present
Chris Austen0012e9b2015-10-22 01:37:46 -050070uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00};
71
72// DIMM Not present
73uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
74
75// Virtual Sensor 5, setting a Value of 0h
76uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00};
77
78// Virtual Sensor setting a boot count
79uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
80
81// Invalid sensor number
82uint8_t testrec_invalidnumber[]= {0x35, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00};
Chris Austen2fb11732015-10-15 00:50:25 -050083
84
Chris Austen0012e9b2015-10-22 01:37:46 -050085int check_results(int rc, const char *method, const char *value) {
86 if (strcmp(g_results_method, method)) {
87 printf("ERROR: Method Failed, expect %s found %s\n", method, g_results_method);
88 return -1;
89 }
90 if (strcmp(g_results_value, value)) {
91 printf("ERROR: Value failed, expected %s found %s\n", value, g_results_value);
92 return -2;
93 }
94
95 return 0;
96}
97
98void testprep(void) {
99 memset(g_results_method, 0, sizeof(g_results_method));
100 memset(g_results_value, 0, sizeof(g_results_value));
101}
102
Chris Austen2fb11732015-10-15 00:50:25 -0500103
104int main() {
105
Chris Austen0012e9b2015-10-22 01:37:46 -0500106 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), "setValue", "FW Progress, Docking station attachment");
107 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", "True");
108 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", "False");
109 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", "False");
110 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", "3");
111 testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", "");
Chris Austen2fb11732015-10-15 00:50:25 -0500112
113 return 0;
114}