| 1 |
#!/usr/bin/env python3 |
| 2 |
# |
| 3 |
# Copyright (c) 2021-2022 Paul Mattes. |
| 4 |
# All rights reserved. |
| 5 |
# |
| 6 |
# Redistribution and use in source and binary forms, with or without |
| 7 |
# modification, are permitted provided that the following conditions are met: |
| 8 |
# * Redistributions of source code must retain the above copyright |
| 9 |
# notice, this list of conditions and the following disclaimer. |
| 10 |
# * Redistributions in binary form must reproduce the above copyright |
| 11 |
# notice, this list of conditions and the following disclaimer in the |
| 12 |
# documentation and/or other materials provided with the distribution. |
| 13 |
# * Neither the names of Paul Mattes nor the names of his contributors |
| 14 |
# may be used to endorse or promote products derived from this software |
| 15 |
# without specific prior written permission. |
| 16 |
# |
| 17 |
# THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 |
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 |
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 20 |
# EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 |
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 |
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 |
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 |
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 |
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
# |
| 28 |
# tcl3270 smoke tests |
| 29 |
|
| 30 |
import unittest |
| 31 |
from subprocess import Popen, PIPE, DEVNULL |
| 32 |
import tempfile |
| 33 |
import os |
| 34 |
import filecmp |
| 35 |
import sys |
| 36 |
import Common.Test.playback as playback |
| 37 |
import Common.Test.cti as cti |
| 38 |
|
| 39 |
@unittest.skipIf(sys.platform == "darwin", "macOS does not like tcl") |
| 40 |
class TestTcl3270Smoke(cti.cti): |
| 41 |
|
| 42 |
# tcl3270 3270 smoke test |
| 43 |
def test_tcl3270_smoke(self): |
| 44 |
|
| 45 |
# Start 'playback' to feed data to tcl3270. |
| 46 |
playback_port, ts = cti.unused_port() |
| 47 |
with playback.playback(self, 's3270/Test/ibmlink.trc', port=playback_port) as p: |
| 48 |
ts.close() |
| 49 |
|
| 50 |
# Create a temporary file. |
| 51 |
(handle, name) = tempfile.mkstemp() |
| 52 |
|
| 53 |
# Start tcl3270. |
| 54 |
tcl_port, ts = cti.unused_port() |
| 55 |
tcl3270 = Popen(cti.vgwrap(["tcl3270", "tcl3270/Test/smoke.tcl", name, "--", |
| 56 |
"-xrm", "tcl3270.contentionResolution: false", |
| 57 |
"-httpd", f"127.0.0.1:{tcl_port}", |
| 58 |
f"127.0.0.1:{playback_port}"]), |
| 59 |
stdin=DEVNULL, stdout=DEVNULL) |
| 60 |
self.children.append(tcl3270) |
| 61 |
self.check_listen(tcl_port) |
| 62 |
ts.close() |
| 63 |
|
| 64 |
# Send a screenful to tcl3270. |
| 65 |
p.send_records(4) |
| 66 |
|
| 67 |
# Wait for the file to show up. |
| 68 |
def Test(): |
| 69 |
return os.lseek(handle, 0, os.SEEK_END) > 0 |
| 70 |
self.try_until(Test, 2, "Script did not produce a file") |
| 71 |
os.close(handle) |
| 72 |
|
| 73 |
# Wait for the processes to exit. |
| 74 |
tcl3270.kill() |
| 75 |
self.children.remove(tcl3270) |
| 76 |
self.vgwait(tcl3270, assertOnFailure=False) |
| 77 |
|
| 78 |
# Compare the files |
| 79 |
self.assertTrue(filecmp.cmp(name, 'tcl3270/Test/smoke.txt')) |
| 80 |
os.unlink(name) |
| 81 |
|
| 82 |
if __name__ == '__main__': |
| 83 |
unittest.main() |