| OLD | NEW |
| 1 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 1 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import struct | 6 import struct |
| 7 import subprocess | 7 import subprocess |
| 8 import tempfile | 8 import tempfile |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 nacl_launcher.NACL_PLUGIN_ASYNC_TO_CHILD_FD], | 60 nacl_launcher.NACL_PLUGIN_ASYNC_TO_CHILD_FD], |
| 61 stderr=write_fh) | 61 stderr=write_fh) |
| 62 if message is not None: | 62 if message is not None: |
| 63 fd2.imc_sendmsg(message, tuple([])) | 63 fd2.imc_sendmsg(message, tuple([])) |
| 64 del fd2 | 64 del fd2 |
| 65 self.assertEquals(proc.wait(), 127) | 65 self.assertEquals(proc.wait(), 127) |
| 66 output_lines = read_fh.read().split("\n") | 66 output_lines = read_fh.read().split("\n") |
| 67 self.assertIn(expected_line, output_lines) | 67 self.assertIn(expected_line, output_lines) |
| 68 | 68 |
| 69 def test_error_on_eof(self): | 69 def test_error_on_eof(self): |
| 70 self._TryStartupMessage(None, "Error receiving startup message") | 70 self._TryStartupMessage(None, "Error receiving startup message (5)") |
| 71 | 71 |
| 72 def test_error_on_missing_tag(self): | 72 def test_error_on_missing_tag(self): |
| 73 self._TryStartupMessage( | 73 self._TryStartupMessage( |
| 74 "", "Startup message does not have the expected tag") | 74 "", "Startup message (0 bytes) lacks the expected tag") |
| 75 | 75 |
| 76 def test_error_on_missing_body(self): | 76 def test_error_on_missing_body(self): |
| 77 self._TryStartupMessage("ARGS", "Startup message too small") | 77 self._TryStartupMessage("ARGS", "Startup message too small (4 bytes)") |
| 78 | 78 |
| 79 def test_error_on_truncated_body(self): | 79 def test_error_on_truncated_body(self): |
| 80 data = nacl_launcher.PackArgsMessage(["a", "b", "c"], []) | 80 data = nacl_launcher.PackArgsMessage(["a", "b", "c"], []) |
| 81 self._TryStartupMessage( | 81 self._TryStartupMessage( |
| 82 data[:-1], "Missing null terminator in argv list") | 82 data[:-1], "Unterminated argument string in startup message") |
| 83 data = nacl_launcher.PackArgsMessage(["a", "b", "c"], ["e", "f"]) | 83 data = nacl_launcher.PackArgsMessage(["a", "b", "c"], ["e", "f"]) |
| 84 self._TryStartupMessage( | 84 self._TryStartupMessage( |
| 85 data[:-1], "Missing null terminator in env list") | 85 data[:-1], "Unterminated environment string in startup message") |
| 86 | 86 |
| 87 def test_error_on_excess_data(self): | 87 def test_error_on_excess_data(self): |
| 88 data = nacl_launcher.PackArgsMessage(["a", "b"], ["c", "d"]) | 88 data = nacl_launcher.PackArgsMessage(["a", "b"], ["c", "d"]) |
| 89 self._TryStartupMessage( | 89 self._TryStartupMessage( |
| 90 data + "x", "Excess data in message body") | 90 data + "x", "Excess data (1 bytes) in startup message body") |
| 91 | 91 |
| 92 def test_error_on_overly_large_array_sizes(self): | 92 def test_error_on_overly_large_array_sizes(self): |
| 93 self._TryStartupMessage( | 93 self._TryStartupMessage( |
| 94 struct.pack("4sII", "ARGS", 0x20000, 0), | 94 struct.pack("4sII", "ARGS", 0x20000, 0), |
| 95 "argv/env too large") | 95 "Unterminated argument string in startup message") |
| 96 self._TryStartupMessage( | 96 self._TryStartupMessage( |
| 97 struct.pack("4sII", "ARGS", 0x20000, -0x18000 & 0xffffffff), | 97 struct.pack("4sII", "ARGS", 0x20000, -0x18000 & 0xffffffff), |
| 98 "argv/env too large") | 98 "Unterminated argument string in startup message") |
| 99 | 99 |
| 100 | 100 |
| 101 if __name__ == "__main__": | 101 if __name__ == "__main__": |
| 102 unittest.main() | 102 unittest.main() |
| OLD | NEW |