View Javadoc
1   /*
2    * Copyright 2022-2023 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.unix.aix;
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.List;
13  import java.util.Locale;
14  import java.util.Map;
15  
16  import org.junit.jupiter.api.Test;
17  import org.junit.jupiter.api.condition.EnabledOnOs;
18  import org.junit.jupiter.api.condition.OS;
19  
20  import oshi.SystemInfo;
21  import oshi.jna.platform.unix.AixLibc.AixLwpsInfo;
22  import oshi.jna.platform.unix.AixLibc.AixPsInfo;
23  import oshi.util.Constants;
24  import oshi.util.ParseUtil;
25  import oshi.util.tuples.Pair;
26  import oshi.util.tuples.Triplet;
27  
28  @EnabledOnOs(OS.AIX)
29  class PsInfoTest {
30      @Test
31      void testQueryPsInfo() {
32          int pid = new SystemInfo().getOperatingSystem().getProcessId();
33          AixPsInfo psinfo = PsInfo.queryPsInfo(pid);
34          assertThat("Process ID in structure should match PID", psinfo.pr_pid, is((long) pid));
35  
36          Triplet<Integer, Long, Long> addrs = PsInfo.queryArgsEnvAddrs(pid, psinfo);
37          assertNotNull(addrs);
38          Pair<List<String>, Map<String, String>> argsEnv = PsInfo.queryArgsEnv(pid, psinfo);
39          assertThat("Arg list size should match argc", argsEnv.getA().size(), is(addrs.getA().intValue()));
40  
41          File directory = new File(String.format(Locale.ROOT, "/proc/%d/lwp", pid));
42          File[] numericFiles = directory.listFiles(file -> Constants.DIGITS.matcher(file.getName()).matches());
43          assertNotNull(numericFiles);
44          for (File lwpidFile : numericFiles) {
45              int tid = ParseUtil.parseIntOrDefault(lwpidFile.getName(), 0);
46              AixLwpsInfo lwpsinfo = PsInfo.queryLwpsInfo(pid, tid);
47              assertThat("Thread ID in structure should match TID", lwpsinfo.pr_lwpid, is((long) tid));
48          }
49      }
50  }