1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <app_mgmt_port_consts.h>
18 #include <app_mgmt_test.h>
19 #include <stddef.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <trusty_ipc.h>
24 #include <uapi/err.h>
25
26 #define TLOG_TAG "port-start-fail-srv"
27
main(void)28 int main(void) {
29 int rc;
30 handle_t phandle;
31 handle_t chandle;
32 uevent_t uevt;
33
34 TLOGE("ERROR: Starting server that should fail to start\n");
35
36 /*
37 * The current manifest for this server request almost 8GB of heap and stack
38 * (the maximum currently supported) to trigger a failure when the kernel
39 * tries to start the app.
40 *
41 * Create START_FAIL_PORT so the test tried to start the app can validate
42 * that the app did not actually start.
43 */
44 rc = port_create(START_FAIL_PORT, 1, 1, IPC_PORT_ALLOW_TA_CONNECT);
45 if (rc < 0) {
46 TLOGI("failed (%d) to create ctrl port\n", rc);
47 return rc;
48 }
49 phandle = (handle_t)rc;
50
51 rc = wait(phandle, &uevt, -1);
52 if (rc != NO_ERROR || !(uevt.event & IPC_HANDLE_POLL_READY)) {
53 TLOGI("Port wait failed(%d) event:%d handle:%d\n", rc, uevt.event,
54 phandle);
55 return rc;
56 }
57
58 chandle = (handle_t)rc;
59
60 rc = close(chandle);
61 if (rc < 0) {
62 TLOGI("Close failed(%d) handle:%d\n", rc, chandle);
63 return rc;
64 }
65
66 return 0;
67 }
68