From 383b6b1c364473ecc5e64d9f2fce8af5bfe2ad79 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 14 Nov 2018 13:28:44 -0800 Subject: [PATCH] add aslibtest --- modules/libcom/test/Makefile | 5 + modules/libcom/test/aslibtest.c | 119 ++++++++++++++++++++++ modules/libcom/test/epicsRunLibComTests.c | 2 + 3 files changed, 126 insertions(+) create mode 100644 modules/libcom/test/aslibtest.c diff --git a/modules/libcom/test/Makefile b/modules/libcom/test/Makefile index 429d446c7..1c26c44b7 100755 --- a/modules/libcom/test/Makefile +++ b/modules/libcom/test/Makefile @@ -194,6 +194,11 @@ macLibTest_SRCS += macLibTest.c testHarness_SRCS += macLibTest.c TESTS += macLibTest +TESTPROD_HOST += aslibtest +aslibtest_SRCS += aslibtest.c +testHarness_SRCS += aslibtest.c +TESTS += aslibtest + # Perl module tests: TESTS += macLib diff --git a/modules/libcom/test/aslibtest.c b/modules/libcom/test/aslibtest.c new file mode 100644 index 000000000..875aa56fd --- /dev/null +++ b/modules/libcom/test/aslibtest.c @@ -0,0 +1,119 @@ +/*************************************************************************\ +* Copyright (c) 2018 Michael Davidsaver +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +static char *asUser, + *asHost; +static int asAsl; + +static void setUser(const char *name) +{ + free(asUser); + asUser = epicsStrDup(name); +} + +static void setHost(const char *name) +{ + free(asHost); + asHost = epicsStrDup(name); +} + +static void testAccess(const char *asg, unsigned mask) +{ + ASMEMBERPVT asp = 0; /* aka dbCommon::asp */ + ASCLIENTPVT client = 0; + long ret; + + ret = asAddMember(&asp, asg); + if(ret) { + testFail("testAccess(ASG:%s, USER:%s, HOST:%s, ASL:%d) -> asAddMember error: %s", + asg, asUser, asHost, asAsl, errSymMsg(ret)); + } else { + ret = asAddClient(&client, asp, asAsl, asUser, asHost); + } + if(ret) { + testFail("testAccess(ASG:%s, USER:%s, HOST:%s, ASL:%d) -> asAddClient error: %s", + asg, asUser, asHost, asAsl, errSymMsg(ret)); + } else { + unsigned actual = 0; + actual |= asCheckGet(client) ? 1 : 0; + actual |= asCheckPut(client) ? 2 : 0; + testOk(actual==mask, "testAccess(ASG:%s, USER:%s, HOST:%s, ASL:%d) -> %x == %x", + asg, asUser, asHost, asAsl, actual, mask); + } + if(client) asRemoveClient(&client); + if(asp) asRemoveMember(&asp); +} + +static void testSyntaxErrors(void) +{ + static const char empty[] = "\n#almost empty file\n\n"; + long ret; + + testDiag("testSyntaxErrors()"); + + eltc(0); + ret = asInitMem(empty, NULL); + testOk(ret==S_asLib_badConfig, "load \"empty\" config -> %s", errSymMsg(ret)); + eltc(1); +} +static const char hostname_config[] = "" + "HAG(foo) {localhost}\n" + "ASG(DEFAULT) {RULE(0, NONE)}\n" + "ASG(ro) {RULE(0, NONE)RULE(1, READ) {HAG(foo)}}\n" + "ASG(rw) {RULE(1, WRITE) {HAG(foo)}}\n" + ; + +static void testHostNames(void) +{ + + testDiag("testHostNames()"); + + testOk1(asInitMem(hostname_config, NULL)==0); + + setUser("testing"); + setHost("localhost"); + asAsl = 0; + + testAccess("invalid", 0); + testAccess("DEFAULT", 0); + testAccess("ro", 1); + testAccess("rw", 3); + + setHost("127.0.0.1"); + + testAccess("invalid", 0); + testAccess("DEFAULT", 0); + testAccess("ro", 0); + testAccess("rw", 0); + + setHost("nosuchhost"); + + testAccess("invalid", 0); + testAccess("DEFAULT", 0); + testAccess("ro", 0); + testAccess("rw", 0); +} +MAIN(aslibtest) +{ + testPlan(14); + testSyntaxErrors(); + testHostNames(); + errlogFlush(); + return testDone(); +} diff --git a/modules/libcom/test/epicsRunLibComTests.c b/modules/libcom/test/epicsRunLibComTests.c index 29c5eda3f..94fe3d76f 100644 --- a/modules/libcom/test/epicsRunLibComTests.c +++ b/modules/libcom/test/epicsRunLibComTests.c @@ -16,6 +16,7 @@ #include #include +int aslibtest(void); int blockingSockTest(void); int epicsAlgorithm(void); int epicsAtomicTest(void); @@ -73,6 +74,7 @@ void epicsRunLibComTests(void) /* * Run the regular tests in alphabetical order */ + runTest(aslibtest); runTest(blockingSockTest); runTest(epicsAlgorithm); runTest(epicsAtomicTest);