SubDir TOP misc-tests ;


# --------------------
# - Compilation
# --------------------

SetupHeadersHoG ;
UsePrivateSystemHeaders ;  # for HaikuControlLook.h

Application basic-layers :
	basics-layers.cpp
	;
Application bench-basic :
	bench-basic.cpp
	;

#xx Force recompilation in case hog_TEST_LEVEL changed (a new value of that constant does not by itself trigger a recompile of files that use it)...
Always [ FGristFiles basics-layers.o ] ;
Always [ FGristFiles bench-basic.o ] ;



# --------------------
# --- hog-test.run ---
# --------------------

# --config--

local LocalFS ;
local ClientServerFS ;
local IndexerFS ;

switch $(LayerLevel)
{
	case 6 : {
		LocalFS = " " ;  # enable *client-local* embedding of NTFS VFS plug-in (no vfs server)
		IndexerFS = " " ;
	}
	case [789] : {
		LocalFS = " " ;
		# give up on (permanent) use of client-server for now, as it would require either 1) move the indexer over to server (together with Ntfs) to match the distro and avoid corner-cases or 2) improving corner-cases support
		# (specifically, it seems fs_file_system.h assigns "out.device = (Genode::addr_t)this"... how come this does not affect the "distro" configuration though ?)
		#///ToDo: keep doing some regular probing/testing in client-server mode though!
#		ClientServerFS = " " ;  # enable vfs *server* (set variable to empty-ish but non-NULL value) and host NTFS driver there
		IndexerFS = " " ;
	}
	case * : {
	}
}

# --steps--

if $(LayerLevel) >= 7
{
	AddAudioComponents  hog-test.run  ;
}

if $(LayerLevel) >= 9
{
	AddNetworkingComponents  hog-test.run  ;
}


if $(ClientServerFS)
{
	AddComponentAsStart  hog-test.run : 2M :
		vfs : "name=\"vfs_ntfs\" caps=\"120\"" :
		"		<binary name=\"vfs\" />
		\		<provides> <service name=\"File_system\"/> </provides>
		\		<config ld_verbose=\"yes\" >
		\			<vfs>
		\				<block name=\"blockdev\"/>
		\				<dir name=\"export\">
		\					<dir name=\"raw_ntfs_1\">
		\						<fuse  block_path=\"/blockdev\"  writeable=\"yes_or_fallback_to_no\"/>
		\					</dir>
	#		\				<dir name=\"Hai_Part_1\">
	#		\					<indexer fs_path=\"/raw_ntfs_1\"/>  <!-- BQuery support, on top of ntfs-3g driver -->
	#		\				......
		\				</dir>
		\			</vfs>
		\			<default-policy
		\				label_prefix=\"\"
		\				root=\"/export/raw_ntfs_1\"
		\				writeable=\"yes\" />
		\		</config>
			"
		;
}

if $(LayerLevel) <= 1
{
	AddMinimumComponents hog-test.run ;
	AddHaikuDepLibs hog-test.run ;
}
else  # levels 2-9
{
	AddInteractiveComponents  hog-test.run ;
}

#///if hog_TEST_LEVEL >= 6...
if $(LayerLevel) >= 2
{
	AddRawComponent	hog-test.run : vfs_fuse.lib.so :	vfs_fuse.lib.so ;
	AddRawComponent	hog-test.run : vfs_indexer.lib.so :	vfs_indexer.lib.so	;
	
	NTFS_TEST_IMAGE_PATH =
		/tmp/hog_test_disk_image.raw
		;
	DiskNtfsBlank $(NTFS_TEST_IMAGE_PATH) ;
	
	if ! $(USE_DRV_MANAGER)
	{
		AddComponentService  hog-test.run
			: 10M
			: ahci  # was: ahci_drv
			: Block
			: "<config>
					<default-policy device=\"0\" writeable=\"yes\" />
				</config>
				"
			;
	}
}

# VFS foo = <block name=\"blockdev\"/> <dir name=\"ram_rw\"> <fuse block_path=\"/blockdev\"/> </dir> ;
#
#else
# VFS foo = <dir name=\"ram_rw\"> <ram/> </dir> ;
#}

AddComponentAsStart  hog-test.run
	: 27M
	: basic-layers
	: "name=\"basic-layers\" caps=\"240\""
	: "\		<config ld_verbose=\"yes\">
		\			<libc  rtc=\"/dev/rtc\" stdin=\"/dev/null\" stdout=\"/dev/log\" stderr=\"/dev/log\"/>
		\			<vfs>
		\				<dir name=\"dev\">
		\					<log/>
		\					<null/>
		\				</dir>
		\				<inline name=\"beos.mp3\">
		\					A real mp3 file would hold binary data here
		\				</inline>
			"
				$(LocalFS)"	\			<block name=\"blockdev\"/>"
			"
		\				<dir name=\"DataNtfs\">
			"
					$(LocalFS)"			<fuse  block_path=\"/blockdev\"  writeable=\"yes_or_fallback_to_no\"/>"  # use fuse_ntfs locally
					$(ClientServerFS)"					<fs/>"  # access fuse_ntfs remotely, at the vfs_ntfs server
			"
		\				</dir>
		\				<dir name=\"ram_rw\">
		\					<ram/>
		\				</dir>
		\				<dir name=\"boot\">
	# ... jam t7, otherwise just use a <ram> node:
	#						<ram/>
	#						<fuse block_path=\"/blockdev\"/>
			"
		\					$(IndexerFS)"	<indexer fs_path=\"/DataNtfs\"/>"
			"
								# we keep the indexer client-side and even the server-side ntfs is exposed "raw" (neither of which would not normally be done) since we do "invasive" correctness tests
		\				</dir>
		\			</vfs>
		\		</config>
		\		<route>
		\			<service name=\"Block\">
							# use label " default" (instead of "ahci-0" or "ahci-1" etc), so that driver/ahci(_drv) will be called (by driver_manager) with either port 0 or 1 or 2... dynamically
		\				<child name=\"drivers_init\" label=\"basic-layers: default\" />  <!-- for the USE_DRV_MANAGER case ; careful to preserve the whitespace in ' default' (see main.cc:399) -->
		\				<child name=\"ahci\" />  <!-- for the 'static drivers' case -->
		\			</service>
		\			<any-service>
		\				<parent/><any-child/>
		\			</any-service>
		\		</route>
	"
	;
	# NOTE on dynamic detection of AHCI ports:
	#   The "drivers_init -> dynamic" policies look like this:
	#
	#[init -> drivers_init -> report_rom]    <service name="Block">
	#[init -> drivers_init -> report_rom]            <policy label_suffix="ahci-0">
	#[init -> drivers_init -> report_rom]                    <child name="ahci"/>
	#[init -> drivers_init -> report_rom]            </policy>
	#......
	#[init -> drivers_init -> report_rom]            <policy label_suffix=" default">
	#[init -> drivers_init -> report_rom]                    <child name="ahci" label="ahci-0"/>
	#[init -> drivers_init -> report_rom]            </policy>
	#[init -> drivers_init -> report_rom]    </service>

#AddComponentClient  hog-test.run
#	: 2M
#	: top
#	;

RunQemu
	hog-test.run : $(NTFS_TEST_IMAGE_PATH)
	;


# --------------------
# --- hog-bench.run ---
# --------------------

AddMinimumComponents  hog-bench.run ;
AddHaikuDepLibs  hog-bench.run ;

AddPosixApp  hog-bench.run : 15M : 120 : bench-basic ;

RunQemu
	hog-bench.run
	;


