SF Bug 2000 - test code for commandline parsing. fix
authorraptorbot <raptorbot@systemstesthead.symbian.intra>
Tue, 23 Feb 2010 19:02:48 +0000
branchfix
changeset 252 6846d05399b6
parent 251 64208ed747d4
child 253 c1e5ac1e307e
SF Bug 2000 - test code for commandline parsing. Also some better comments on other test files
sbsv2/raptor/util/talon/Makefile
sbsv2/raptor/util/talon/chomp.c
sbsv2/raptor/util/talon/chomp.h
sbsv2/raptor/util/talon/talon.c
sbsv2/raptor/util/talon/testbuffer.c
sbsv2/raptor/util/talon/testchomp.c
sbsv2/raptor/util/talon/testprocess.c
--- a/sbsv2/raptor/util/talon/Makefile	Mon Feb 22 22:24:20 2010 +0000
+++ b/sbsv2/raptor/util/talon/Makefile	Tue Feb 23 19:02:48 2010 +0000
@@ -21,6 +21,7 @@
 include $(SBS_HOME:\=/)/util/gccprogram.mk
 
 ifeq ($(filter win,$(HOSTPLATFORM)),win)
+CHOMP_C:=chomp.c
 PROCESS_C:=process_win.c
 CFLAGS:=-DHOST_WIN
 ifeq ($(SBS_MINGW),)
@@ -29,6 +30,7 @@
 LDFLAGS:=$(subst \,/,$(SBS_MINGW:\=/)\lib\libiberty.a)
 endif
 else
+CHOMP_C:=
 PROCESS_C:=process.c
 CFLAGS:=-g
 linux_PTHREADLIBS:=-lpthread
@@ -43,7 +45,7 @@
 MANIFEST:=$(SOURCEDIR)/manifest
 
 TARGET:=talon
-SOURCES:=$(addprefix $(SOURCEDIR)/,talon.c buffer.c sema.c log.c $(PROCESS_C))
+SOURCES:=$(addprefix $(SOURCEDIR)/,talon.c buffer.c sema.c log.c $(PROCESS_C) $(CHOMP_C)) 
 #$(info $(cprogram))
 $(eval $(cprogram))
 
@@ -63,3 +65,7 @@
 SOURCES:=$(addprefix $(SOURCEDIR)/,lock.c sema.c log.c)
 $(eval $(cprogram))
 
+TARGET:=testchomp
+SOURCES:=$(addprefix $(SOURCEDIR)/,testchomp.c chomp.c log.c)
+$(eval $(cprogram))
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/util/talon/chomp.c	Tue Feb 23 19:02:48 2010 +0000
@@ -0,0 +1,177 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+/*
+   Get rid of the path to talon from a commandline string on windows find the 
+   -c (if it's there) and step past it to after the quote on the first command:
+
+   "g:\program files\talon\talon.exe" -c "gcc -c . . ."
+                                          ^------ Returns a pointer to here
+
+   Take care of the possibilty that there might be spaces in the command
+   if it is quoted.
+
+   A state-machine is flexible but not all that easy to write.  Should investigate
+   the possiblity of using the Ragel state machine generator perhaps.
+
+*/
+#define CH_START 0
+#define CH_PRE 1
+#define CH_EXQUOTE 2
+#define CH_INQUOTE 3
+#define CH_POST 4
+#define CH_MINUS 5
+#define CH_C 6
+#define CH_PRECOMMAND 7
+#define CH_COMMAND 8
+#define CH_ERR 9
+
+#include "log.h"
+#include "chomp.h"
+
+char * chompCommand(char command[])
+{
+	char *result = command;
+	int state = CH_START;
+
+	while (state != CH_COMMAND && state != CH_ERR)
+	{
+		DEBUG(("startstate: %d, char %c ",state, *result));
+		switch (*result)
+		{
+			case ' ':
+				switch (state)
+				{
+					case CH_START:
+					case CH_PRE:
+						state = CH_PRE;
+						break;
+					case CH_EXQUOTE:
+						state = CH_POST;
+						break;
+					case CH_INQUOTE:
+						break;
+					case CH_POST:
+						break;
+					case CH_MINUS:
+						state = CH_C;
+						break;
+					case CH_C:
+						state = CH_PRECOMMAND;
+						break;
+					case CH_PRECOMMAND:
+						break;
+					default:
+						state = CH_ERR;
+						break;
+				}
+			break;
+			case 'c':
+				switch (state)
+				{
+					case CH_START:
+					case CH_PRE:
+						state = CH_EXQUOTE;
+						break;
+					case CH_EXQUOTE:
+					case CH_INQUOTE:
+						break;
+					case CH_POST:
+						state = CH_ERR;
+						break;
+					case CH_MINUS:
+						state = CH_C;
+						break;
+					case CH_C:
+					case CH_PRECOMMAND:
+					default:
+						state = CH_ERR;
+						break;
+				}
+			break;
+			case '-':
+				switch (state)
+				{
+					case CH_START:
+					case CH_PRE:
+						state = CH_EXQUOTE;
+						break;
+					case CH_EXQUOTE:
+					case CH_INQUOTE:
+						break;
+					case CH_POST:
+						state = CH_MINUS;
+						break;
+					case CH_MINUS:
+					case CH_C:
+					case CH_PRECOMMAND:
+					default:
+						state = CH_ERR;
+						break;
+				}
+			break;
+			case '"':
+				switch (state)
+				{
+					case CH_START:
+					case CH_PRE:
+					case CH_EXQUOTE:
+						state = CH_INQUOTE;
+						break;
+					case CH_INQUOTE:
+						state = CH_EXQUOTE;
+						break;
+					case CH_POST:
+					case CH_MINUS:
+					case CH_C:
+						state = CH_ERR;
+						break;
+					case CH_PRECOMMAND:
+						state = CH_COMMAND;
+						break;
+					default:
+						state = CH_ERR;
+						break;
+				}
+
+			break;
+			default:
+				switch (state)
+				{
+					case CH_START:
+					case CH_PRE:
+						state = CH_EXQUOTE;
+						break;
+					case CH_INQUOTE:
+					case CH_EXQUOTE:
+						break;
+					default:
+						state = CH_ERR;
+						break;
+				}
+			break;
+		}
+		DEBUG(("endstate: %d\n",state));
+		result ++;
+		
+	}
+
+	if (state == CH_ERR)
+		return (char *)0;
+
+	return result;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/util/talon/chomp.h	Tue Feb 23 19:02:48 2010 +0000
@@ -0,0 +1,21 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+#ifndef _CHOMP_H_
+#define _CHOMP_H_
+char * chompCommand(char command[]);
+#endif
--- a/sbsv2/raptor/util/talon/talon.c	Mon Feb 22 22:24:20 2010 +0000
+++ b/sbsv2/raptor/util/talon/talon.c	Tue Feb 23 19:02:48 2010 +0000
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
@@ -33,6 +33,10 @@
 #include "buffer.h"
 #include "../config.h"
 
+#ifdef HAS_GETCOMMANDLINE
+#include "chomp.h"
+#endif
+
 /* The output semaphore. */
 sbs_semaphore talon_sem;
 
@@ -222,166 +226,6 @@
 	return recipe;
 }
 
