File: PluginTest.cc

package info (click to toggle)
libzypp 17.25.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,144 kB
  • sloc: cpp: 94,656; xml: 2,575; sh: 700; makefile: 34; python: 12
file content (207 lines) | stat: -rw-r--r-- 4,575 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "Tools.h"

#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>

#include <zypp/base/PtrTypes.h>
#include <zypp/base/Exception.h>
#include <zypp/base/Gettext.h>
#include <zypp/base/LogTools.h>
#include <zypp/base/Debug.h>
#include <zypp/base/Functional.h>
#include <zypp/base/IOStream.h>
#include <zypp/base/InputStream.h>
#include <zypp/base/ProvideNumericId.h>
#include <zypp/base/Flags.h>
#include <zypp/AutoDispose.h>

#include <zypp/PluginScript.h>
#include <zypp/PathInfo.h>


using namespace zypp;
using namespace zypp::functor;
using namespace zypp::ui;

///////////////////////////////////////////////////////////////////

static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );

///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////

static PluginScript scr( "/bin/cat" );

void repeat( const PluginFrame & f )
{
  if ( ! scr.isOpen() )
    scr.open();
  MIL << "--> " << f << endl;
  scr.send( f );
  PluginFrame r( scr.receive() );
  MIL << "<-- " << r << endl;
  if ( r != f )
    ERR << "send/receive does not match." << endl;
}

void send( const PluginFrame & f )
{
  if ( ! scr.isOpen() )
    scr.open();
  MIL << "--> " << f << endl;
  scr.send( f );
}


PluginFrame receive()
{
  if ( ! scr.isOpen() )
    scr.open();
  PluginFrame r( scr.receive() );
  MIL << "<-- " << r << endl;
  return r;
}

  /////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////

#define DOLOG(C) USR << #C << ": " << endl; C;

namespace zypp {
  namespace target {
    void testCommitPlugins( const Pathname & path_r );
  }
}

/******************************************************************
**
**      FUNCTION NAME : main
**      FUNCTION TYPE : int
*/
int main( int argc, char * argv[] )
try {
  --argc,++argv;
  zypp::base::LogControl::instance().logToStdErr();
  INT << "===[START]==========================================" << endl;
  //////////////////////////////////////////////////////////////////

  zypp::target::testCommitPlugins( "/tmp/pltest" );

  if ( 0 )
  {
  Pathname script( "PluginTest.py" );
  PluginScript plugin( script );
  USR << plugin << endl;

  DOLOG( plugin.open() );

  DOLOG( plugin.send( PluginFrame( "PLUGINBEGIN" ) ) );

  PluginFrame ret;
  DOLOG( ret = plugin.receive() );
  MIL << ret << endl;

  DOLOG( plugin.send( PluginFrame( "PLUGINEND" ) ) );
  DOLOG( ret = plugin.receive() );
  MIL << ret << endl;

  DOLOG( plugin.close() );
  }

  if ( 0 ) {
    Pathname script( ZConfig::instance().pluginsPath()/"system/spacewalkx" );
    if ( PathInfo( script ).isX() )
      try {
	PluginScript spacewalk( script );
	spacewalk.open();

	PluginFrame notify( "PACKAGESETCHANGED" );
	spacewalk.send( notify );

	PluginFrame ret( spacewalk.receive() );
	MIL << ret << endl;
	if ( ret.command() == "ERROR" )
	  ret.writeTo( WAR ) << endl;
      }
      catch ( const Exception & excpt )
      {
	WAR << excpt.asUserHistory() << endl;
      }
  }

  if ( 0 ) {
    Measure x( "" );
    PluginFrame f( "a" );
    f.setBody( std::string( 1020, '0' ) );
    if ( ! scr.isOpen() )
      scr.open();
    for ( unsigned i = 1; true; ++i )
    {
      try {
	MIL << "Receiving " << i << endl;
	PluginFrame ret( receive() );
      }
      catch ( const PluginScriptTimeout & excpt )
      {
	ERR << excpt << endl;
	scr.send( f );
      }
      catch ( const PluginScriptDiedUnexpectedly & excpt )
      {
	ERR << excpt << endl;
	ERR << scr << endl;
	scr.close();
	break;
      }
    }
  }

  if ( 0 ) {
    Measure x( "" );
    PluginFrame f( "a" );
    f.setBody( std::string( 10200, '0' ) );
    for ( unsigned i = 1; true; ++i )
    {
      try {
	MIL << "Sending " << i << endl;
	send( f );
      }
      catch ( const PluginScriptTimeout & excpt )
      {
	ERR << excpt << endl;
	::kill( scr.getPid(), SIGKILL);
      }
      catch ( const PluginScriptDiedUnexpectedly & excpt )
      {
	ERR << excpt << endl;
	ERR << scr << endl;
	scr.close();
	break;
      }
    }
  }

  //////////////////////////////////////////////////////////////////
  INT << "===[END]============================================" << endl << endl;
  zypp::base::LogControl::instance().logNothing();
  return 0;
}
catch ( const Exception & exp )
{
  INT << exp << endl << exp.historyAsString();
  throw;
}
catch (...)
{
  throw;
}