test-logging.phpt 1.79 KB
Newer Older
1 2 3 4 5
<?php
	$logfile = 'test.log';

	require_once('functions.phpt');

6
	@unlink($logfile);
7 8 9
	if (!libvirt_logfile_set($logfile, 1))
		bail('Cannot enable debug logging to test.log file');

10
	$conn = libvirt_connect('test:///default');
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
	if (!is_resource($conn))
		bail('Connection to default hypervisor failed');

	$res = libvirt_node_get_info($conn);
	if (!is_array($res))
		bail('Node get info doesn\'t return an array');

	if (!is_numeric($res['memory']))
		bail('Invalid memory size');
	if (!is_numeric($res['cpus']))
		bail('Invalid CPU core count');
	unset($res);

	if (!libvirt_connect_get_uri($conn))
		bail('Invalid URI value');

	if (!libvirt_connect_get_hostname($conn))
		bail('Invalid hostname value');

	if (!($res = libvirt_domain_get_counts($conn)))
		bail('Invalid domain count');

	if ($res['active'] != count( libvirt_list_active_domains($conn)))
		bail('Numbers of active domains mismatch');

	if ($res['inactive'] != count( libvirt_list_inactive_domains($conn)))
		bail('Numbers of inactive domains mismatch');

	if (libvirt_connect_get_hypervisor($conn) == false)
		echo "Warning: Getting hypervisor information failed!\n";

	if (libvirt_connect_get_maxvcpus($conn) == false)
		echo "Warning: Cannot get the maximum number of VCPUs per VM!\n";

	if (libvirt_connect_get_capabilities($conn) == false)
		bail('Invalid capabilities on the hypervisor connection');

48
	if (@libvirt_connect_get_information($conn) == false)
49 50 51 52 53 54 55 56 57
		bail('No information on the connection are available');

	unset($res);
	unset($conn);

	$fp = fopen($logfile, 'r');
	$log = fread($fp, filesize($logfile));
	fclose($fp);

58
	$ok = ((strpos($log, 'libvirt_connect: Connection')) &&
59 60 61 62 63 64 65 66 67
		(strpos($log, 'libvirt_connection_dtor: virConnectClose')));

	unlink($logfile);

	if (!$ok)
		bail('Missing entries in the log file');

	success( basename(__FILE__) );
?>