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 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 11 | int i = 0; |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 12 | uint8_t rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 13 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 14 | while (g_sensortype[i][0] != 0xff) |
| 15 | { |
| 16 | if (g_sensortype[i][1] == sensor_number) |
| 17 | { |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 18 | break; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 19 | } |
| 20 | else |
| 21 | { |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 22 | i++; |
| 23 | } |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 24 | } |
| 25 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 26 | rc = g_sensortype[i][0]; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 27 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | if (rc == 0xFF) |
| 29 | { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 30 | rc = 0; |
| 31 | } |
| 32 | return rc; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 35 | char g_results_method[64]; |
| 36 | char g_results_value[64]; |
| 37 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 38 | int set_sensor_dbus_state_s(unsigned char number, const char* member, |
| 39 | const char* value) |
| 40 | { |
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 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 47 | int set_sensor_dbus_state_y(unsigned char number, const char* member, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 48 | uint8_t value) |
| 49 | { |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 50 | char val[2]; |
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 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 60 | extern int updateSensorRecordFromSSRAESC(const void* record); |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 61 | |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 62 | // DIMM Present |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 63 | uint8_t testrec_sensor1[] = {0x1F, 0xa9, 0x00, 0x40, 0x00, |
| 64 | 0x00, 0x00, 0x00, 0x00, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 65 | |
| 66 | // DIMM Not present |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 67 | uint8_t testrec_sensor2[] = {0x1F, 0xa9, 0x00, 0x00, 0x00, |
| 68 | 0x40, 0x00, 0x00, 0x00, 0x00}; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 69 | |
| 70 | // DIMM Not present |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 71 | uint8_t testrec_procfailed[] = {0x02, 0xa9, 0x00, 0x00, 0x00, |
| 72 | 0x00, 0x01, 0x00, 0x00, 0x00}; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 73 | |
| 74 | // Virtual Sensor 5, setting a Value of 0h |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 75 | uint8_t testrec_bootprogress[] = {0x05, 0xa9, 0x00, 0x04, 0x00, |
| 76 | 0x00, 0x00, 0x00, 0x0E, 0x00}; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 77 | |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 78 | // Virtual Sensor setting a boot count |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 79 | uint8_t testrec_bootcount[] = {0x01, 0x09, 0x00, 0x03, 0x00, |
| 80 | 0x00, 0x00, 0x00, 0x00, 0x00}; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 81 | |
| 82 | // Invalid sensor number |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 83 | uint8_t testrec_invalidnumber[] = {0x35, 0xa9, 0x00, 0x04, 0x00, |
| 84 | 0x00, 0x00, 0x00, 0x03, 0x00}; |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 85 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 86 | int check_results(int rc, const char* method, const char* value) |
| 87 | { |
| 88 | if (strcmp(g_results_method, method)) |
| 89 | { |
| 90 | log<level::ERR>("Method Failed", entry("EXPECT=%s", method), |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 91 | entry("GOT=%s", g_results_method)); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 92 | return -1; |
| 93 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 94 | if (strcmp(g_results_value, value)) |
| 95 | { |
| 96 | log<level::ERR>("Value failed", entry("EXPECT=%s", value), |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 97 | entry("GOT=%s", g_results_method)); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 98 | return -2; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | void testprep(void) |
| 105 | { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 106 | memset(g_results_method, 0, sizeof(g_results_method)); |
| 107 | memset(g_results_value, 0, sizeof(g_results_value)); |
| 108 | } |
| 109 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 110 | int main() |
| 111 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 112 | testprep(); |
| 113 | check_results(updateSensorRecordFromSSRAESC(testrec_bootprogress), |
| 114 | "setValue", "FW Progress, Docking station attachment"); |
| 115 | testprep(); |
| 116 | check_results(updateSensorRecordFromSSRAESC(testrec_sensor1), "setPresent", |
| 117 | "True"); |
| 118 | testprep(); |
| 119 | check_results(updateSensorRecordFromSSRAESC(testrec_sensor2), "setPresent", |
| 120 | "False"); |
| 121 | testprep(); |
| 122 | check_results(updateSensorRecordFromSSRAESC(testrec_procfailed), "setFault", |
| 123 | "False"); |
| 124 | testprep(); |
| 125 | check_results(updateSensorRecordFromSSRAESC(testrec_bootcount), "setValue", |
| 126 | "3"); |
| 127 | testprep(); |
| 128 | check_results(updateSensorRecordFromSSRAESC(testrec_invalidnumber), "", ""); |
Chris Austen | 2fb1173 | 2015-10-15 00:50:25 -0500 | [diff] [blame] | 129 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 130 | return 0; |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 131 | } |