-#ifdef HAS_GETCOMMANDLINE
-/*
-   Get rid of the path to talon from a commandline string on windows find the 
-   -c (if it's there) and step past it to after the quote on the first command:
-
-   "g:\program files\talon\talon.exe" -c "gcc -c . . ."
-                                          ^------ Returns a pointer to here
-
-   Take care of the possibilty that there might be spaces in the command
-   if it is quoted.
-
-   A state-machine is flexible but not all that easy to write.  Should investigate
-   the possiblity of using the Ragel state machine generator perhaps.
-
-*/
-#define CH_START 0
-#define CH_PRE 1
-#define CH_EXQUOTE 2
-#define CH_INQUOTE 3
-#define CH_POST 4
-#define CH_MINUS 5
-#define CH_C 6
-#define CH_PRECOMMAND 7
-#define CH_COMMAND 8
-#define CH_ERR 9
-
-char * chompCommand(char command[])
-{
-	char *result = command;
-	int state = CH_START;
-
-	while (state != CH_COMMAND && state != CH_ERR)
-	{
-		DEBUG(("startstate: %d, char %c ",state, *result));
-		switch (*result)
-		{
-			case ' ':
-				switch (state)
-				{
-					case CH_START:
-					case CH_PRE:
-						state = CH_PRE;
-						break;
-					case CH_EXQUOTE:
-						state = CH_POST;
-						break;
-					case CH_INQUOTE:
-						break;
-					case CH_POST:
-						break;
-					case CH_MINUS:
-						state = CH_C;
-						break;
-					case CH_C:
-						state = CH_PRECOMMAND;
-						break;
-					case CH_PRECOMMAND:
-						break;
-					default:
-						state = CH_ERR;
-						break;
-				}
-			break;
-			case 'c':
-				switch (state)
-				{
-					case CH_START:
-					case CH_PRE:
-						state = CH_EXQUOTE;
-						break;
-					case CH_EXQUOTE:
-					case CH_INQUOTE:
-						break;
-					case CH_POST:
-						state = CH_ERR;
-						break;
-					case CH_MINUS:
-						state = CH_C;
-						break;
-					case CH_C:
-					case CH_PRECOMMAND:
-					default:
-						state = CH_ERR;
-						break;
-				}
-			break;
-			case '-':
-				switch (state)
-				{
-					case CH_START:
-					case CH_PRE:
-						state = CH_EXQUOTE;
-						break;
-					case CH_EXQUOTE:
-					case CH_INQUOTE:
-						break;
-					case CH_POST:
-						state = CH_MINUS;
-						break;
-					case CH_MINUS:
-					case CH_C:
-					case CH_PRECOMMAND:
-					default:
-						state = CH_ERR;
-						break;
-				}
-			break;
-			case '"':
-				switch (state)
-				{
-					case CH_START:
-					case CH_PRE:
-					case CH_EXQUOTE:
-						state = CH_INQUOTE;
-						break;
-					case CH_INQUOTE:
-						state = CH_EXQUOTE;
-						break;
-					case CH_POST:
-					case CH_MINUS:
-					case CH_C:
-						state = CH_ERR;
-						break;
-					case CH_PRECOMMAND:
-						state = CH_COMMAND;
-						break;
-					default:
-						state = CH_ERR;
-						break;
-				}
-
-			break;
-			default:
-				switch (state)
-				{
-					case CH_START:
-					case CH_PRE:
-						state = CH_EXQUOTE;
-						break;
-					case CH_INQUOTE:
-					case CH_EXQUOTE:
-						break;
-					default:
-						state = CH_ERR;
-						break;
-				}
-			break;
-		}
-		DEBUG((stderr,"endstate: %d\n",state));
-		result ++;
-		
-	}
-
-	if (state == CH_ERR)
-		return NULL;
-
-	return result;
-}
-#endif
-
 int main(int argc, char *argv[])
 {
 	/* find the argument to -c then strip the talon related front section */
--- a/sbsv2/raptor/util/talon/testbuffer.c	Mon Feb 22 22:24:20 2010 +0000
+++ b/sbsv2/raptor/util/talon/testbuffer.c	Tue Feb 23 19:02:48 2010 +0000
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
@@ -12,7 +12,10 @@
 * Contributors:
 *
 * Description: 
-*
+* This program reads from stdin into a "buffer" structure. It is designed to be
+* run from within valgrind to detect memory corruption errors.
+* The buffer is then written to /tmp/outfile where it can be compared
+* with the input to determine if they are the same
 */
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/util/talon/testchomp.c	Tue Feb 23 19:02:48 2010 +0000
@@ -0,0 +1,96 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+* This programs tests the chompCommand function used by talon.
+*/
+
+
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
+#include "chomp.h"
+#include "log.h"
+
+char *positives[] =  { 
+"c:\\apps\\talon.exe -c \"armcc -o barney.o\"", 
+"c:\\apps\\sbs2112-capabilites\\bin\\talon.exe -c \"armcc -o barney.o\"", 
+"\"c:\\apps and stuff\\talon.exe\" -c \"armcc -o barney.o\"", 
+"\"c:\\apps-can-cause-crxxx\\talon.exe\" -c \"armcc -o barney.o\"", 
+"c:\\bigspaces-\"   \"\\talon.exe -c \"armcc -o barney.o\"", 
+"c:\\bigspaces2\"   \"\\talon.exe -c \"armcc -o barney.o\"", 
+"c:\\apps\\talon.exe   -c   \"armcc -o barney.o\"", 
+"c:\\\"apps\"\\talon.exe   -c   \"armcc -o barney.o\"", 
+"c:\\\"ap ps\"\\talon.exe -c \"armcc -o barney.o\"", 
+(char *)0
+};
+
+char *negatives[] =  { 
+"c:\\apps\\talon.exe -c\"armcc -o barney.o\"", 
+"c:\\apps and stuff\\talon.exe -c \"armcc -o barney.o\"", 
+"c:\\apps\\talon.exe -c armcc -o barney.o", 
+"c:\\apps\\talon.exe commandlist.tmp", 
+(char *)0
+};
+
+char commandstr[]="armcc -o barney.o\"";
+
+int main(int argc, char *argv[])
+{
+	int i;
+	int errors = 0;
+	/* loglevel = LOGDEBUG; /* useful to leave this here */
+
+	for (i=0; positives[i] != (char *)0 ; i++)
+	{
+		char * c = chompCommand(positives[i]);
+		if (!c)
+		{
+			fprintf(stdout,"error: test failed with NULL on: %s\n", positives[i]);
+			errors++;
+			continue;
+		}
+
+		if (strcmp(commandstr, c) != 0)
+		{
+			fprintf(stdout,"error: test failed with %s on: %s\n", c,positives[i]);
+			errors++;
+			continue;
+		}
+		fprintf(stdout,"ok: %s\n", positives[i]);
+	}
+
+	for (i=0; negatives[i] != (char *)0 ; i++)
+	{
+		char * c = chompCommand(negatives[i]);
+		if (c)
+		{
+			fprintf(stdout,"error: negatice test failed with %s on: %s\n", c, negatives[i]);
+			errors++;
+			continue;
+		}
+		fprintf(stdout,"ok: negative: %s\n", negatives[i]);
+	}
+
+		
+	fprintf(stdout,"TOTAL errors: %d\n", errors);
+	return errors;
+}
--- a/sbsv2/raptor/util/talon/testprocess.c	Mon Feb 22 22:24:20 2010 +0000
+++ b/sbsv2/raptor/util/talon/testprocess.c	Tue Feb 23 19:02:48 2010 +0000
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
@@ -12,7 +12,11 @@
 * Contributors:
 *
 * Description: 
-*
+* This programs tests the process execution functions in talon.
+* it executes it's first argument with the following arguments 
+* as parameters to it.  Output is buffered and finally printed.
+* Should be run from within valgrind if possible to detect memory
+* corruption errors.
 */