Skip to content

Commit 08ac928

Browse files
authored
Merge pull request #18 from qc-azarrabi/debug-fix
So random update
2 parents f800c7b + 3e8d87a commit 08ac928

File tree

6 files changed

+83
-74
lines changed

6 files changed

+83
-74
lines changed

libqcomtee/include/qcomtee_object_types.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
* @brief Get a credentials object.
1111
* @param root The root object to which this object belongs.
1212
* @param object Credentials object.
13-
* @return On success returns @ref QCOMTEE_OK;
14-
* Otherwise @ref QCOMTEE_ERROR_MEM.
13+
* @return On success, returns 0; Otherwise, returns -1.
1514
*/
16-
qcomtee_result_t
17-
qcomtee_object_credentials_init(struct qcomtee_object *root,
18-
struct qcomtee_object **object);
15+
int qcomtee_object_credentials_init(struct qcomtee_object *root,
16+
struct qcomtee_object **object);
1917

2018
/* Select qcomtee_memory_object_alloc vs. qcomtee_memory_object_register. */
2119
#define qcomtee_memory_object_tee_api_select(a, b, c, d, fun, ...) fun

libqcomtee/src/objects/credentials_obj.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,25 @@ static struct qcomtee_object_ops ops = {
139139
.dispatch = qcomtee_object_credentials_dispatch,
140140
};
141141

142-
qcomtee_result_t
143-
qcomtee_object_credentials_init(struct qcomtee_object *root,
144-
struct qcomtee_object **object)
142+
int qcomtee_object_credentials_init(struct qcomtee_object *root,
143+
struct qcomtee_object **object)
145144
{
146145
struct qcomtee_credentials *qcomtee_cred;
147146

148147
qcomtee_cred = calloc(1, sizeof(*qcomtee_cred));
149148
if (!qcomtee_cred)
150-
return QCOMTEE_ERROR_MEM;
149+
return -1;
151150

152151
qcomtee_object_cb_init(&qcomtee_cred->object, &ops, root);
153152
/* INIT the credentials buffer. */
154153
if (credentials_init(&qcomtee_cred->ubuf)) {
155154
free(qcomtee_cred);
156155

157-
return QCOMTEE_ERROR_MEM;
156+
return -1;
158157
}
159158

160159
/* Get the credentials object. */
161160
*object = &qcomtee_cred->object;
162161

163-
return QCOMTEE_OK;
162+
return 0;
164163
}

tests/common.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int tee_call(int fd, int op, ...)
3030
ret = ioctl(fd, op, arg);
3131
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
3232
if (ret < 0)
33-
PRINT("ioctl: %s\n", strerror(errno));
33+
MSG_ERROR("%s\n", strerror(errno));
3434

3535
return ret;
3636
}
@@ -46,7 +46,7 @@ static void *test_supplicant_worker(void *arg)
4646
break;
4747
}
4848

49-
PRINT("qcomtee_object_process_one.\n");
49+
MSG_INFO("Supplicant thread exited\n");
5050

5151
return NULL;
5252
}
@@ -66,7 +66,8 @@ static void test_supplicant_release(void *arg)
6666
pthread_join(sup->thread, NULL);
6767
}
6868

69-
PRINT("test_supplicant_worker killed.\n");
69+
MSG_INFO("Supplicant thread killed.\n");
70+
7071
free(sup);
7172
}
7273

@@ -77,23 +78,27 @@ struct qcomtee_object *test_get_root(void)
7778
pthread_t thread;
7879

7980
sup = calloc(1, sizeof(*sup));
80-
if (!sup)
81+
if (!sup) {
82+
MSG_ERROR("%s\n", strerror(errno));
8183
return QCOMTEE_OBJECT_NULL;
84+
}
8285

8386
/* Start a fresh namespace. */
8487
root = qcomtee_object_root_init(DEV_TEE, tee_call,
8588
test_supplicant_release, sup);
86-
if (root == QCOMTEE_OBJECT_NULL)
89+
if (root == QCOMTEE_OBJECT_NULL) {
90+
MSG_ERROR("Unable to initialize the root object\n");
8791
goto failed_out;
92+
}
8893

