22 lines
1.6 KiB
Java
22 lines
1.6 KiB
Java
package com.iomatex.console;
|
|
import java.nio.file.*;
|
|
import java.util.*;
|
|
public final class ThermalSensorsTest {
|
|
static void zone(Path root,int index,String name,String raw)throws Exception{
|
|
Path path=Files.createDirectory(root.resolve("thermal_zone"+index));Files.write(path.resolve("type"),name.getBytes());if(raw!=null)Files.write(path.resolve("temp"),raw.getBytes());
|
|
}
|
|
public static void main(String[] args)throws Exception{
|
|
Path root=Files.createTempDirectory("thermal-contract");
|
|
try{
|
|
zone(root,0,"soc-thermal","63888");zone(root,1,"gpu-thermal","60000");zone(root,2,"test_battery","2600");
|
|
zone(root,3,"cpu-missing",null);zone(root,4,"bad","NaN");zone(root,5,"overflow","999999");zone(root,6,"zero","0");
|
|
List<ThermalSensors.Reading> values=ThermalSensors.read(root.toFile());
|
|
if(values.size()!=6||!values.get(0).name.equals("soc-thermal")||values.get(0).celsius!=63.9||values.get(1).celsius!=60.0)throw new AssertionError("identity/scaling/test-zone exclusion");
|
|
for(int i=2;i<=4;i++)if(values.get(i).celsius!=null)throw new AssertionError("unavailable/invalid values must not become temperatures");
|
|
if(values.get(5).celsius!=0.0)throw new AssertionError("zero is a valid temperature");
|
|
if(!ThermalSensors.read(root.resolve("missing").toFile()).isEmpty())throw new AssertionError("missing sysfs");
|
|
System.out.println("PASS thermal units, identity, unavailable, invalid, range and zero");
|
|
}finally{try(java.util.stream.Stream<Path> paths=Files.walk(root)){paths.sorted(Comparator.reverseOrder()).forEach(p->{try{Files.delete(p);}catch(Exception ignored){}});}}
|
|
}
|
|
}
|