From 7bfff83859f4bfb254c659dc0caa529735fd2507 Mon Sep 17 00:00:00 2001 From: Kevin Koch Date: Tue, 22 Jan 2008 19:14:04 +0000 Subject: Windows CCAPI snapshot. Should build & pass ping test TargetVersion: 1.7 Component: krb5-libs Ticket: 5594 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20203 dc483132-0cff-0310-8789-dd5450dbe970 --- src/ccapi/test/Makefile.w32 | 64 ++++++++++++++++ src/ccapi/test/pingtest.c | 108 +++++++++++++++++++++++++++ src/ccapi/test/simple_lock_test.c | 153 +++++++++++++++++++++----------------- 3 files changed, 256 insertions(+), 69 deletions(-) create mode 100644 src/ccapi/test/Makefile.w32 create mode 100644 src/ccapi/test/pingtest.c (limited to 'src/ccapi/test') diff --git a/src/ccapi/test/Makefile.w32 b/src/ccapi/test/Makefile.w32 new file mode 100644 index 000000000..077c20b06 --- /dev/null +++ b/src/ccapi/test/Makefile.w32 @@ -0,0 +1,64 @@ +# . is ccapi/test. +CO = ..\common +COWIN = $(CO)\win +LIBDIR = ..\lib +LIBWIN = $(LIBDIR)\win + +!include + +INC = -I..\..\include -I..\..\util\et -I$(CO) -I$(COWIN) -I$(LIBDIR) -I$(LIBWIN) + +!if "$(CPU)" == "i386" +cflags = $(cflags) /EHsc /MTd -D_CRTAPI1=_cdecl -D_CRTAPI2=_cdecl -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 \ +$(INC) +!else +cflags = $(cflags) /W3 -D_CRTAPI1= -D_CRTAPI2= $(INC) +!endif +LIBS = $(LIBWIN)\ccapi.lib + +DSTROOT = . +SRC = $(DSTROOT) +#OBJDIR = $(DSTROOT)\obj +OBJDIR = . +OBJEXT = obj +TESTDIR = $(DSTROOT)\tests +TESTEXT = exe +DSTDIR = $(DSTROOT)\ccapi_tests +PINGOBJS = pingtest.obj ccs_request_c.obj +SIMPLEOBJS = simple_lock_test.obj + +OBJS = cci_debugging.$(OBJEXT) \ + ccs_request_c.obj \ + cci_os_debugging.$(OBJEXT) \ + win-utils.obj \ + ccapi_os_ipc.obj \ + cci_stream.obj + +#all: build-base simple_lock_test pingtest +all: build-base pingtest + +# compile base files used by all tests +build-base: $(OBJS) + @echo "Base objects built." + +# rule to compile src files +.c.obj: + $(cc) $(cdebug) $(cflags) /Fo$(OBJDIR)\$(*B).$(OBJEXT) $(SRC)\$(*B).c + +simple_lock_test: simple_lock_test.obj $(OBJS) + @echo R3+ Build $(*B) in $(TESTDIR) + $(cc) $(cdebug) $(cflags) $(*B).c + $(link) $(linkdebug) $(conflags) -out:$(TESTDIR)\$(*B).exe $(*B).obj \ + $(LIBS) rpcrt4.lib + @echo R3- Built $(*B) in $(TESTDIR) + +pingtest: pingtest.obj + @echo R4+ Build $(*B) in $(TESTDIR) + $(cc) $(cdebug) $(cflags) $(*B).c +# $(link) $(linkdebug) $(conflags) -out:$(*B).exe $(*B).obj \ + $(link) $(linkdebug) $(conflags) -out:$(*B).exe $(PINGOBJS) \ + $(LIBS) rpcrt4.lib + @echo R4- Built $(*B) in $(TESTDIR) + +clean: + DEL *.$(OBJEXT) \ No newline at end of file diff --git a/src/ccapi/test/pingtest.c b/src/ccapi/test/pingtest.c new file mode 100644 index 000000000..992772586 --- /dev/null +++ b/src/ccapi/test/pingtest.c @@ -0,0 +1,108 @@ +// pingtest.c +// +// Test RPC to server, with PING message, which exists for no other purpose than this test. + +#include +#include + +#include "cci_debugging.h" +#include "CredentialsCache.h" +#include "cci_stream.h" +#include "win-utils.h" + +#include "ccs_request.h" +#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle + + +extern cc_int32 cci_os_ipc_thread_init (void); +extern cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server, + cci_stream_t in_request_stream, + cc_int32 in_msg, + cci_stream_t* out_reply_stream); + +RPC_STATUS send_test(char* endpoint) { + unsigned char* pszNetworkAddress = NULL; + unsigned char* pszOptions = NULL; + unsigned char* pszStringBinding = NULL; + unsigned char* pszUuid = NULL; + RPC_STATUS status; + + status = RpcStringBindingCompose(pszUuid, + (RPC_CSTR)"ncalrpc", + pszNetworkAddress, + (unsigned char*)endpoint, + pszOptions, + &pszStringBinding); + cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding); + if (status) {return cci_check_error(status);} + + /* Set the binding handle that will be used to bind to the RPC server [the 'client']. */ + status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE); + if (status) {return cci_check_error(status);} + + status = RpcStringFree(&pszStringBinding); // Temp var no longer needed. + + if (!status) { + RpcTryExcept { + cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__); + status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!"); + cci_debug_printf(" ccs_authenticate returned %d", status); + } + RpcExcept(1) { + status = cci_check_error(RpcExceptionCode()); + } + RpcEndExcept + } + + cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE)); + + return (status); + } + +int main( int argc, char *argv[]) { + cc_int32 err = 0; + cc_context_t context = NULL; + cci_stream_t send_stream = NULL; + cci_stream_t reply_stream = NULL; + char* message = "Hello, RPC!"; + + +// send_test("krbcc.229026.0.ep"); + +#if 0 + err = cc_initialize(&context, ccapi_version_7, NULL, NULL); +#endif + + if (!err) { + err = cci_os_ipc_thread_init(); + } + if (!err) { + err = cci_stream_new (&send_stream); + err = cci_stream_write(send_stream, message, 1+strlen(message)); + } + + if (!err) { + err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream); + } + Sleep(10*1000); + cci_debug_printf("Try finishing async call."); + + Sleep(INFINITE); + cci_debug_printf("main: return. err == %d", err); + + return 0; + } + + + +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ + +void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) { + return(malloc(len)); + } + +void __RPC_USER midl_user_free(void __RPC_FAR * ptr) { + free(ptr); + } diff --git a/src/ccapi/test/simple_lock_test.c b/src/ccapi/test/simple_lock_test.c index 6674a1ef6..254663c3a 100644 --- a/src/ccapi/test/simple_lock_test.c +++ b/src/ccapi/test/simple_lock_test.c @@ -1,69 +1,84 @@ -/* - simple_lock_test.c - - Initializes two contexts in two different threads and tries to get read locks on both at the same time. - Hangs at line 24. -*/ -#include -#include -#include -#include -#include - -void * other_thread () -{ - cc_int32 err; - cc_context_t context = NULL; - - err = cc_initialize(&context, ccapi_version_7, NULL, NULL); - - fprintf(stderr, "thread: attempting lock. may hang. err == %d\n", err); - - if (!err) { - // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately - err = cc_context_lock(context, cc_lock_read, cc_lock_noblock); - } - - if (context) { - cc_context_unlock(context); - cc_context_release(context); - context = NULL; - } - fprintf(stderr, "thread: return. err == %d\n", err); -} - - -int main (int argc, char *argv[]) -{ - cc_int32 err; - int status; - pthread_t thread_id; - cc_context_t context = NULL; - - err = cc_initialize(&context, ccapi_version_7, NULL, NULL); - if (!err) { - err = cc_context_lock(context, cc_lock_read, cc_lock_noblock); - } - - fprintf(stderr, "main: initialized and read locked context. err == %d\n", err); - - status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL); - if (status != 0) { - fprintf(stderr,"Create error!\n"); - exit(-1); - } - - pthread_join(thread_id, NULL); - - fprintf(stderr, "main: unlocking and releasing context. err == %d\n", err); - - if (context) { - cc_context_unlock(context); - cc_context_release(context); - context = NULL; - } - - fprintf(stderr, "main: return. err == %d\n", err); - - return 0; -} \ No newline at end of file +/* + simple_lock_test.c + + Initializes two contexts in two different threads and tries to get read locks on both at the same time. + Hangs at line 24. +*/ +#include +#include + +#include "cci_debugging.h" + +#ifdef TARGET_OS_MAC +#include +#include +#else +#include "CredentialsCache.h" +#endif + + +void * other_thread () { + cc_int32 err; + cc_context_t context = NULL; + + err = cc_initialize(&context, ccapi_version_7, NULL, NULL); + + cci_debug_printf("thread: attempting lock. may hang. err == %d", err); + + if (!err) { + // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately + err = cc_context_lock(context, cc_lock_read, cc_lock_noblock); + } + + if (context) { + cc_context_unlock(context); + cc_context_release(context); + context = NULL; + } + cci_debug_printf("thread: return. err == %d", err); + } + + +int main (int argc, char *argv[]) { + cc_int32 err; + int status; + cc_context_t context = NULL; + +#ifdef TARGET_OS_MAC + pthread_t thread_id; +#endif + + err = cc_initialize(&context, ccapi_version_7, NULL, NULL); + if (!err) { + err = cc_context_lock(context, cc_lock_read, cc_lock_noblock); + } + + cci_debug_printf("main: initialized and read locked context. err == %d", err); + +#ifdef TARGET_OS_MAC + status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL); + if (status != 0) { + cci_debug_printf("Create error!"); + exit(-1); + } + + pthread_join(thread_id, NULL); +#else + +#endif + + cci_debug_printf("main: unlocking and releasing context. err == %d", err); + + if (context) { + cci_debug_printf("main: calling cc_context_unlock"); + cc_context_unlock(context); + cci_debug_printf("main: calling cc_context_release"); + cc_context_release(context); + context = NULL; + } + + cci_debug_printf("main: return. err == %d", err); + + UNREFERENCED_PARAMETER(status); // no whining! + return 0; + } \ No newline at end of file -- cgit