8994
sup->root = root;
90-
9195
/* Start a supplicant thread. */
92-
if (pthread_create(&thread, NULL, test_supplicant_worker, sup))
96+
if (pthread_create(&thread, NULL, test_supplicant_worker, sup)) {
97+
MSG_ERROR("Unable to start supplicant thread\n");
9398
goto failed_out;
99+
}
94100

95101
sup->thread = thread;
96-
97102
return root;
98103

99104
failed_out:
@@ -109,24 +114,29 @@ struct qcomtee_object *test_get_client_env_object(struct qcomtee_object *root)
109114
struct qcomtee_param params[2];
110115
qcomtee_result_t result;
111116

112-
if (qcomtee_object_credentials_init(root, &creds_object))
117+
if (qcomtee_object_credentials_init(root, &creds_object)) {
118+
MSG_ERROR("Unable to initialize the credential object\n");
113119
return QCOMTEE_OBJECT_NULL;
120+
}
114121

115122
/* INIT parameters and invoke object: */
116123
params[0].attr = QCOMTEE_OBJREF_INPUT;
117124
params[0].object = creds_object;
118125
params[1].attr = QCOMTEE_OBJREF_OUTPUT;
119126
/* 2 is IClientEnv_OP_registerAsClient. */
120127
if (qcomtee_object_invoke(root, 2, params, 2, &result)) {
128+
/* Releases creds_object. */
121129
qcomtee_object_refs_dec(creds_object);
122-
return QCOMTEE_OBJECT_NULL;
130+
goto failed_out;
123131
}
124132

125133
/* qcomtee_object_invoke was successful; QTEE releases creds_object. */
126134

127135
if (!result)
128136
return params[1].object;
129137

138+
failed_out:
139+
MSG_ERROR("Unable to obtain the env object, result %d\n", result);
130140
return QCOMTEE_OBJECT_NULL;
131141
}
132142

@@ -142,9 +152,13 @@ test_get_service_object(struct qcomtee_object *client_env_object, uint32_t uid)
142152
params[1].attr = QCOMTEE_OBJREF_OUTPUT;
143153
/* 0 is IClientEnv_OP_open. */
144154
if (qcomtee_object_invoke(client_env_object, 0, params, 2, &result) ||
145-
(result != QCOMTEE_OK))
155+
(result != QCOMTEE_OK)) {
156+
MSG_ERROR("Unable to obtain object (UID = %u), result %d\n",
157+
uid, result);
146158
return QCOMTEE_OBJECT_NULL;
159+
}
147160

161+
MSG_INFO("Obtained object (UID = %u)\n", uid);
148162
return params[1].object;
149163
}
150164

@@ -156,18 +170,18 @@ size_t test_get_file_size(FILE *file)
156170
ssize_t size;
157171

158172
if (fseek(file, 0, SEEK_END)) {
159-
PRINT("%s\n", strerror(errno));
173+
MSG_ERROR("%s\n", strerror(errno));
160174
return 0;
161175
}
162176

163177
size = ftell(file);
164178
if (size < 0) {
165-
PRINT("%s\n", strerror(errno));
179+
MSG_ERROR("%s\n", strerror(errno));
166180
return 0;
167181
}
168182

169183
if (fseek(file, 0, SEEK_SET)) {
170-
PRINT("%s\n", strerror(errno));
184+
MSG_ERROR("%s\n", strerror(errno));
171185
return 0;
172186
}
173187

@@ -186,7 +200,8 @@ size_t test_get_file_size_by_filename(const char *pathname, const char *name)
186200

187201
file = fopen(filename, "r");
188202
if (!file) {
189-
PRINT("%s\n", strerror(errno));
203+
MSG_ERROR("%s\n", strerror(errno));
204+
190205
return 0;
191206
}
192207

@@ -214,7 +229,8 @@ size_t test_read_file(const char *filename, char **buffer, size_t size)
214229

215230
file = fopen(filename, "r");
216231
if (!file) {
217-
PRINT("%s\n", strerror(errno));
232+
MSG_ERROR("%s\n", strerror(errno));
233+
218234
return 0;
219235
}
220236

