1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "hdf_io_service_if.h"
13 #include "hdf_uhdf_test.h"
14
15 static struct HdfIoService *g_testService = NULL;
16 static struct HdfSBuf *g_msg = NULL;
17 static struct HdfSBuf *g_reply = NULL;
18
HdfTestOpenService(void)19 void HdfTestOpenService(void)
20 {
21 g_testService = HdfIoServiceBind(HDF_TEST_SERVICE_NAME);
22 g_msg = HdfSbufObtainDefaultSize();
23 if (g_msg == NULL) {
24 printf("fail to obtain sbuf data\n\r");
25 return;
26 }
27 g_reply = HdfSbufObtainDefaultSize();
28 if (g_reply == NULL) {
29 printf("fail to obtain sbuf reply\n\r");
30 HdfSbufRecycle(g_msg);
31 return;
32 }
33 }
34
HdfTestCloseService(void)35 void HdfTestCloseService(void)
36 {
37 if (g_msg != NULL) {
38 HdfSbufRecycle(g_msg);
39 g_msg = NULL;
40 };
41 if (g_reply != NULL) {
42 HdfSbufRecycle(g_reply);
43 g_reply = NULL;
44 };
45 if (g_testService != NULL) {
46 HdfIoServiceRecycle(g_testService);
47 g_testService = NULL;
48 };
49 }
50
HdfTestSendMsgToService(struct HdfTestMsg * msg)51 int HdfTestSendMsgToService(struct HdfTestMsg *msg)
52 {
53 int ret;
54 struct HdfTestMsg *testReply = NULL;
55 unsigned int len;
56 CHECK_TEST_NULL_PTR_RETURN(g_testService);
57 CHECK_TEST_NULL_PTR_RETURN(g_msg);
58 CHECK_TEST_NULL_PTR_RETURN(g_reply);
59 CHECK_TEST_NULL_PTR_RETURN(msg);
60
61 if (!HdfSbufWriteBuffer(g_msg, msg, sizeof(*msg))) {
62 printf("HdfTestSendMsgToService g_msg write failed\n\r");
63 }
64
65 ret = g_testService->dispatcher->Dispatch(&g_testService->object, 0, g_msg, g_reply);
66 if (ret != HDF_SUCCESS) {
67 printf("HdfTestSendMsgToService fail to send service call\n\r");
68 return ret;
69 }
70
71 if (!HdfSbufReadBuffer(g_reply, (const void **)&testReply, &len)) {
72 printf("HdfTestSendMsgToService g_reply read failed\n\r");
73 }
74
75 if (testReply == NULL) {
76 printf("HdfTestSendMsgToService testReply is null\n\r");
77 ret = -1;
78 } else {
79 ret = testReply->result;
80 }
81 HdfSbufFlush(g_msg);
82 HdfSbufFlush(g_reply);
83
84 return ret;
85 }
86
87