Debian Codegraph @

modules/lsp-runtime-lib/src/test/utest/ipc/process2.cpp

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 21 сент. 2020 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/test-fw/utest.h>
23 #include <lsp-plug.in/ipc/Process.h>
24 #include <lsp-plug.in/ipc/Thread.h>
25 #include <lsp-plug.in/runtime/system.h>
26
27 using namespace lsp;
28
29 namespace {
30 class StaticTest
31 {
32 private:
33 status_t nStatus;
34
35 public:
36 StaticTest() { nStatus = STATUS_OK; }
37 ~StaticTest() { nStatus = STATUS_REMOVED; }
38
39 public:
40 inline status_t status() const { return nStatus; }
41 };
42
43 static StaticTest static_test;
44
45 #ifdef PLATFORM_POSIX
46 static int atexit_calls = 0;
47
48 void handle_atexit(void)
49 {
50 ++atexit_calls;
51 printf("atexit called for pid=%d\n", int(getpid()));
52 }
53 #endif /* PLATFORM_POSIX */
54 };
55
56 UTEST_BEGIN("runtime.ipc", process2)
57
58 UTEST_MAIN
59 {
60 printf("Testing launch of non-existing process\n");
61
62 // Test static data for being not destructed
63 UTEST_ASSERT(static_test.status() == STATUS_OK);
64
65 #ifdef PLATFORM_POSIX
66 printf("Parent pid=%d\n", int(getpid()));
67 atexit(handle_atexit);
68 #endif /* PLATFORM_POSIX */
69
70 ipc::Process p;
71 p.set_command("some-long-unexisting-command-which-will-fail");
72 p.add_arg("1");
73 p.add_arg("2");
74 p.add_arg("3");
75
76 printf("Launching process...\n");
77 UTEST_ASSERT(p.launch() == STATUS_OK);
78 printf("Launched process\n");
79
80 UTEST_ASSERT(p.wait() == STATUS_OK);
81 printf("Process has exited\n");
82
83 int code = 0;
84 UTEST_ASSERT(p.exit_code(&code) == STATUS_OK);
85
86 printf("Exit code = %d\n", code);
87
88 // Test static data for being not destructed and atexit() has not been called
89 UTEST_ASSERT(static_test.status() == STATUS_OK);
90
91 #ifdef PLATFORM_POSIX
92 UTEST_ASSERT(atexit_calls == 0);
93 #endif /* PLATFORM_POSIX */
94 }
95 UTEST_END;
96