@@ -225,7 +241,7 @@ size_t test_read_file(const char *filename, char **buffer, size_t size)
225241
if (size > 0) {
226242
/* User provided the buffer; make sure it is large enough. */
227243
if (size < file_size) {
228-
PRINT("no space.\n");
244+
MSG_ERROR("Buffer is small (required %lu)\n", file_size);
229245
file_size = 0; /* Unable to read. */
230246

231247
goto out;
@@ -236,17 +252,17 @@ size_t test_read_file(const char *filename, char **buffer, size_t size)
236252
/* User did not provide the buffer; allocate one. */
237253
file_buf = malloc(file_size);
238254
if (!file_buf) {
239-
PRINT("malloc.\n");
255+
MSG_ERROR("%s\n", strerror(errno));
240256
file_size = 0; /* Unable to read. */
241257

242258
goto out;
243259
}
244260
}
245261

246-
PRINT("File %s, size: %lu Bytes.\n", filename, file_size);
262+
MSG_INFO("Reading %s, %lu Bytes.\n", filename, file_size);
247263

248264
if (fread(file_buf, 1, file_size, file) != file_size) {
249-
PRINT("fread.\n");
265+
MSG_ERROR("%s\n", feof(file) ? "EOF" : strerror(errno));
250266
if (size == 0)
251267
free(file_buf);
252268
file_size = 0; /* Unable to read. */

tests/diagnostics.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,43 @@ void test_print_diagnostics_info(void)
1919
struct qcomtee_param params[1];
2020
qcomtee_result_t result;
2121

22+
MSG("Starting test_print_diagnostics_info\n");
23+
2224
/* Get root + supplicant. */
2325
root = test_get_root();
24-
if (root == QCOMTEE_OBJECT_NULL) {
25-
PRINT("test_get_root.\n");
26+
if (root == QCOMTEE_OBJECT_NULL)
2627
return;
27-
}
2828

2929
client_env_object = test_get_client_env_object(root);
30-
if (client_env_object == QCOMTEE_OBJECT_NULL) {
31-
PRINT("test_get_client_env_object.\n");
30+
if (client_env_object == QCOMTEE_OBJECT_NULL)
3231
goto dec_root_object;
33-
}
3432

3533
/* 143 is UID of Diagnostics service. */
3634
service_object = test_get_service_object(client_env_object, 143);
37-
if (service_object == QCOMTEE_OBJECT_NULL) {
38-
PRINT("test_get_service_object.\n");
35+
if (service_object == QCOMTEE_OBJECT_NULL)
3936
goto dec_client_env_object;
40-
}
4137

4238
/* INIT parameters and invoke object: */
4339
params[0].attr = QCOMTEE_UBUF_OUTPUT;
4440
params[0].ubuf = UBUF_INIT(&heap_info);
4541
/* 0 is IDiagnostics_OP_queryHeapInfo. */
4642
if (qcomtee_object_invoke(service_object, 0, params, 1, &result) ||
4743
(result != QCOMTEE_OK)) {
48-
PRINT("qcomtee_object_invoke.\n");
44+
MSG_ERROR("Unable to obtain diagnostics info, result %d\n",
45+
result);
4946
goto dec_service_object;
5047
}
5148

52-
PRINT("%-15d = Total bytes as heap\n", heap_info.total_size);
53-
PRINT("%-15d = Total bytes allocated from heap\n", heap_info.used_size);
54-
PRINT("%-15d = Total bytes free on heap\n", heap_info.free_size);
55-
PRINT("%-15d = Total bytes overhead\n", heap_info.overhead_size);
56-
PRINT("%-15d = Total bytes wasted\n", heap_info.wasted_size);
57-
PRINT("%-15d = Largest free block size\n\n",
58-
heap_info.largest_free_block_size);
49+
MSG_INFO("%-15d = Total bytes as heap\n", heap_info.total_size);
50+
MSG_INFO("%-15d = Total bytes allocated from heap\n",
51+
heap_info.used_size);
52+
MSG_INFO("%-15d = Total bytes free on heap\n", heap_info.free_size);
53+
MSG_INFO("%-15d = Total bytes overhead\n", heap_info.overhead_size);
54+
MSG_INFO("%-15d = Total bytes wasted\n", heap_info.wasted_size);
55+
MSG_INFO("%-15d = Largest free block size\n\n",
56+
heap_info.largest_free_block_size);
5957

60-
PRINT("SUCCESS.\n");
58+
MSG_INFO("SUCCESS.\n");
6159

6260
dec_service_object:
6361
qcomtee_object_refs_dec(service_object);

0 commit comments

Comments
 (0)