summaryrefslogtreecommitdiffstats
path: root/pts/test-resources/compliance-acpi/install.sh
blob: ec17ddac8d48c4d238d1c696ef81b9ed0d2b9066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh

cat > acpi-checks << 'EOT'
<?php
function read_delimit($contents, $match)
{
	$value = "";
	$cpuinfo_lines = explode("\n", $contents);

	for($i = 0; $i < count($cpuinfo_lines) && $value == ""; $i++)
	{
		$line = explode(": ", $cpuinfo_lines[$i]);
		$this_attribute = trim($line[0]);

		if(count($line) > 1)
			$this_value = trim($line[1]);
		else
			$this_value = "";

		if($this_attribute == $match)
			$value = $this_value;
	}
	return $value;
}

$acpi_results = array();

$acpi_battery = "FAIL";
foreach(glob("/proc/acpi/video/*/*/brightness") as $brightness_file)
	if($acpi_battery == "FAIL")
	{
		$brightness_file_contents = file_get_contents($brightness_file);
		if(strpos($brightness_file_contents, "levels") !== FALSE && strpos($brightness_file_contents, "current") !== FALSE)
			$acpi_battery = "PASS";
	}
array_push($acpi_results, $acpi_battery);

$acpi_cpupm = "FAIL";
foreach(glob("/proc/acpi/processor/*/info") as $cpu_info_file)
	if(read_delimit(file_get_contents($cpu_info_file), "power management") == "yes")
		$acpi_cpupm = "PASS";
array_push($acpi_results, $acpi_cpupm);

$acpi_thermal_zone = "FAIL";
foreach(glob("/proc/acpi/thermal_zone/*/temperature") as $temperature_file)
	if($acpi_thermal_zone == "FAIL")
		if(strlen(read_delimit(file_get_contents($temperature_file), "temperature")) > 1)
			$acpi_thermal_zone = "PASS";
array_push($acpi_results, $acpi_thermal_zone);

$acpi_suspend = "FAIL";
if(is_file("/proc/acpi/sleep") && strpos(($sleep_file = file_get_contents("/proc/acpi/sleep")), "S3") > 0 && strpos($sleep_file, "S4") > 0)
	$acpi_suspend = "PASS";
array_push($acpi_results, $acpi_suspend);

echo implode(",", $acpi_results) . "\n";

?>
EOT

cat > compliance-acpi << 'EOT'
#!/bin/sh
php acpi-checks
EOT
chmod +x compliance-acpi