From f641e402385c734e6fd7f1a31bf720f6e9631382 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 13 Oct 2010 16:28:12 +0000 Subject: [PATCH] Fix SB #73206: - revision of the perl code generator (fixed jobid, notifid and timeval types, mainly in logging functions) - fixed toString perl method for logsrc (duplicated line) - new client API test (simple run for SEGV check) --- org.glite.lb.client/Makefile | 15 ++++- org.glite.lb.client/src/logevent.c.T | 36 ++++++----- org.glite.lb.client/src/uiwrap.T | 9 ++- org.glite.lb.client/src/uiwrap.c.T | 1 + org.glite.lb.client/test/api_test.cpp.T | 99 +++++++++++++++++++++++++++++++ org.glite.lb.common/interface/ulm_parse.h | 8 +++ org.glite.lb.types/types.T | 1 - 7 files changed, 147 insertions(+), 22 deletions(-) create mode 100644 org.glite.lb.client/test/api_test.cpp.T diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index 700e01f..902b9c1 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -274,7 +274,7 @@ perftest_logjobs.o: perftest_logjobs.c examples: ${EXAMPLES} ${EXAMPLES_PLUS} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} ${sh_PROGS} -check: compile +check: compile check.api # shut up check.producer check.producer: producer_test @@ -286,6 +286,15 @@ producer_test: producer_test.o prod_proto_test.o producer_test.o: %.o: %.cpp ${CXX} -c ${CXXFLAGS} ${TEST_INC} $< +check.api: api_test + ./api_test + +api_test.o: %.o: %.cpp uiwrap.c + ${CXX} -c ${CXXFLAGS} ${TEST_INC} $< + +api_test: api_test.o + ${LINKXX} -o $@ ${LIB} ${COMMON_LIB} ${TEST_LIBS} $+ ${EXT_LIB} + man: ${MAN_GZ} ${MAN8_GZ} stage: compile @@ -349,7 +358,7 @@ endif ${INSTALL} -m 644 ${top_srcdir}/m4/glite_lb.m4 ${PREFIX}/share/build/m4/ clean: - rm -rvf *.o *.lo .libs lib* *.c *.cpp *.h *.dox producer_test notify C/ CPP/ + rm -rvf *.o *.lo .libs lib* *.c *.cpp *.h *.dox producer_test api_test notify C/ CPP/ rm -rvf ${LIB} ${THRLIB} ${TOOLS} logevent register_sandbox ${PLUSLIB} ${THRPLUSLIB} ${MAN_GZ} ${MAN8_GZ} rm -rvf ${EXAMPLES} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} ${sh_PROGS} rm -f EventAttrNames.pl @@ -359,4 +368,4 @@ check_version: ${CHECK_VERSION} ${stagedir}/include/glite/lb/common_version.h -.PHONY: default all compile examples check stage install clean check_version +.PHONY: default all compile examples check stage install clean check_version check.producer check.api diff --git a/org.glite.lb.client/src/logevent.c.T b/org.glite.lb.client/src/logevent.c.T index c5dbe41..69658cf 100644 --- a/org.glite.lb.client/src/logevent.c.T +++ b/org.glite.lb.client/src/logevent.c.T @@ -36,6 +36,7 @@ limitations under the License. #include "glite/lb/events.h" #include "glite/lb/context.h" #include "glite/lb/context-int.h" +#include "glite/lb/ulm_parse.h" #include "producer.h" #include "args.h" @@ -269,30 +270,35 @@ $indent = "\t"; $event->getTypes) { my $tu = uc $t; - gen $indent."case EDG_WLL_EVENT_$tu :\n"; + gen $indent."case EDG_WLL_EVENT_${tu}: {\n"; selectType $event $t; my $argl = ""; + my $values = ""; + my $frees = ""; for ($event->getFieldsOrdered) { my $f = selectField $event $_; my $fn = $f->getName; - my $ft; - -# gen { $fn $f->{codes} }; - if ($f->{codes}) { -# $ft = "enum edg_wll\_$t" . ucfirst $fn; - $ft = "char *"; + my $fdecl = $f->{codes} ? 'char *' : $f->getType; + my $ft = $f->{type}; + + if ($ft eq 'timeval') { +gen "\t char s_${fn}[ULM_DATE_STRING_LENGTH + 1];\n"; + $values .= "\n\t ".$f->toString($fn, "s_${fn}"); + $argl .= ", s_${fn}"; + } elsif ($ft eq 'jobid' or $ft eq 'notifid' or $ULMasString{$ft}) { +gen "\t char *s_${fn};\n"; + $values .= "\n\t ".$f->toString($fn, "s_${fn}"); + $frees .= "\n\t free(s_$fn);"; + $argl .= ", s_${fn}"; } else { - $ft = $f->getType; + $argl .= ", $fn"; } - - $fn = $f->getType()."ToString($fn)" if $ULMasString{$f->{type}}; - - $argl = $argl . ", "; - $argl = $argl . $fn; } -gen qq{\t //edg_wll_Log$t(); -\t err |= logev(ctx, EDG_WLL_EVENT_$tu, EDG_WLL_FORMAT_${tu}$argl); +gen qq{$values +\t //edg_wll_Log$t(); +\t err |= logev(ctx, EDG_WLL_EVENT_$tu, EDG_WLL_FORMAT_${tu}$argl);$frees +\t \} \t break; }; } diff --git a/org.glite.lb.client/src/uiwrap.T b/org.glite.lb.client/src/uiwrap.T index c6c85ca..9edc9c0 100644 --- a/org.glite.lb.client/src/uiwrap.T +++ b/org.glite.lb.client/src/uiwrap.T @@ -27,9 +27,12 @@ for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } my $sfn = $fn; my $ft = "const "; my $fc = $f->getComment; - if ($ULMasString{$f->{type}}) { - $decl .= "\tchar *s_$fn = ".$f->getType()."ToString($fn);\n"; - $free .= "\tif (s_$fn) free(s_$fn);\n"; + if ($f->{type} eq 'timeval') { + $decl .= "\tchar s_$fn".'[ULM_DATE_STRING_LENGTH + 1]; '.$f->toString($fn, "s_$fn")."\n"; + $sfn = "s_$fn"; + } elsif ($f->{type} eq 'jobid' or $f->{type} eq 'notifid' or $ULMasString{$f->{type}}) { + $decl .= "\tchar *s_$fn; ".$f->toString($fn, "s_$fn")."\n"; + $free .= "\tfree(s_$fn);\n"; $sfn = "s_$fn"; } if ($f->{codes}) { diff --git a/org.glite.lb.client/src/uiwrap.c.T b/org.glite.lb.client/src/uiwrap.c.T index edf9da6..db32145 100644 --- a/org.glite.lb.client/src/uiwrap.c.T +++ b/org.glite.lb.client/src/uiwrap.c.T @@ -24,6 +24,7 @@ limitations under the License. #include #include "glite/jobid/cjobid.h" #include "producer.h" +#include "glite/lb/ulm_parse.h" @@@{ $PRINTPROTOTYPESONLY = 0; diff --git a/org.glite.lb.client/test/api_test.cpp.T b/org.glite.lb.client/test/api_test.cpp.T new file mode 100644 index 0000000..e664161 --- /dev/null +++ b/org.glite.lb.client/test/api_test.cpp.T @@ -0,0 +1,99 @@ +/* +Copyright (c) Members of the EGEE Collaboration. 2004-2010. +See http://www.eu-egee.org/partners for details on the copyright holders. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +@@@LANG: C + +#include +#include +#include + +#include "glite/lbu/trio.h" +#include "producer.h" +#include "glite/lb/ulm_parse.h" + +#define edg_wll_LogEvent edg_wll_LogEventTest +#define edg_wll_LogEventProxy edg_wll_LogEventTest + +int edg_wll_LogEventTest(edg_wll_Context context, edg_wll_EventCode event, char *fmt, ...) { + va_list fmt_args; + int ret; + + va_start(fmt_args, fmt); + ret = trio_vprintf(fmt,fmt_args); + printf("\n"); + va_end(fmt_args); + return ret; +} + +@@@{ +use strict; +require '../src/uiwrap.T'; +@@@} + +int main() { + edg_wll_Context ctx; + +@@@{ + +#use strict; + +for my $e ($event->getTypesOrdered) { + my $E = uc $e; + my $func = "edg_wll_Log$e"; # name of generated function + my $funcproxy = $func . "Proxy"; + my $p = "ctx"; + my $values = ""; + my $frees = ""; + +gen "// $e\n{\n"; + + selectType $event $e; + for ($event->getFieldsOrdered) { + my $f = selectField $event $_; + my $fn = $f->getName; + my $fdecl = $f->getType; + my $ft = $f->{type}; + my $value = undef; + my $free = "free($fn);"; + + if ($f->{codes}) { + $fdecl = "char *"; + $value = "$fn = edg_wll_$e".ucfirst($fn)."ToString(EDG_WLL_${E}_$f->{codes}->[0]->{name});"; + } elsif (($ft eq "int") || ($ft eq "port")) { $value = "$fn = 654;"; $free = ""; } + elsif (($ft eq "float") || ($ft eq "double")) { $value = "$fn = 3.14159265358979323846264;"; $free = ""; } + elsif ($ft eq "string") { $value = "$fn = strdup(\"teststring\");"; } + elsif ($ft eq "logsrc") { $value = "$fn = EDG_WLL_SOURCE_APPLICATION;"; $free = ""; } + elsif ($ft eq "jobid") { $value = "glite_jobid_parse(\"https://some.host:1234/x67qr549qc\",&$fn);"; $free = "glite_jobid_free($fn);"; } + elsif ($ft eq "notifid") { $value = "edg_wll_NotifIdParse(\"https://some.host:1234/NOTIF:x67qr549qc\",&$fn);"; $free = "edg_wll_NotifIdFree($fn);"; } + elsif ($ft eq "timeval") { $value = "$fn.tv_sec = 274492800; $fn.tv_usec = 1; //tpb rox! :-)"; $free = ""; } + else { +gen "% FIXME: unknown type $ft for $fn \n"; + } + $p .= ", $fn"; + $values .= "\n\t$value"; + if ($free) { $frees .= "\n\t$free"; } + +gen "\t$fdecl $fn;\n"; + } +gen "$values\n\tprintf(\"%s: \", \"$e\");\n\tedg_wll_Log$e($p);\n\t$frees\n"; +gen "}\n\n"; +} + + +@@@} + edg_wll_LogSandboxOUTPUT(ctx, "tj", "cj"); +} diff --git a/org.glite.lb.common/interface/ulm_parse.h b/org.glite.lb.common/interface/ulm_parse.h index 2fbff02..e4e09f4 100644 --- a/org.glite.lb.common/interface/ulm_parse.h +++ b/org.glite.lb.common/interface/ulm_parse.h @@ -23,6 +23,10 @@ limitations under the License. #include /* for ULCconvertDate */ #include +#ifdef __cplusplus +extern "C" { +#endif + /*========= DATA =====================================================*/ #define ULM_DATE_STRING_LENGTH 21 @@ -61,4 +65,8 @@ extern double edg_wll_ULMDateToDouble( const char *s ); void edg_wll_ULMDateToTimeval( const char *s, struct timeval *tv ); extern int edg_wll_ULMTimevalToDate( long sec, long usec, char *dstr ); +#ifdef __cplusplus +} +#endif + #endif /* GLITE_LB_ULM_PARSE_H */ diff --git a/org.glite.lb.types/types.T b/org.glite.lb.types/types.T index cfb1629..7b727f5 100644 --- a/org.glite.lb.types/types.T +++ b/org.glite.lb.types/types.T @@ -88,7 +88,6 @@ notifid=>'qq{$dst = edg_wll_NotifIdUnparse($src);}', # level=>'qq{$dst = edg_wll_LevelToString($src);}', logsrc=>'qq{$dst = edg_wll_SourceToString($src);}', - logsrc=>'qq{$dst = edg_wll_StringToSource($src);}', cclassad=>'qq{$dst = NULL;}', # strlist, intlist, stslist are used only in consumer API, they don't need toString method } -- 1.8.2.3