Documentation of the Test-Client-Server tool used for example.test
.
The Naming-Test-Tool tool is used to test the name-resolution-feature of libmqmsgque.
To perform the test 2 tools are used, the testclient and the testserver.
testclient | This tool creates multiple parent and child client-context, all using a |
testserver | This tool listen on the service GTCX and return the unique identification pattern of the server-context in duty. |
All context created, 8x client and 8x server, are connected using the libmqmsgque protocoll and build together a flat structure.
The GOAL for this setup is:
/** * @file NHI1/example/c/testclient.c * @brief testclient.c - 25 Aug 2024 - aotto1968 * @copyright (C) NHI - #1 - Project - Group * This software has NO permissions to copy, * please contact AUTHOR for additional information * @version c3b28928437a81158df1f3cafe23fbded7b34813 * @date Sun Aug 25 22:59:57 2024 +0200 * @author aotto1968 <aotto1968@t-online.de> */ /* LABEL-START */ #define META_FILE_NAME "testclient.c" /* LABEL-END */ #include <libgen.h> #include <limits.h> #include "common.h" #define META_CONTEXT_S ctx static const char * Get ( MQ_CTX const ctx ) { MkRtSetup_NULL; static char str[250]; MK_STRN buf; MqSendSTART_E (ctx); MqSendEND_AND_WAIT_E (ctx, "GTCX", MK_TIMEOUT_USER); str[0] = '\0'; strncat(str, MqConfigGetName(ctx), 250-1); strncat(str, "+", 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); MqReadSTR_E (ctx, &buf); strncat(str, buf, 250-1); return str; error: MqExit_1(ctx); return ""; } #define FIRST int main (int argc, MK_STRN argv[]) { MkRtSetup_NULL; // find abs path :-) FILE *fp; char abs_exe_path[PATH_MAX]; // build command strcpy (abs_exe_path, "/usr/bin/which "); strcat (abs_exe_path, argv[0]); /* Open the command for reading. */ fp = popen(abs_exe_path, "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit(1); } /* Read the output a line at a time - output it. */ if (fgets(abs_exe_path, sizeof(abs_exe_path), fp) == NULL) { printf("Failed to extract path\n" ); exit(1); } /* close */ pclose(fp); char * sd = strdup(dirname(abs_exe_path)); strcpy (abs_exe_path, sd); #ifdef META_IS_POSIX strcat (abs_exe_path, "/testserver"), #else strcat (abs_exe_path, "/testserver.exe"), #endif free(sd); // start work MK_BFL largv = MkBufferListCreateVC(argc, argv); MQ_CTX ctx=NULL; #if defined(FIRST) MQ_CTX c0=NULL, c00=NULL, c01=NULL, c000=NULL; #endif MQ_CTX c1=NULL, c10=NULL, c100=NULL, c101=NULL; #if defined(FIRST) struct MkBufferListS *bs0 = MkBufferListCreateVA( argv[0], "--prefix", "c", "--debug", getenv("TS_DEBUG"), "@", abs_exe_path, "--prefix", "s",NULL); struct MkBufferListS *args; #endif #if defined(FIRST) ctx = MqContextCreate(NULL,NULL); MqConfigSetPostfix(ctx, "0"); MqLinkCreate_E (ctx, bs0); MqCheckForLeftOverArguments_E (ctx,bs0); MkBufferListDelete(bs0); c0 = ctx; ctx = MqContextCreate(NULL,NULL); args = MkBufferListCreateVA ("--postfix", "00", NULL); MqLinkCreateChild_E (ctx, c0, args); MkBufferListDelete(args); c00 = ctx; ctx = MqContextCreate(NULL,NULL); args = MkBufferListCreateVA ("--postfix", "01", NULL); MqLinkCreateChild_E (ctx, c0, args); MkBufferListDelete(args); c01 = ctx; ctx = MqContextCreate(NULL,NULL); args = MkBufferListCreateVA ("--postfix", "000", NULL); MqLinkCreateChild_E (ctx, c00, args); MkBufferListDelete(args); c000 = ctx; #endif ctx = MqContextCreate(NULL,NULL); MqConfigSetPrefix(ctx, "c"); MqConfigSetPostfix(ctx, "1"); MqLinkCreate_E (ctx, largv); MqCheckForLeftOverArguments_E (ctx, largv); MkBufferListDelete(largv); c1 = ctx; ctx = MqContextCreate(NULL,NULL); MqConfigSetPostfix(ctx, "10"); MqLinkCreateChild_E (ctx, c1, NULL); c10 = ctx; ctx = MqContextCreate(NULL,NULL); MqConfigSetPostfix(ctx, "100"); MqLinkCreateChild_E (ctx, c10, NULL); c100 = ctx; ctx = MqContextCreate(NULL,NULL); MqConfigSetPostfix(ctx, "101"); MqLinkCreateChild_E (ctx, c10, NULL); c101 = ctx; // do the tests #if defined(FIRST) fprintf(stdout,"%s\n", Get(c0)); fprintf(stdout,"%s\n", Get(c00)); fprintf(stdout,"%s\n", Get(c01)); fprintf(stdout,"%s\n", Get(c000)); #endif fprintf(stdout,"%s\n", Get(c1)); fprintf(stdout,"%s\n", Get(c10)); fprintf(stdout,"%s\n", Get(c100)); fprintf(stdout,"%s\n", Get(c101)); fflush(stdout); // do the cleanup #if defined(FIRST) MqContextDelete(c0); MqContextDelete(c00); MqContextDelete(c01); MqContextDelete(c000); #endif MqContextDelete(c1); MqContextDelete(c10); MqContextDelete(c100); MqContextDelete(c101); return 0; error: MqExit_1(ctx); }
/** * @file NHI1/example/c/testserver.c * @brief testserver.c - 25 Aug 2024 - aotto1968 * @copyright (C) NHI - #1 - Project - Group * This software has NO permissions to copy, * please contact AUTHOR for additional information * @version c3b28928437a81158df1f3cafe23fbded7b34813 * @date Sun Aug 25 22:59:57 2024 +0200 * @author aotto1968 <aotto1968@t-online.de> */ /* LABEL-START */ #define META_FILE_NAME "testserver.c" /* LABEL-END */ #include "common.h" static enum MkErrorE GTCX( MQ_SERVICE_CALL_ARGS ) { MqSendSTART_E (mqctx); MqSendI32_E (mqctx, (MK_I32)MqLinkGetCtxId(mqctx)); MqSendSTR_E (mqctx, "+"); if (MqLinkIsParent(mqctx)) { MqSendI32_E (mqctx, -1); } else { MqSendI32_E (mqctx, (MK_I32)MqLinkGetCtxId(MqLinkGetParent(mqctx))); } MqSendSTR_E (mqctx, "+"); MqSendSTR_E (mqctx, MqConfigGetName(mqctx)); MqSendSTR_E (mqctx, ":"); error: return MqSendRETURN(mqctx); } static enum MkErrorE ServerSetup ( MQ_SERVICE_CALL_ARGS ) { return MqServiceCreate(mqctx,"GTCX", GTCX, NULL, NULL, NULL); } #if 0 int main (int argc, MK_STRN argv[]) { //MkSetup(); struct MkBufferListS * largv = MkBufferListCreateVC(argc, argv); MQ_CTX mqctx = MqContextCreate(0, NULL); MqConfigSetServerSetup (mqctx, ServerSetup, NULL, NULL, NULL); MqLinkCreate_E (mqctx, largv); MqProcessEvent_E (mqctx,MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT); error: MkBufferListDelete(largv); MqExit_1(mqctx); } #else enum MkErrorE Factory ( MQ_CALLBACK_FACTORY_CTOR_ARGS ) { MQ_CTX const mqctx = *contextP = MqContextCreate(NULL,tmpl); MqConfigSetServerSetup (mqctx, ServerSetup, NULL, NULL, NULL); return MK_OK; } int main (int argc, MK_STRN argv[]) { MqRtSetup_NULL; // setup commandline arguments for later use MK_BFL largv = MkBufferListCreateVC(argc, argv); MQ_CTX mqctx = NULL; // create "testserver" factory… and make it to the default. MqFactoryDefault( MqFactoryAdd(MK_ERROR_PANIC, Factory, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "testserver") ); // inspect commandline-argument for the "factory" to choose… and create a object MqFactoryNew_E (MqFactoryGetCalledL(largv), NULL, &mqctx); // start listen for incoming call's MqLinkCreate_E (mqctx, largv); MqCheckForLeftOverArguments_E (mqctx, largv); MqProcessEvent_E (mqctx,MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT); error: MkBufferListDelete(largv); MqExit_1(mqctx); } #endif