bin_PROGRAMS = tesh
-tesh_SOURCES = tesh.c
+tesh_SOURCES = tesh.c tesh.h buff.h buff.c signal.c
tesh_LDADD = $(top_builddir)/src/libsimgrid.la
TESTS_ENVIRONMENT=./tesh
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
-am_tesh_OBJECTS = tesh.$(OBJEXT)
+am_tesh_OBJECTS = tesh.$(OBJEXT) buff.$(OBJEXT) signal.$(OBJEXT)
tesh_OBJECTS = $(am_tesh_OBJECTS)
tesh_DEPENDENCIES = $(top_builddir)/src/libsimgrid.la
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src
target_os = @target_os@
target_vendor = @target_vendor@
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src/include
-tesh_SOURCES = tesh.c
+tesh_SOURCES = tesh.c tesh.h buff.h buff.c signal.c
tesh_LDADD = $(top_builddir)/src/libsimgrid.la
TESTS_ENVIRONMENT = ./tesh
TESTS = basic.tesh cd.tesh \
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buff.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tesh.Po@am__quote@
.c.o:
--- /dev/null
+/* $Id$ */
+
+/* buff -- buffers as needed by tesh */
+
+/* Copyright (c) 2007 Martin Quinson. */
+/* All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* specific to Borland Compiler */
+#ifdef __BORLANDDC__
+#pragma hdrstop
+#endif
+
+#include "buff.h"
+
+/**
+ ** Buffer code
+ **/
+
+void buff_empty(buff_t *b) {
+ b->used=0;
+ b->data[0]='\n';
+ b->data[1]='\0';
+}
+buff_t *buff_new(void) {
+ buff_t *res=malloc(sizeof(buff_t));
+ res->data=malloc(512);
+ res->size=512;
+ buff_empty(res);
+ return res;
+}
+void buff_free(buff_t *b) {
+ if (b) {
+ if (b->data)
+ free(b->data);
+ free(b);
+ }
+}
+void buff_append(buff_t *b, char *toadd) {
+ int addlen=strlen(toadd);
+ int needed_space=b->used+addlen+1;
+
+ if (needed_space > b->size) {
+ b->data = realloc(b->data, needed_space);
+ b->size = needed_space;
+ }
+ strcpy(b->data+b->used, toadd);
+ b->used += addlen;
+}
+void buff_chomp(buff_t *b) {
+ while (b->data[b->used] == '\n') {
+ b->data[b->used] = '\0';
+ if (b->used)
+ b->used--;
+ }
+}
+
+void buff_trim(buff_t* b) {
+ xbt_str_trim(b->data," ");
+ b->used = strlen(b->data);
+}
--- /dev/null
+/* $Id$ */
+
+/* buff -- buffers as needed by tesh */
+
+/* Copyright (c) 2007 Martin Quinson. */
+/* All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef TESH_BUFF_H
+#define TESH_BUFF_H
+
+#include "portable.h"
+#include "xbt/sysdep.h"
+#include "xbt/function_types.h"
+#include "xbt/log.h"
+#include "xbt/str.h"
+
+/**
+ ** Buffer code
+ **/
+typedef struct {
+ char *data;
+ int used,size;
+} buff_t;
+
+
+void buff_empty(buff_t *b);
+buff_t *buff_new(void);
+void buff_free(buff_t *b);
+void buff_append(buff_t *b, char *toadd);
+void buff_chomp(buff_t *b);
+void buff_trim(buff_t* b);
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* signal -- what TESH needs to know about signals */
+
+/* Copyright (c) 2007 Martin Quinson. */
+/* All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "tesh.h"
+#include <signal.h>
+
+typedef struct s_signal_entry {
+ const char* name;
+ int number;
+} s_signal_entry_t,* signal_entry_t;
+
+static const s_signal_entry_t signals[] = {
+ {"SIGHUP" ,SIGHUP},
+ {"SIGINT" ,SIGINT},
+ {"SIGQUIT" ,SIGQUIT},
+ {"SIGILL" ,SIGILL},
+ {"SIGTRAP" ,SIGTRAP},
+ {"SIGABRT" ,SIGABRT},
+ {"SIGFPE" ,SIGFPE},
+ {"SIGKILL" ,SIGKILL},
+ {"SIGBUS" ,SIGBUS},
+ {"SIGSEGV" ,SIGSEGV},
+ {"SIGSYS" ,SIGSYS},
+ {"SIGPIPE" ,SIGPIPE},
+ {"SIGALRM" ,SIGALRM},
+ {"SIGTERM" ,SIGTERM},
+ {"SIGURG" ,SIGURG},
+ {"SIGSTOP" ,SIGSTOP},
+ {"SIGTSTP" ,SIGTSTP},
+ {"SIGCONT" ,SIGCONT},
+ {"SIGCHLD" ,SIGCHLD},
+ {"SIGTTIN" ,SIGTTIN},
+ {"SIGTTOU" ,SIGTTOU},
+ {"SIGIO" ,SIGIO},
+ {"SIGXCPU" ,SIGXCPU},
+ {"SIGXFSZ" ,SIGXFSZ},
+ {"SIGVTALRM" ,SIGVTALRM},
+ {"SIGPROF" ,SIGPROF},
+ {"SIGWINCH" ,SIGWINCH},
+ {"SIGUSR1" ,SIGUSR1},
+ {"SIGUSR2" ,SIGUSR2},
+ {"SIG UNKNOWN" ,-1}
+};
+
+
+const char* signal_name(unsigned int got, char *expected) {
+ int i;
+
+ /* Make SIGBUS a synonym for SIGSEGV
+ (segfault leads to any of them depending on the system) */
+ if((got == SIGBUS) && !strcmp("SIGSEGV",expected))
+ got = SIGSEGV;
+
+ for (i=0; signals[i].number != -1; i++)
+ if (signals[i].number == got)
+ return (signals[i].name);
+
+ return "SIG UNKNOWN";
+}
#pragma hdrstop
#endif
-#include "portable.h"
-#include "xbt/sysdep.h"
-#include "xbt/function_types.h"
-#include "xbt/log.h"
-#include "xbt/str.h"
+#include "tesh.h"
#include <sys/types.h>
#include <sys/wait.h>
-/**
- ** Buffer code
- **/
-typedef struct {
- char *data;
- int used,size;
-} buff_t;
-
-static void buff_empty(buff_t *b) {
- b->used=0;
- b->data[0]='\n';
- b->data[1]='\0';
-}
-static buff_t *buff_new(void) {
- buff_t *res=malloc(sizeof(buff_t));
- res->data=malloc(512);
- res->size=512;
- buff_empty(res);
- return res;
-}
-static void buff_free(buff_t *b) {
- if (b) {
- if (b->data)
- free(b->data);
- free(b);
- }
-}
-static void buff_append(buff_t *b, char *toadd) {
- int addlen=strlen(toadd);
- int needed_space=b->used+addlen+1;
-
- if (needed_space > b->size) {
- b->data = realloc(b->data, needed_space);
- b->size = needed_space;
- }
- strcpy(b->data+b->used, toadd);
- b->used += addlen;
-}
-static void buff_chomp(buff_t *b) {
- while (b->data[b->used] == '\n') {
- b->data[b->used] = '\0';
- if (b->used)
- b->used--;
- }
-}
-
-static void buff_trim(buff_t* b)
-{
- xbt_str_trim(b->data," ");
- b->used = strlen(b->data);
-}
-
-typedef struct s_signal_entry
-{
- const char* name;
- int number;
-}s_signal_entry_t,* signal_entry_t;
-
-static const s_signal_entry_t signals[] =
-{
- {"SIGHUP" ,1},
- {"SIGINT" ,2},
- {"SIGQUIT" ,3},
- {"SIGILL" ,4},
- {"SIGTRAP" ,5},
- {"SIGABRT" ,6},
- {"SIGEMT" ,7},
- {"SIGFPE" ,8},
- {"SIGKILL" ,9},
- {"SIGBUS" ,10},
- {"SIGSEGV" ,11},
- {"SIGSYS" ,12},
- {"SIGPIPE" ,13},
- {"SIGALRM" ,14},
- {"SIGTERM" ,15},
- {"SIGURG" ,16},
- {"SIGSTOP" ,17},
- {"SIGTSTP" ,18},
- {"SIGCONT" ,19},
- {"SIGCHLD" ,20},
- {"SIGTTIN" ,21},
- {"SIGTTOU" ,22},
- {"SIGIO" ,23},
- {"SIGXCPU" ,24},
- {"SIGXFSZ" ,25},
- {"SIGVTALRM",26},
- {"SIGPROF" ,27},
- {"SIGWINCH" ,28},
- {"SIGINFO" ,29},
- {"SIGUSR1" ,30},
- {"SIGUSR2" ,31}
-};
-
-#define SIGMAX 31
-#define SIGUNKNW SIGMAX + 1
-
-/* returns the name of the signal from it number */
-const char*
-signal_name(unsigned int number);
-
/**
** Options
**/
return;
buff_chomp(output_got);
buff_chomp(output_wanted);
- buff_trim(output_got);
-buff_trim(output_wanted);
+ buff_trim(output_got);
+ buff_trim(output_wanted);
if ( output_got->used != output_wanted->used
|| strcmp(output_got->data, output_wanted->data)) {
/* Wait for child, and check why it terminated */
wait(&status);
- if (WIFSIGNALED(status) && strcmp(signal_name(WTERMSIG(status)),expected_signal)) {
- fprintf(stderr,"Child got signal %s instead of signal %s\n",signal_name(WTERMSIG(status)), expected_signal);
+ if (WIFSIGNALED(status) &&
+ strcmp(signal_name(WTERMSIG(status),expected_signal),
+ expected_signal)) {
+ fprintf(stderr,"Child got signal %s instead of signal %s\n",
+ signal_name(WTERMSIG(status),expected_signal),
+ expected_signal);
exit(WTERMSIG(status)+4);
}
return 0;
}
-const char*
-signal_name(unsigned int number)
-{
- if(number > SIGMAX)
- return "SIGUNKNW";
-
- /* special case of SIGSEGV and SIGBUS (be conditional of the implementation)*/
- if((number == SIGBUS) && strcmp("SIGBUS",expected_signal))
- number = SIGSEGV;
-
- return (signals[number - 1].name);
-}
--- /dev/null
+/* $Id$ */
+
+/* TESH (Test Shell) -- mini shell specialized in running test units */
+
+/* Copyright (c) 2007 Martin Quinson. */
+/* All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef TESH_H
+#define TESH_H
+
+/*** Buffers ***/
+/***************/
+#include "buff.h"
+
+/*** What we need to know about signals ***/
+/******************************************/
+/* return the name of a signal, aliasing SIGBUS to SIGSEGV since
+ segfault leads to any of them depending on the system */
+const char* signal_name(unsigned int got, char *expected);
+
+
+
+#endif /* TESH_H */