Debian Codegraph @

modules/lsp-runtime-lib/src/test/utest/runtime/system.cpp

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 24 июн. 2022 г.
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/runtime/system.h>
24
25 UTEST_BEGIN("runtime.runtime", system)
26
27 void test_sleep_msec(size_t period)
28 {
29 system::time_millis_t start, end;
30 printf("Testing sleep for %d milliseconds\n", int(period));
31
32 start = system::get_time_millis();
33 UTEST_ASSERT(system::sleep_msec(period) == STATUS_OK);
34 end = system::get_time_millis();
35
36 wssize_t delay_ms = end - start;
37 printf("Requested delay: %ld, actual delay: %ld\n", long(period), long(delay_ms));
38
39 // The delay should not be less than expected.
40 UTEST_ASSERT(delay_ms >= wssize_t(period));
41 }
42
43 void test_time_measure()
44 {
45 system::time_t ctime;
46 system::time_millis_t millis, computed;
47
48 millis = system::get_time_millis();
49 system::get_time(&ctime);
50 computed = system::time_millis_t(ctime.seconds) * 1000 + system::time_millis_t(ctime.nanos) / 1000000;
51
52 printf("ctime = %lld seconds %lld nanos\n", (long long)(ctime.seconds), (long long)(ctime.nanos));
53 printf("millis = %lld\n", (long long)millis);
54 printf("computed = %lld\n", (long long)computed);
55 printf("rate = %lld\n", (long long)(millis/computed));
56
57 UTEST_ASSERT(ctime.nanos < 1000000000u);
58 UTEST_ASSERT(computed >= millis);
59 UTEST_ASSERT((computed - millis) <= 10);
60 }
61
62 void test_volume_info()
63 {
64 lltl::parray<system::volume_info_t> list;
65 lsp_finally{ system::free_volume_info(&list); };
66 UTEST_ASSERT(system::get_volume_info(&list) == STATUS_OK);
67
68 printf("List of available volumes:\n");
69
70 for (size_t i=0, n=list.size(); i<n; ++i)
71 {
72 system::volume_info_t *v = list.uget(i);
73 UTEST_ASSERT(v != NULL);
74
75 printf("dev %s root=%s type=%s mounted on %s dummy=%s, remote=%s, drive=%s\n",
76 v->device.get_native(),
77 v->root.get_native(),
78 v->name.get_native(),
79 v->target.get_native(),
80 (v->flags & system::VF_DUMMY) ? "true" : "false",
81 (v->flags & system::VF_REMOTE) ? "true" : "false",
82 (v->flags & system::VF_DRIVE) ? "true" : "false");
83 }
84 }
85
86 void test_get_user_login()
87 {
88 LSPString login;
89 UTEST_ASSERT(system::get_user_login(&login) == STATUS_OK);
90 printf("User login is: %s\n", login.get_native());
91 }
92
93 UTEST_MAIN
94 {
95 // Test user login
96 test_get_user_login();
97
98 // Test reading of volume info
99 test_volume_info();
100
101 // Test time measurement
102 test_time_measure();
103
104 // Test the system::sleep_msec function.
105 test_sleep_msec(10);
106 test_sleep_msec(15);
107 test_sleep_msec(100);
108 test_sleep_msec(105);
109 test_sleep_msec(150);
110 test_sleep_msec(1000);
111 test_sleep_msec(1005);
112 }
113 UTEST_END;
114
115