Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | |
| 7 | unsigned char g_sensortype [][2] = { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 8 | {0xC3, 0x01}, |
| 9 | {0x07, 0x02}, |
| 10 | {0x0F, 0x05}, |
| 11 | {0x0c, 0x1F}, |
| 12 | {0xFF ,0xff} |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 13 | }; |
| 14 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 15 | uint8_t find_type_for_sensor_number(uint8_t sensor_number) { |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 16 | |
| 17 | int i=0; |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 18 | uint8_t rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 19 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 20 | while (g_sensortype[i][0] != 0xff) { |
| 21 | if (g_sensortype[i][1] == sensor_number) { |
| 22 | break; |
| 23 | } else { |
| 24 | i++; |
| 25 | } |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 28 | rc = g_sensortype[i][0]; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 29 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 30 | if (rc == 0xFF) { |
| 31 | rc = 0; |
| 32 | } |
| 33 | return rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 36 | char g_results_method[64]; |
| 37 | char g_results_value[64]; |
| 38 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 39 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 40 | int set_sensor_dbus_state_s(unsigned char number, const char *member, const char *value) { |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 41 | strcpy(g_results_method, member); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 42 | strcpy(g_results_value, value); |
| 43 | |
| 44 | return 0; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 47 | int set_sensor_dbus_state_y(unsigned char number, char const* member, uint8_t value) { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 48 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 49 | char val[2]; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 50 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 51 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 52 | snprintf(val, 2, "%d", value); |
| 53 | |
| 54 | strcpy(g_results_method, member); |
| 55 | strcpy(g_results_value, val); |
| 56 | |
| 57 | return 0; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
| 61 | extern int updateSensorRecordFromSSRAESC(const void *record); |
| 62 | |
| 63 | |
| 64 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 65 | // DIMM Present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 66 | uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 67 | |
| 68 | // DIMM Not present |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 69 | uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}; |
| 70 | |
| 71 | // DIMM Not present |
| 72 | uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; |
| 73 | |
| 74 | // Virtual Sensor 5, setting a Value of 0h |
| 75 | uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00}; |
| 76 | |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 77 | // Virtual Sensor setting a boot count |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 78 | uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 79 | |
| 80 | // Invalid sensor number |
| 81 | uint8_t testrec_invalidnumber[]= {0x35, 0xa9, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 82 | |
| 83 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 84 | int check_results(int rc, const char *method, const char *value) { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 85 | 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 Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 89 | return -1; |
| 90 | } |
| 91 | if (strcmp(g_results_value, value)) { |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 92 | log<level::ERR>("Value failed", |
| 93 | entry("EXPECT=%s", value), |
| 94 | entry("GOT=%s", g_results_method)); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 95 | return -2; |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | void 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 Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 106 | |
| 107 | int main() { |
| 108 | |
Chris Austen | 1864155 | 2015-12-10 18:44:07 -0600 | [diff] [blame] | 109 | 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 Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 114 | testprep(); check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", ""); |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 115 | |
| 116 | return 0; |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 117 | } |