12
#include <zypp/base/PtrTypes.h>
13
#include <zypp/base/Exception.h>
14
#include <zypp/base/Gettext.h>
15
#include <zypp/base/LogTools.h>
16
#include <zypp/base/Debug.h>
17
#include <zypp/base/Functional.h>
18
#include <zypp/base/IOStream.h>
19
#include <zypp/base/InputStream.h>
20
#include <zypp/base/ProvideNumericId.h>
21
#include <zypp/base/Flags.h>
22
#include <zypp/AutoDispose.h>
24
#include <zypp/PluginScript.h>
25
#include <zypp/PathInfo.h>
30
using namespace zypp::functor;
31
using namespace zypp::ui;
33
///////////////////////////////////////////////////////////////////
35
static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
37
///////////////////////////////////////////////////////////////////
39
{ /////////////////////////////////////////////////////////////////
41
static PluginScript scr( "/bin/cat" );
43
void repeat( const PluginFrame & f )
47
MIL << "--> " << f << endl;
49
PluginFrame r( scr.receive() );
50
MIL << "<-- " << r << endl;
52
ERR << "send/receive does not match." << endl;
55
void send( const PluginFrame & f )
59
MIL << "--> " << f << endl;
68
PluginFrame r( scr.receive() );
69
MIL << "<-- " << r << endl;
73
/////////////////////////////////////////////////////////////////
75
///////////////////////////////////////////////////////////////////
77
#define DOLOG(C) USR << #C << ": " << endl; C;
81
void testCommitPlugins( const Pathname & path_r );
85
/******************************************************************
87
** FUNCTION NAME : main
88
** FUNCTION TYPE : int
90
int main( int argc, char * argv[] )
93
zypp::base::LogControl::instance().logToStdErr();
94
INT << "===[START]==========================================" << endl;
95
//////////////////////////////////////////////////////////////////
97
zypp::target::testCommitPlugins( "/tmp/pltest" );
101
Pathname script( "PluginTest.py" );
102
PluginScript plugin( script );
103
USR << plugin << endl;
105
DOLOG( plugin.open() );
107
DOLOG( plugin.send( PluginFrame( "PLUGINBEGIN" ) ) );
110
DOLOG( ret = plugin.receive() );
113
DOLOG( plugin.send( PluginFrame( "PLUGINEND" ) ) );
114
DOLOG( ret = plugin.receive() );
117
DOLOG( plugin.close() );
121
Pathname script( ZConfig::instance().pluginsPath()/"system/spacewalkx" );
122
if ( PathInfo( script ).isX() )
124
PluginScript spacewalk( script );
127
PluginFrame notify( "PACKAGESETCHANGED" );
128
spacewalk.send( notify );
130
PluginFrame ret( spacewalk.receive() );
132
if ( ret.command() == "ERROR" )
133
ret.writeTo( WAR ) << endl;
135
catch ( const Exception & excpt )
137
WAR << excpt.asUserHistory() << endl;
143
PluginFrame f( "a" );
144
f.setBody( std::string( 1020, '0' ) );
145
if ( ! scr.isOpen() )
147
for ( unsigned i = 1; true; ++i )
150
MIL << "Receiving " << i << endl;
151
PluginFrame ret( receive() );
153
catch ( const PluginScriptTimeout & excpt )
155
ERR << excpt << endl;
158
catch ( const PluginScriptDiedUnexpectedly & excpt )
160
ERR << excpt << endl;
170
PluginFrame f( "a" );
171
f.setBody( std::string( 10200, '0' ) );
172
for ( unsigned i = 1; true; ++i )
175
MIL << "Sending " << i << endl;
178
catch ( const PluginScriptTimeout & excpt )
180
ERR << excpt << endl;
181
::kill( scr.getPid(), SIGKILL);
183
catch ( const PluginScriptDiedUnexpectedly & excpt )
185
ERR << excpt << endl;
193
//////////////////////////////////////////////////////////////////
194
INT << "===[END]============================================" << endl << endl;
195
zypp::base::LogControl::instance().logNothing();
198
catch ( const Exception & exp )
200
INT << exp << endl << exp.historyAsString();