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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -18,8 +18,13 @@
|
|||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
#define kLaunchDaemonSignature "application/x-vnd.Haiku-launch_daemon"
|
#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
|
// Message constants
|
||||||
|
|||||||
@@ -341,8 +341,12 @@ BLaunchRoster::GetJobInfo(const char* name, BMessage& info)
|
|||||||
void
|
void
|
||||||
BLaunchRoster::_InitMessenger()
|
BLaunchRoster::_InitMessenger()
|
||||||
{
|
{
|
||||||
|
#ifdef TEST_MODE
|
||||||
|
port_id daemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME);
|
||||||
|
#else
|
||||||
// find the launch_daemon port
|
// find the launch_daemon port
|
||||||
port_id daemonPort = BPrivate::get_launch_daemon_port();
|
port_id daemonPort = BPrivate::get_launch_daemon_port();
|
||||||
|
#endif
|
||||||
port_info info;
|
port_info info;
|
||||||
if (daemonPort >= 0 && get_port_info(daemonPort, &info) == B_OK) {
|
if (daemonPort >= 0 && get_port_info(daemonPort, &info) == B_OK) {
|
||||||
BMessenger::Private(fMessenger).SetTo(info.team, daemonPort,
|
BMessenger::Private(fMessenger).SetTo(info.team, daemonPort,
|
||||||
|
|||||||
@@ -59,8 +59,10 @@ using namespace BSupportKit;
|
|||||||
using BSupportKit::BPrivate::JobQueue;
|
using BSupportKit::BPrivate::JobQueue;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TEST_MODE
|
||||||
static const char* kLaunchDirectory = "launch";
|
static const char* kLaunchDirectory = "launch";
|
||||||
static const char* kUserLaunchDirectory = "user_launch";
|
static const char* kUserLaunchDirectory = "user_launch";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
enum launch_options {
|
enum launch_options {
|
||||||
@@ -328,7 +330,11 @@ LaunchDaemon::LaunchDaemon(bool userMode, const EventMap& events,
|
|||||||
userMode ? "AppPort" : B_LAUNCH_DAEMON_PORT_NAME), false, &error),
|
userMode ? "AppPort" : B_LAUNCH_DAEMON_PORT_NAME), false, &error),
|
||||||
fEvents(events),
|
fEvents(events),
|
||||||
fInitTarget(userMode ? NULL : new Target("init")),
|
fInitTarget(userMode ? NULL : new Target("init")),
|
||||||
|
#ifdef TEST_MODE
|
||||||
|
fUserMode(true)
|
||||||
|
#else
|
||||||
fUserMode(userMode)
|
fUserMode(userMode)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
mutex_init(&fTeamsLock, "teams lock");
|
mutex_init(&fTeamsLock, "teams lock");
|
||||||
|
|
||||||
@@ -437,12 +443,17 @@ LaunchDaemon::ReadyToRun()
|
|||||||
Utility::BlockMedia("/boot", true);
|
Utility::BlockMedia("/boot", true);
|
||||||
|
|
||||||
if (fUserMode) {
|
if (fUserMode) {
|
||||||
|
#ifndef TEST_MODE
|
||||||
BLaunchRoster roster;
|
BLaunchRoster roster;
|
||||||
BLaunchRoster::Private(roster).RegisterSessionDaemon(this);
|
BLaunchRoster::Private(roster).RegisterSessionDaemon(this);
|
||||||
|
#endif // TEST_MODE
|
||||||
} else
|
} else
|
||||||
_InitSystem();
|
_InitSystem();
|
||||||
|
|
||||||
BStringList paths;
|
BStringList paths;
|
||||||
|
#ifdef TEST_MODE
|
||||||
|
paths.Add("/boot/home/test_launch");
|
||||||
|
#else
|
||||||
if (fUserMode) {
|
if (fUserMode) {
|
||||||
// System-wide user specific jobs
|
// System-wide user specific jobs
|
||||||
BPathFinder::FindPaths(B_FIND_PATH_DATA_DIRECTORY, kUserLaunchDirectory,
|
BPathFinder::FindPaths(B_FIND_PATH_DATA_DIRECTORY, kUserLaunchDirectory,
|
||||||
@@ -462,6 +473,7 @@ LaunchDaemon::ReadyToRun()
|
|||||||
|
|
||||||
BPathFinder::FindPaths(B_FIND_PATH_SETTINGS_DIRECTORY, kLaunchDirectory,
|
BPathFinder::FindPaths(B_FIND_PATH_SETTINGS_DIRECTORY, kLaunchDirectory,
|
||||||
fUserMode ? B_FIND_PATHS_USER_ONLY : B_FIND_PATHS_SYSTEM_ONLY, paths);
|
fUserMode ? B_FIND_PATHS_USER_ONLY : B_FIND_PATHS_SYSTEM_ONLY, paths);
|
||||||
|
#endif // TEST_MODE
|
||||||
_ReadPaths(paths);
|
_ReadPaths(paths);
|
||||||
|
|
||||||
BMessenger target(this);
|
BMessenger target(this);
|
||||||
@@ -1905,9 +1917,11 @@ LaunchDaemon::_SetupEnvironment()
|
|||||||
void
|
void
|
||||||
LaunchDaemon::_InitSystem()
|
LaunchDaemon::_InitSystem()
|
||||||
{
|
{
|
||||||
|
#ifndef TEST_MODE
|
||||||
_AddInitJob(new InitRealTimeClockJob());
|
_AddInitJob(new InitRealTimeClockJob());
|
||||||
_AddInitJob(new InitSharedMemoryDirectoryJob());
|
_AddInitJob(new InitSharedMemoryDirectoryJob());
|
||||||
_AddInitJob(new InitTemporaryDirectoryJob());
|
_AddInitJob(new InitTemporaryDirectoryJob());
|
||||||
|
#endif
|
||||||
|
|
||||||
fJobQueue.AddJob(fInitTarget);
|
fJobQueue.AddJob(fInitTarget);
|
||||||
}
|
}
|
||||||
@@ -1924,6 +1938,9 @@ LaunchDaemon::_AddInitJob(BJob* job)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TEST_MODE
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
open_stdio(int targetFD, int openMode)
|
open_stdio(int targetFD, int openMode)
|
||||||
{
|
{
|
||||||
@@ -1939,6 +1956,9 @@ open_stdio(int targetFD, int openMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TEST_MODE
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@@ -1947,10 +1967,12 @@ main()
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TEST_MODE
|
||||||
// Make stdin/out/err available
|
// Make stdin/out/err available
|
||||||
open_stdio(STDIN_FILENO, O_RDONLY);
|
open_stdio(STDIN_FILENO, O_RDONLY);
|
||||||
open_stdio(STDOUT_FILENO, O_WRONLY);
|
open_stdio(STDOUT_FILENO, O_WRONLY);
|
||||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||||
|
#endif
|
||||||
|
|
||||||
EventMap events;
|
EventMap events;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|||||||
@@ -2,9 +2,14 @@ SubDir HAIKU_TOP src tests servers launch ;
|
|||||||
|
|
||||||
AddSubDirSupportedPlatforms libbe_test ;
|
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 servers launch ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits app ] ;
|
||||||
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin ] ;
|
||||||
|
|
||||||
UnitTestLib liblaunch_daemontest.so :
|
UnitTestLib liblaunch_daemontest.so :
|
||||||
LaunchDaemonTestAddon.cpp
|
LaunchDaemonTestAddon.cpp
|
||||||
@@ -21,3 +26,34 @@ UnitTestLib liblaunch_daemontest.so :
|
|||||||
|
|
||||||
: be network bnetapi shared [ TargetLibstdc++ ] [ TargetLibsupc++ ]
|
: 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
|
||||||
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user