00001 /* 00002 * This file is part of testrunner-lite 00003 * 00004 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00005 * 00006 * Contact: Sami Lahtinen <ext-sami.t.lahtinen@nokia.com> 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * version 2.1 as published by the Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00020 * 02110-1301 USA 00021 * 00022 */ 00023 00024 #ifndef EXECUTOR_H 00025 #define EXECUTOR_H 00026 00027 #include <time.h> 00028 #include <unistd.h> 00029 00030 /* ------------------------------------------------------------------------- */ 00031 /* INCLUDES */ 00032 /* None */ 00033 00034 /* ------------------------------------------------------------------------- */ 00035 /* CONSTANTS */ 00036 /* None */ 00037 00038 /* ------------------------------------------------------------------------- */ 00039 /* MACROS */ 00040 00041 #define SHELLCMD "/bin/sh" 00042 /* shell options are 00043 * -l : Login shell. .profile is read upon login 00044 * -c : Execute a command. This must be the last option followed by a command 00045 */ 00046 #define SHELLCMD_ARGS "-c" 00047 #define SHELLCMD_ARGS_STR "-c" 00048 #define FAILURE_INFO_TIMEOUT "timeout" 00049 #define POLL_TIMEOUT_MS 100 00050 #define POLL_TIMEOUT_US (1000*POLL_TIMEOUT_MS) 00051 #define COMMON_SOFT_TIMEOUT 90 00052 #define COMMON_HARD_TIMEOUT 5 00053 00054 /* ------------------------------------------------------------------------- */ 00055 /* DATA TYPES */ 00056 /* ------------------------------------------------------------------------- */ 00057 struct _stream_data { 00058 unsigned char* buffer; 00059 int size; 00060 int length; 00061 }; 00062 00063 typedef struct _stream_data stream_data; 00064 00065 enum _stream_output_redirection { 00066 DONT_REDIRECT_OUTPUT = 0, 00067 REDIRECT_OUTPUT 00068 }; 00069 00070 struct _exec_data { 00071 /* input parameters */ 00072 int redirect_output; 00073 unsigned soft_timeout; /* in seconds, 0 = no timeout */ 00074 unsigned hard_timeout; /* after soft_timeout, 0 = no timeout */ 00075 /* output parameters */ 00076 pid_t pid; 00077 pid_t pgid; 00078 stream_data stdout_data; 00079 stream_data stderr_data; 00080 stream_data failure_info; 00081 time_t start_time; 00082 time_t end_time; 00083 int result; 00084 }; 00085 00086 typedef struct _exec_data exec_data; 00087 00088 /* ------------------------------------------------------------------------- */ 00089 /* FORWARD DECLARATIONS */ 00090 /* None */ 00091 00092 /* ------------------------------------------------------------------------- */ 00093 /* STRUCTURES */ 00094 /* None */ 00095 00096 /* ------------------------------------------------------------------------- */ 00097 /* FUNCTION PROTOTYPES */ 00098 void executor_init (testrunner_lite_options *opts); 00099 int execute(const char* command, exec_data* data); 00100 void init_exec_data(exec_data* data); 00101 void clean_exec_data(exec_data* data); 00102 void init_stream_data(stream_data* data, int allocate); 00103 void clean_stream_data(stream_data* data); 00104 void kill_pgroup(int pgroup, int sig); 00105 void executor_close (); 00106 /* ------------------------------------------------------------------------- */ 00107 #endif /* EXECUTOR_H */ 00108 /* End of file */ 00109