1
2
3
4
5 package oshi.driver.unix.solaris;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.is;
9 import static org.junit.jupiter.api.Assertions.assertNotNull;
10
11 import java.io.File;
12 import java.util.Locale;
13
14 import org.junit.jupiter.api.Test;
15 import org.junit.jupiter.api.condition.EnabledOnOs;
16 import org.junit.jupiter.api.condition.OS;
17
18 import oshi.SystemInfo;
19 import oshi.jna.platform.unix.SolarisLibc.SolarisLwpsInfo;
20 import oshi.jna.platform.unix.SolarisLibc.SolarisPsInfo;
21 import oshi.util.Constants;
22 import oshi.util.ParseUtil;
23
24 @EnabledOnOs(OS.SOLARIS)
25 class PsInfoTest {
26 @Test
27 void testQueryPsInfo() {
28 int pid = new SystemInfo().getOperatingSystem().getProcessId();
29 SolarisPsInfo psinfo = PsInfo.queryPsInfo(pid);
30 assertThat("Process ID in structure should match PID", psinfo.pr_pid, is(pid));
31 File directory = new File(String.format(Locale.ROOT, "/proc/%d/lwp", pid));
32 File[] numericFiles = directory.listFiles(file -> Constants.DIGITS.matcher(file.getName()).matches());
33 assertNotNull(numericFiles);
34 for (File lwpidFile : numericFiles) {
35 int tid = ParseUtil.parseIntOrDefault(lwpidFile.getName(), 0);
36 SolarisLwpsInfo lwpsinfo = PsInfo.queryLwpsInfo(pid, tid);
37 assertThat("Thread ID in structure should match TID", lwpsinfo.pr_lwpid, is(tid));
38 }
39 }
40 }