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