Commit Graph

40 Commits (91fa31c065a582b9ead8a3d2f537c9b3d72474ee)

Author SHA1 Message Date
Nat Goodspeed adb3f447b3 DRTVWR-493: Introduce test catch_what(), catch_llerrs() functions.
Use them in place of awkward try/catch test boilerplate.
2019-08-10 20:33:59 -04:00
Nat Goodspeed c4096f670c SL-10153: Review and rationalize fetching paths from environment.
Use LLStringUtil::getenv() or getoptenv() whenever we fetch a string that will
be used as a pathname.

Use LLFile::tmpdir() instead of getenv("TEMP").

As an added extra-special bonus, finally clean up $TMP/llcontrol-test-zzzzzz
directories that have been accumulating every time we run a local build!
2018-12-14 15:38:13 -05:00
Callum Prentice 9dd7c67012 Pull in improvements to LLProcess termination via a commit from Nat Linden here: 4f39500cb4?at=default 2017-04-19 16:50:56 -07:00
Oz Linden c8726aba30 remove execute permission from many files that should not have it 2015-11-10 09:48:56 -05:00
Nat Goodspeed a2bb483f2d Disambiguate a few ensure() calls.
These were of the form ensure(std::string, something convertible to bool). Not
sure what the ambiguity was, but ensure(std::string, bool(something)) works
better.
2014-12-11 13:12:20 -05:00
Richard Linden 52da9f5f49 merge with viewer-release 2013-09-09 18:58:41 -07:00
Richard Linden 0b96a0e80c BUILDFIX: corrected template parameter for LL_BAD_TEMPLATE_INSTANTIATION macro in llunit 2013-08-26 18:37:07 -07:00
Richard Linden 4c7f489629 BUILDFIX: replaced function that was accidentally removed 2013-08-23 15:02:37 -07:00
Richard Linden a77f424945 BUILDFIX: fix for crashes in unit tests on mac and linux 2013-08-23 13:41:51 -07:00
Nat Goodspeed c5c412469a MAINT-2302: Make llprocess test<6> output less like a build error.
build.sh LogScan greps for "error:" (among other things) so removing the colon
from the test name "syntax_error" should help.
2013-06-29 10:12:30 -04:00
Nat Goodspeed 92d184847a MAINT-2302: Re-enable previously-disabled LLProcess tests for diagnosis. 2013-06-29 10:10:51 -04:00
Graham Madarasz fd447189c5 Merge 3.5.1 into Materials 2013-04-25 21:00:16 -07:00
Oz Linden 8fe17529c6 fix? race condition that occasionally fails in unit test 2013-04-09 15:57:23 -04:00
Graham Madarasz bf6182daa8 Update Mac and Windows breakpad builds to latest 2013-03-29 07:50:08 -07:00
Oz Linden dfc3faf240 workaround by skipping llprocess tests that frequently fail on Windows 2013-01-31 10:33:39 -05:00
Nat Goodspeed 7d3cf544c7 Add timeout functionality to waitfor() helper functions.
Otherwise, a stuck child process could potentially hang the test, and thus the
whole viewer build.
2012-03-13 14:15:11 -04:00
Nat Goodspeed f904867720 Make CaptureLog::withMessage() raise tut::failure if not found.
All known callers were using ensure(! withMessage(...).empty()). Centralize
that logic. Make failure message report the string being sought and the log
messages in which it wasn't found.
In case someone does want to permit the search to fail, add an optional
'required' parameter, default true.
Leverage new functionality in llprocess_test.cpp.
2012-03-01 14:33:23 -05:00
Nat Goodspeed 2596816f31 Break out TestRecorder class as CaptureLog into wrapllerrs.h.
Giving more unit tests the ability to capture and examine log output is
generally useful. Renaming the class just makes it less ambiguous: what's a
TestRecorder? Something that records tests?
2012-03-01 13:43:52 -05:00
Nat Goodspeed 3649eda62a Guarantee LLProcess::Params::postend listener any ReadPipe data.
Previously one might get process-terminated notification but still have to
wait for the child process's final data to arrive on one or more ReadPipes.
That required complex consumer timing logic to handle incomplete pending
ReadPipe data, e.g. a partial last line with no terminating newline. New code
guarantees that by the time LLProcess sends process-terminated notification,
all pending pipe data will have been buffered in ReadPipes.
Document LLProcess::ReadPipe::getPump() notification event; add "eof" key.
Add LLProcess::ReadPipe::getline() and read() convenience methods.
Add static LLProcess::getline() and basename() convenience methods, publishing
logic already present elsewhere.
Use ReadPipe::getline() and read() in unit tests.
Add unit test for "eof" event on ReadPipe::getPump().
Add unit test verifying that final data have been buffered by termination
notification event.
2012-02-29 17:10:19 -05:00
Nat Goodspeed 7fd281ac99 Reduce redundancy in llprocess_test.cpp using get_test_name(). 2012-02-27 15:24:14 -05:00
Nat Goodspeed 14ddc6474a Tighten up LLProcess pipe support, per Richard's code review.
Clarify wording in some of the doc comments; be a bit more explicit about some
of the parameter fields.
Make some query methods 'const'.
Change default LLProcess::ReadPipe::getLimit() value to 0: don't post any
incoming data with notification event unless caller requests it. But do post
pertinent FILESLOT in case caller reuses same listener for both stdout and
stderr.
Use more idiomatic, readable syntax for accessing LLProcess::Params data.
2012-02-23 13:41:26 -05:00
Nat Goodspeed 999484a608 Let LLProcess consumer specify desired description for logging.
If caller runs (e.g.) a Python script, it's not very helpful to a human log
reader to keep seeing LLProcess instances logged as /pathname/to/python (pid).
If caller is aware, the code can at least use the script name as the desc --
or maybe even a hint as to the script's purpose.
If caller doesn't explicitly pass a desc, at least shorten to just the
basename of the executable.
2012-02-20 14:22:32 -05:00
Nat Goodspeed 8b5d5f9652 Make LLProcess post termination event to specified pump if desired.
This way a caller need not spin on isRunning(); we can just listen for the
requested termination event.
Post a similar event containing error message if for any reason
LLProcess::create() failed to launch the child.
Add unit tests for both cases.
2012-02-20 12:40:38 -05:00
Nat Goodspeed f52cf4be70 Fix typos in a few LLProcess::ReadPipe::find() unit tests.
The typos didn't make for invalid tests, but they made a few tests redundant
while leaving other (subtly different) cases untested.
2012-02-16 21:10:06 -05:00
Nat Goodspeed a06ba836c7 Fix bug in LLProcess::ReadPipe::peek() substring computation.
Add unit tests for peek() with substring args, reimplemented contains(),
various forms of find().
(yay unit tests)
2012-02-16 17:35:34 -05:00
Nat Goodspeed 4ecf9d6a2d Add unit test for LLProcess::ReadPipe::setLimit(). 2012-02-16 16:40:14 -05:00
Nat Goodspeed e92c311354 Add LLProcess::ReadPipe::find() methods, with corresponding npos.
If it's useful to have contains() to tell you whether incoming data contains a
particular substring, and if it's useful for contains() and peek() to accept
an offset within that data, then it's useful to allow you to get the offset of
a desired substring within that data. But of course a find() returning offset
needs something like std::string::npos for "not found"; borrow that
convention.
Support both find(const std::string&) and find(char); the latter permits a
more efficient implementation. In fact, make find(string) recognize a string
of length 1 and leverage the find(char) implementation.
Given that, reimplement contains(mumble) as shorthand for find(mumble) != npos.
Implement find() overloads using std::search() and std::find() on
boost::asio::streambuf character iterators, rather than copying to std::string
and then using string search like previous contains() implementation.
Reimplement WritePipeImpl::tick() and ReadPipeImpl::tick() to write/read
directly from/to boost::asio::streambuf data, instead of copying to/from a
temporary flat buffer.
As long as ReadPipeImpl::tick() keeps successfully filling buffers, keep
reading. Previous implementation would only handle a long child write over
successive tick() calls. Stop on read error or when we come up short.
2012-02-16 16:05:04 -05:00
Nat Goodspeed 85057908c3 Add unit test for listening on LLProcess::ReadPipe::getPump(). 2012-02-15 21:55:53 -05:00
Nat Goodspeed fc6d70db87 Don't be confused by "\r\n" line endings on pipe on Windows.
These are all very well when we just want to dump the output to a log, or
whatever, but in a unit-test context it matters for comparison.
2012-02-15 20:57:25 -05:00
Nat Goodspeed 56d931216e Add LLProcess::ReadPipe::size(), peek(), contains().
Also add "len" key to event data on LLProcess::getPump(). If you've used
setLimit(), event["data"].length() may not reflect the length of the
accumulated data in the ReadPipe.
Add unit test with stdin/stdout handshake with child process.
2012-02-15 15:47:03 -05:00
Nat Goodspeed 10ab4adc86 Fix llprocess_test.cpp's exception catching for Linux.
In the course of re-enabling the indra/test tests last year, Log generalized a
workaround I'd introduced in llsdmessage_test.cpp. In Linux viewer land, a
test program trying to catch an expected exception can't seem to catch it by
its specific class (across the libllcommon.so boundary), but must instead
catch std::runtime_error and validate the typeid().name() string. Log added a
macro for this idiom in llevents_tut.cpp. Generalize that macro further for
normal-case processing as well, move it to a header file of its own and use it
in all known places -- plus the new exception-catching tests in
llprocess_test.cpp.
2012-02-15 13:44:43 -05:00
Nat Goodspeed c6ccdb5b50 Add tests for LLProcess::get[Opt][Read|Write]Pipe() validations. 2012-02-15 12:11:38 -05:00
Nat Goodspeed e239cad1f5 Preliminary pipe support for LLProcess.
Add LLProcess::FileParam to specify how to construct each child's standard
file slot, with lots of comments about features designed but not yet
implemented. The point is to design it with enough flexibility to be able to
extend to foreseeable use cases.
Add LLProcess::Params::files to collect up to 3 FileParam items. Naturally
this extends the accepted LLSD syntax as well.
Implement type="" (child inherits parent file descriptor) and "pipe" (parent
constructs anonymous pipe to pass to child).
Add LLProcess::FILESLOT enum, plus methods:
getReadPipe(FILESLOT), getOptReadPipe(FILESLOT)
getWritePipe(), getOptWritePipe()
getPipeName(FILESLOT): placeholder implementation for now
Add LLProcess::ReadPipe and WritePipe classes, as returned by get*Pipe().
WritePipe supports get_ostream() method for streaming to child stdin.
ReadPipe supports get_istream() method for reading from child stdout/stderr.
It also provides getPump() returning LLEventPump& so interested parties can
listen for arrival of new data on the aforementioned std::istream.
For "pipe" slots, instantiate appropriate *Pipe class.
ReadPipe and WritePipe classes are pure virtual bases for ReadPipeImpl and
WritePipeImpl, respectively: all implementation data are hidden in the latter
classes, visible only in llprocess.cpp. In fact each *PipeImpl class registers
itself for "mainloop" ticks, attempting nonblocking I/O to the underlying
apr_file_t on each tick. Data are buffered in a boost::asio::streambuf, which
bridges between std::[io]stream and the APR I/O calls.
Sanity-test ReadPipeImpl by using a pipe to absorb the Python "SyntaxError"
output from the successful syntax_error test, rather than alarming the user.
Add first few unit tests for validating FileParam. More tests coming!
2012-02-15 10:07:09 -05:00
Nat Goodspeed aae61392be Use per-frame ticks on "mainloop" LLEventPump to update LLProcess.
When we reimplemented LLProcess on APR, necessitating APR's funny callback
mechanism to sense child-process status, every isRunning() or getStatus() call
called the APR poll function that calls ALL registered LLProcess callbacks. In
other words, every time any consumer called any LLProcess::isRunning() method,
all LLProcess callbacks were redundantly fired. Change that so that the single
APR poll function is called once per frame, courtesy of the "mainloop"
LLEventPump. Once per viewer frame should be well within the realtime duration
in which it's reasonable to expect child-process status to change.
In effect, this changes LLProcess's public API to introduce a dependency on
"mainloop" ticks. Add such ticks to llprocess_test.cpp as well.
2012-02-13 17:38:25 -05:00
Nat Goodspeed d4f887e43c Add unit tests for LLProcess::Status functionality. 2012-02-13 16:18:46 -05:00
Nat Goodspeed 32e11494ff Use os.path.normcase(os.path.normpath()) when comparing directories.
Once again we've been bitten by comparison failure between "c:\somepath" and
"C:\somepath". Normalize paths in both Python helper scripts to make that
comparison more robust.
2012-02-07 12:28:57 -05:00
Nat Goodspeed aafb03b29f Convert LLProcess implementation from platform-specific to using APR.
Include logic to engage Linden apr_procattr_autokill_set() extension: on
Windows, magic CreateProcess() flag must be pushed down into apr_proc_create()
level. When using an APR package without that extension, present
implementation should lock (e.g.) SLVoice.exe lifespan to viewer's on Windows
XP but probably won't on Windows 7: need magic flag on CreateProcess().
Using APR child-termination callback requires us to define state (e.g.
LLProcess::RUNNING). Take the opportunity to present Status, capturing state
and (if terminated) rc or signal number; but since most of the time all caller
really wants is to log the outcome, also present status string, encapsulating
logic to examine state and describe exited-with-rc vs. killed-by-signal.
New Status logic may report clearer results in the case of a Windows child
process killed by exception.
Clarify that static LLProcess::isRunning(handle) overload is only for use when
the original LLProcess object has been destroyed: really only for unit tests.
We necessarily retain our original platform-specific implementations for just
that one method. (Nonstatic isRunning() no longer calls static method.)
Clarify log output from llprocess_test.cpp in a couple places.
2012-02-07 10:53:23 -05:00
Nat Goodspeed 85581eefa6 Expose 'handle' as well as 'id' on LLProcess objects.
On Posix, these and the corresponding getProcessID()/getProcessHandle()
accessors produce the same pid_t value; but on Windows, it's useful to
distinguish an int-like 'id' useful to human log readers versus an opaque
'handle' for passing to platform-specific API functions. So make the
distinction in a platform-independent way.
2012-01-30 12:11:44 -05:00
Nat Goodspeed 47d9475707 Convert LLProcess consumers from LLSD to LLProcess::Params block.
Using a Params block gives compile-time checking against attribute typos. One
might inadvertently set myLLSD["autofill"] = false and only discover it when
things behave strangely at runtime; but trying to set myParams.autofill will
produce a compile error.
However, it's excellent that the same LLProcess::create() method can accept
either LLProcess::Params or a properly-constructed LLSD block.
2012-01-21 11:45:15 -05:00
Nat Goodspeed f0dbb87833 Per Richard, replace LLProcessLauncher with LLProcess.
LLProcessLauncher had the somewhat fuzzy mandate of (1) accumulating
parameters with which to launch a child process and (2) sometimes tracking the
lifespan of the ensuing child process. But a valid LLProcessLauncher object
might or might not have ever been associated with an actual child process.
LLProcess specifically tracks a child process. In effect, it's a fairly thin
wrapper around a process HANDLE (on Windows) or pid_t (elsewhere), with
lifespan management thrown in. A static LLProcess::create() method launches a
new child; create() accepts an LLSD bundle with child parameters. So building
up a parameter bundle is deferred to LLSD rather than conflated with the
process management object.
Reconcile all known LLProcessLauncher consumers in the viewer code base,
notably the class unit tests.
2012-01-20 18:10:40 -05:00