Added simple test_launch_daemon.

* Expects its config files in /boot/home/test_launch.
* Uses standard I/O, and is always in user mode.
* Also added test_launch_roster command that is able to talk to the test
  server like it does to the real thing.
This commit is contained in:
Axel Dörfler
2017-11-29 17:19:46 +01:00
parent 2028f6e7fa
commit e96835a9a4
4 changed files with 70 additions and 3 deletions
+7 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016, Haiku, Inc. All Rights Reserved.
* Copyright 2015-2017, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -18,8 +18,13 @@
namespace BPrivate {
#define kLaunchDaemonSignature "application/x-vnd.Haiku-launch_daemon"
#define B_LAUNCH_DAEMON_PORT_NAME "system:launch_daemon"
#ifdef TEST_MODE
# define B_LAUNCH_DAEMON_PORT_NAME "test:launch_daemon"
#else
# define B_LAUNCH_DAEMON_PORT_NAME "system:launch_daemon"
#endif
// Message constants
+4
View File
@@ -341,8 +341,12 @@ BLaunchRoster::GetJobInfo(const char* name, BMessage& info)
void
BLaunchRoster::_InitMessenger()
{
#ifdef TEST_MODE
port_id daemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME);
#else
// find the launch_daemon port
port_id daemonPort = BPrivate::get_launch_daemon_port();
#endif
port_info info;
if (daemonPort >= 0 && get_port_info(daemonPort, &info) == B_OK) {
BMessenger::Private(fMessenger).SetTo(info.team, daemonPort,
+22
View File
@@ -59,8 +59,10 @@ using namespace BSupportKit;
using BSupportKit::BPrivate::JobQueue;
#ifndef TEST_MODE
static const char* kLaunchDirectory = "launch";
static const char* kUserLaunchDirectory = "user_launch";
#endif
enum launch_options {
@@ -328,7 +330,11 @@ LaunchDaemon::LaunchDaemon(bool userMode, const EventMap& events,
userMode ? "AppPort" : B_LAUNCH_DAEMON_PORT_NAME), false, &error),
fEvents(events),
fInitTarget(userMode ? NULL : new Target("init")),
#ifdef TEST_MODE
fUserMode(true)
#else
fUserMode(userMode)
#endif
{
mutex_init(&fTeamsLock, "teams lock");
@@ -437,12 +443,17 @@ LaunchDaemon::ReadyToRun()
Utility::BlockMedia("/boot", true);
if (fUserMode) {
#ifndef TEST_MODE
BLaunchRoster roster;
BLaunchRoster::Private(roster).RegisterSessionDaemon(this);
#endif // TEST_MODE
} else
_InitSystem();
BStringList paths;
#ifdef TEST_MODE
paths.Add("/boot/home/test_launch");
#else
if (fUserMode) {
// System-wide user specific jobs
BPathFinder::FindPaths(B_FIND_PATH_DATA_DIRECTORY, kUserLaunchDirectory,
@@ -462,6 +473,7 @@ LaunchDaemon::ReadyToRun()
BPathFinder::FindPaths(B_FIND_PATH_SETTINGS_DIRECTORY, kLaunchDirectory,
fUserMode ? B_FIND_PATHS_USER_ONLY : B_FIND_PATHS_SYSTEM_ONLY, paths);
#endif // TEST_MODE
_ReadPaths(paths);
BMessenger target(this);
@@ -1905,9 +1917,11 @@ LaunchDaemon::_SetupEnvironment()
void
LaunchDaemon::_InitSystem()
{
#ifndef TEST_MODE
_AddInitJob(new InitRealTimeClockJob());
_AddInitJob(new InitSharedMemoryDirectoryJob());
_AddInitJob(new InitTemporaryDirectoryJob());
#endif
fJobQueue.AddJob(fInitTarget);
}
@@ -1924,6 +1938,9 @@ LaunchDaemon::_AddInitJob(BJob* job)
// #pragma mark -
#ifndef TEST_MODE
static void
open_stdio(int targetFD, int openMode)
{
@@ -1939,6 +1956,9 @@ open_stdio(int targetFD, int openMode)
}
#endif // TEST_MODE
int
main()
{
@@ -1947,10 +1967,12 @@ main()
return EXIT_FAILURE;
}
#ifndef TEST_MODE
// Make stdin/out/err available
open_stdio(STDIN_FILENO, O_RDONLY);
open_stdio(STDOUT_FILENO, O_WRONLY);
dup2(STDOUT_FILENO, STDERR_FILENO);
#endif
EventMap events;
status_t status;
+37 -1
View File
@@ -2,9 +2,14 @@ SubDir HAIKU_TOP src tests servers launch ;
AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders app shared storage support ;
UsePrivateHeaders app libroot shared storage support ;
UsePrivateSystemHeaders ;
UseHeaders [ FDirName $(HAIKU_TOP) src bin multiuser ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src servers launch ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits app ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin ] ;
UnitTestLib liblaunch_daemontest.so :
LaunchDaemonTestAddon.cpp
@@ -21,3 +26,34 @@ UnitTestLib liblaunch_daemontest.so :
: be network bnetapi shared [ TargetLibstdc++ ] [ TargetLibsupc++ ]
;
local defines = [ FDefines TEST_MODE=1 ] ;
SubDirCcFlags $(defines) ;
SubDirC++Flags $(defines) ;
Server test_launch_daemon :
LaunchDaemon.cpp
BaseJob.cpp
Conditions.cpp
Events.cpp
Job.cpp
NetworkWatcher.cpp
SettingsParser.cpp
Target.cpp
Utility.cpp
VolumeWatcher.cpp
Worker.cpp
:
be network bnetapi shared libmultiuser_utils.a [ TargetLibstdc++ ]
:
LaunchDaemon.rdef
;
BinCommand test_launch_roster :
LaunchRoster.cpp
launch_roster.cpp
:
be
;