test all proc functions dont fault w/ invalid pid

This commit is contained in:
Doug MacEachern 2004-07-07 02:31:47 +00:00
parent ee9cefd9e5
commit 11c9afd576
10 changed files with 52 additions and 0 deletions

View File

@ -80,6 +80,10 @@ public abstract class SigarTestCase extends TestCase {
return out; return out;
} }
public long getInvalidPid() {
return 666666;
}
public void traceln(String msg) { public void traceln(String msg) {
if (getVerbose()) { if (getVerbose()) {
getWriter().println(msg); getWriter().println(msg);

View File

@ -1,6 +1,7 @@
package net.hyperic.sigar.test; package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarNotImplementedException; import net.hyperic.sigar.SigarNotImplementedException;
public class TestProcArgs extends SigarTestCase { public class TestProcArgs extends SigarTestCase {
@ -28,6 +29,11 @@ public class TestProcArgs extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcArgs(getInvalidPid());
} catch (SigarException e) {
}
try { try {
String[] args = sigar.getProcArgs(sigar.getPid()); String[] args = sigar.getProcArgs(sigar.getPid());

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.Map; import java.util.Map;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarNotImplementedException; import net.hyperic.sigar.SigarNotImplementedException;
public class TestProcEnv extends SigarTestCase { public class TestProcEnv extends SigarTestCase {
@ -15,6 +16,11 @@ public class TestProcEnv extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcEnv(getInvalidPid());
} catch (SigarException e) {
}
long pid = sigar.getPid(); long pid = sigar.getPid();
try { try {

View File

@ -3,6 +3,7 @@ package net.hyperic.sigar.test;
import java.io.File; import java.io.File;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcExe; import net.hyperic.sigar.ProcExe;
import net.hyperic.sigar.SigarNotImplementedException; import net.hyperic.sigar.SigarNotImplementedException;
@ -15,6 +16,11 @@ public class TestProcExe extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcExe(getInvalidPid());
} catch (SigarException e) {
}
try { try {
ProcExe exe = sigar.getProcExe(sigar.getPid()); ProcExe exe = sigar.getProcExe(sigar.getPid());

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarLoader; import net.hyperic.sigar.SigarLoader;
import net.hyperic.sigar.SigarNotImplementedException; import net.hyperic.sigar.SigarNotImplementedException;
@ -16,6 +17,11 @@ public class TestProcFd extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcFd(getInvalidPid());
} catch (SigarException e) {
}
try { try {
long pid = sigar.getPid(); long pid = sigar.getPid();

View File

@ -1,6 +1,7 @@
package net.hyperic.sigar.test; package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcMem; import net.hyperic.sigar.ProcMem;
public class TestProcMem extends SigarTestCase { public class TestProcMem extends SigarTestCase {
@ -12,6 +13,11 @@ public class TestProcMem extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcMem(getInvalidPid());
} catch (SigarException e) {
}
ProcMem procMem = sigar.getProcMem(sigar.getPid()); ProcMem procMem = sigar.getProcMem(sigar.getPid());
assertTrue(procMem.getSize() > 0); assertTrue(procMem.getSize() > 0);

View File

@ -30,6 +30,11 @@ public class TestProcModules extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
printModules(sigar, getInvalidPid());
} catch (SigarException e) {
}
try { try {
printModules(sigar, sigar.getPid()); printModules(sigar, sigar.getPid());
} catch (SigarNotImplementedException e) { } catch (SigarNotImplementedException e) {

View File

@ -1,6 +1,7 @@
package net.hyperic.sigar.test; package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcStat; import net.hyperic.sigar.ProcStat;
public class TestProcStat extends SigarTestCase { public class TestProcStat extends SigarTestCase {

View File

@ -1,6 +1,7 @@
package net.hyperic.sigar.test; package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcState; import net.hyperic.sigar.ProcState;
public class TestProcState extends SigarTestCase { public class TestProcState extends SigarTestCase {
@ -12,6 +13,11 @@ public class TestProcState extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = getSigar(); Sigar sigar = getSigar();
try {
sigar.getProcState(getInvalidPid());
} catch (SigarException e) {
}
ProcState procState = sigar.getProcState(sigar.getPid()); ProcState procState = sigar.getProcState(sigar.getPid());
assertTrue(procState.getState() == 'R'); assertTrue(procState.getState() == 'R');

View File

@ -1,6 +1,7 @@
package net.hyperic.sigar.test; package net.hyperic.sigar.test;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcTime; import net.hyperic.sigar.ProcTime;
public class TestProcTime extends SigarTestCase { public class TestProcTime extends SigarTestCase {
@ -12,6 +13,11 @@ public class TestProcTime extends SigarTestCase {
public void testCreate() throws Exception { public void testCreate() throws Exception {
Sigar sigar = new Sigar(); Sigar sigar = new Sigar();
try {
sigar.getProcTime(getInvalidPid());
} catch (SigarException e) {
}
ProcTime procTime = sigar.getProcTime(sigar.getPid()); ProcTime procTime = sigar.getProcTime(sigar.getPid());
assertGtEqZeroTrace("StartTime", procTime.getStartTime()); assertGtEqZeroTrace("StartTime", procTime.getStartTime());