1 /*
2 * Copyright (C) 2014 Satoshi Noguchi
3 * Copyright (C) 2014 Synaptics Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include <sys/types.h>
19
20 #include "testutil.h"
21
22 const char *test_error_str[] = {
23 "success", // TEST_SUCCESS
24 "failed", // TEST_FAIL
25 "timeout", // TEST_FAIL_TIMEOUT
26 "failed to find F01 on device", // TEST_FAIL_NO_FUNCTION_01
27 "failed to find F54 on device", // TEST_FAIL_NO_FUNCTION_54
28 "failed to find F55 on device", // TEST_FAIL_NO_FUNCTION_55
29 "failed to query the basic properties in F01", // TEST_FAIL_QUERY_BASIC_PROPERTIES
30 "failed to read F54 query registers", // TEST_FAIL_READ_F54_QUERIES
31 "failed to read F54 control registers", // TEST_FAIL_READ_F54_CONTROLS
32 "failed to scan the PDT", // TEST_FAIL_SCAN_PDT
33 "failed to read the device status", // TEST_FAIL_READ_DEVICE_STATUS
34 "failed to read F01 control 0 register", // TEST_FAIL_READ_F01_CONTROL_0
35 "failed to write F01 control 0 register", // TEST_FAIL_WRITE_F01_CONTROL_0
36 "timeout waiting for attn", // TEST_FAIL_TIMEOUT_WAITING_FOR_ATTN
37 "invalid parameter", // TEST_FAIL_INVALID_PARAMETER
38 "memory allocation failure", // TEST_FAIL_MEMORY_ALLOCATION
39 };
40
test_err_to_string(int err)41 const char * test_err_to_string(int err)
42 {
43 return test_error_str[err];
44 }
45
extract_long(const unsigned char * data)46 unsigned long extract_long(const unsigned char *data)
47 {
48 return (unsigned long)data [0]
49 + (unsigned long)data [1] * 0x100
50 + (unsigned long)data [2] * 0x10000
51 + (unsigned long)data [3] * 0x1000000;
52 }
53
extract_short(const unsigned char * data)54 unsigned short extract_short(const unsigned char *data)
55 {
56 return (unsigned long)data [0]
57 + (unsigned long)data [1] * 0x100;
58 }
59
StripPath(const char * path,ssize_t size)60 const char * StripPath(const char * path, ssize_t size)
61 {
62 int i;
63 const char * str;
64
65 for (i = size - 1, str = &path[size - 1]; i > 0; --i, --str)
66 if (path[i - 1] == '/')
67 break;
68
69 return str;
70 }
71