[ci skip] update generated files
[scons.git] / test / Rpcgen / live.py
blob1e31694ee1f336467171754a04f1c4c4db0ed738
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verifies correct use of a live rpcgen command.
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
34 _exe = TestSCons._exe
36 test = TestSCons.TestSCons()
38 rpcgen = test.where_is('rpcgen')
39 if not rpcgen:
40 test.skip_test('Can not find installed "rpcgen", skipping test.\n')
42 test.subdir('do_rpcgen')
44 test.write('SConstruct', """\
45 import os
46 env = Environment(ENV=os.environ)
47 if env['PLATFORM'] == 'darwin':
48 # The generated rpcif_clnt.c file uses memset() without the necessary
49 # #include <stdlib.h> to get the declarations right. Suppress the
50 # warnings so the test passes.
51 env.Append(CCFLAGS=['-w'])
53 # on some Linux systems, RPC support has moved to libtirpc. Check for that.
54 conf = Configure(env)
55 env.Append(CPPPATH=['/usr/include/tirpc'])
56 if conf.CheckLibWithHeader('tirpc', 'rpc/rpc.h', 'c'):
57 env.Append(LIBS=['tirpc'])
58 env = conf.Finish()
60 env.Program('rpcclnt', ['rpcclnt.c', 'do_rpcgen/rpcif_clnt.c'])
61 env.RPCGenHeader('do_rpcgen/rpcif')
62 env.RPCGenClient('do_rpcgen/rpcif')
63 env.RPCGenService('do_rpcgen/rpcif')
64 env.RPCGenXDR('do_rpcgen/rpcif')
65 """)
67 test.write(['do_rpcgen', 'rpcif.x'], """\
68 program RPCTEST_IF
70 version RPCTEST_IF_VERSION
72 int START(unsigned long) = 1;
73 int STOP(unsigned long) = 2;
74 int STATUS(unsigned long) = 3;
75 } = 1; /* version */
76 } = 0xfeedf00d; /* portmap program ID */
77 """)
79 # Following test tries to make sure it can compile and link, but when
80 # it's run it doesn't actually invoke any rpc operations because that
81 # would have significant dependencies on network configuration,
82 # portmapper, etc. that aren't necessarily appropriate for an scons
83 # test.
85 test.write('rpcclnt.c', """\
86 #include <rpc/rpc.h>
87 #include <rpc/pmap_clnt.h>
88 #include "do_rpcgen/rpcif.h"
90 int main(int argc, char **args) {
91 const char* const SERVER = "localhost";
92 CLIENT *cl;
93 int *rslt;
94 unsigned long arg = 0;
95 if (argc > 2) {
96 cl = clnt_create( SERVER, RPCTEST_IF, RPCTEST_IF_VERSION, "udp" );
97 if (cl == 0 ) { return 1; }
98 rslt = start_1(&arg, cl);
99 if (*rslt == 0) { clnt_perror( cl, SERVER ); return 1; }
100 clnt_destroy(cl);
101 } else
102 printf("Hello!\\n");
103 return 0;
105 """)
108 test.run()
110 test.run(program=test.workpath('rpcclnt'+_exe))
112 test.fail_test(not test.stdout() in ["Hello!\n", "Hello!\r\n"])
116 test.pass_test()
118 # Local Variables:
119 # tab-width:4
120 # indent-tabs-mode:nil
121 # End:
122 # vim: set expandtab tabstop=4 shiftwidth=4: