1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Stdcpp_test/stdcxx/testengine/src/system.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,120 @@
1.4 +/************************************************************************
1.5 + *
1.6 + * system.cpp - definitions of testsuite helpers
1.7 + *
1.8 + * $Id: system.cpp 290012 2005-09-18 23:38:12Z sebor $
1.9 + *
1.10 + ************************************************************************
1.11 + *
1.12 + * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
1.13 + * Software division. Licensed under the Apache License, Version 2.0 (the
1.14 + * "License"); you may not use this file except in compliance with the
1.15 + * License. You may obtain a copy of the License at
1.16 + * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
1.17 + * applicable law or agreed to in writing, software distributed under
1.18 + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
1.19 + * CONDITIONS OF ANY KIND, either express or implied. See the License
1.20 + * for the specific language governing permissions and limitations under
1.21 + * the License.
1.22 + *
1.23 + **************************************************************************/
1.24 +
1.25 +// expand _TEST_EXPORT macros
1.26 +#define _RWSTD_TEST_SRC
1.27 +
1.28 +#include <system.h>
1.29 +
1.30 +#include <driver.h>
1.31 +#include <printf.h>
1.32 +
1.33 +#include <stdarg.h> // for va_copy, va_list, ...
1.34 +#include <stdlib.h> // for system
1.35 +
1.36 +#if !defined (_WIN32) && !defined (_WIN64)
1.37 +# include <unistd.h>
1.38 +# include <sys/wait.h> // for WIFEXITED(), WIFSIGNALED(), WTERMSIG()
1.39 +#endif
1.40 +
1.41 +#ifdef __SYMBIAN32__
1.42 +#include <assert.h>
1.43 +#endif
1.44 +
1.45 +/**************************************************************************/
1.46 +
1.47 +_TEST_EXPORT int
1.48 +rw_vasnprintf (char**, size_t*, const char*, va_list);
1.49 +
1.50 +/**************************************************************************/
1.51 +
1.52 +static int
1.53 +_rw_vsystem (const char *cmd, va_list va)
1.54 +{
1.55 + _RWSTD_ASSERT (0 != cmd);
1.56 +
1.57 + char buffer [256];
1.58 + char *buf = buffer;
1.59 +
1.60 + size_t bufsize = sizeof buffer;
1.61 +
1.62 + rw_vasnprintf (&buf, &bufsize, cmd, va);
1.63 +
1.64 + rw_note (0, __FILE__, __LINE__,
1.65 + "executing \"%s\"", buf);
1.66 +
1.67 + const int ret = system (buf);
1.68 +
1.69 + if (ret) {
1.70 +
1.71 +#if !defined (_WIN32)
1.72 +
1.73 + if (-1 == ret) {
1.74 + // system() failed, e.g., because fork() failed
1.75 + rw_error (0, __FILE__, __LINE__,
1.76 + "system (\"%s\") failed: errno = %{#m} (%{m})", buf);
1.77 + }
1.78 + else if (WIFSIGNALED (ret)) {
1.79 + // command exited with a signal
1.80 + const int signo = WTERMSIG (ret);
1.81 +
1.82 + rw_error (0, __FILE__, __LINE__,
1.83 + "the command \"%s\" exited with signal %d (%{K})",
1.84 + buf, signo, signo);
1.85 + }
1.86 + else {
1.87 + // command exited with a non-zero status
1.88 + const int status = WEXITSTATUS (ret);
1.89 +
1.90 + rw_error (0, __FILE__, __LINE__,
1.91 + "the command \"%s\" exited with status %d",
1.92 + buf, status);
1.93 + }
1.94 +#else // if defined (_WIN32)
1.95 +
1.96 + // FIXME: make this more descriptive
1.97 + rw_error (0, __FILE__, __LINE__,
1.98 + "the command \"%s\" failed with code %d",
1.99 + buf, ret);
1.100 +
1.101 +#endif // _WIN32
1.102 +
1.103 + }
1.104 +
1.105 + if (buf != buffer)
1.106 + free (buf);
1.107 +
1.108 + return ret;
1.109 +}
1.110 +
1.111 +/**************************************************************************/
1.112 +
1.113 +_TEST_EXPORT int
1.114 +rw_system (const char *cmd, ...)
1.115 +{
1.116 + va_list va;
1.117 + va_start (va, cmd);
1.118 +
1.119 + const int ret = _rw_vsystem (cmd, va);
1.120 +
1.121 + va_end (va);
1.122 + return ret;
1.123 +}