Skip to content

Commit

Permalink
Created a test for the MemMgr. See #4
Browse files Browse the repository at this point in the history
Had to modify a bunch of files to allow c++ linkage. Removed the old testing. Also modified build to allow configure to still work without cppunit
  • Loading branch information
dschatzberg committed Dec 13, 2011
1 parent c6715f9 commit 6e83d36
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 86 deletions.
12 changes: 4 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ include lrt/Makefile.am
include misc/Makefile.am
include net/Makefile.am

include test/Makefile.am

bin_PROGRAMS = ebbtest

ebbtest_SOURCES = EBBStart.c $(arch_sources) $(l0_sources) $(lrt_sources) \
$(misc_sources) $(net_sources)

TESTS = cppunit
check_PROGRAMS = cppunit
cppunit_SOURCES = $(test_cppunit_sources) $(misc_cppunit_sources) \
$(ebbtest_SOURCES)
cppunit_CXXFLAGS = $(CPPUNIT_CFLAGS)
cppunit_LDFLAGS = $(CPPUNIT_LIBS)
if BUILD_TESTS
TESTS = $(l0_tests)
check_PROGRAMS = $(l0_tests)
endif
9 changes: 8 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
AC_CONFIG_SRCDIR([EBBStart.c])
AC_CONFIG_HEADER([config.h])
AM_PATH_CPPUNIT(1.12.1)

AC_CANONICAL_HOST
AS_CASE([$host_cpu], [x86_64], [], [powerpc], [], [AC_MSG_ERROR([not on a supported architecture])])
Expand Down Expand Up @@ -57,5 +56,13 @@ AC_SEARCH_LIBS([pcap_freealldevs], [pcap], [],
[AC_MSG_ERROR([pcap library missing])])
AC_CHECK_FUNCS([bzero dup2 gethostbyname memset socket strerror])

#PKG_CHECK_MODULES([CHECK], [check >= 0.9.8], [BUILD_TESTS="yes"],
# AC_MSG_WARN([Check not found; cannot run unit tests!])
# [BUILD_TESTS="no"])
AM_PATH_CPPUNIT(1.12.1, [BUILD_TESTS="yes"],
AC_MSG_WARN([Check not found; cannot run unit tests!])
[BUILD_TESTS="no"])
AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes")

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
1 change: 1 addition & 0 deletions l0/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include l0/cobj/Makefile.am
include l0/cplus/Makefile.am
include l0/lrt/Makefile.am
include l0/sys/Makefile.am
include l0/test/Makefile.am

l0_ebbmgrprim_sources = l0/EBBMgrPrim.c l0/EBBMgrPrim.h l0/EBBMgrPrimBoot.c \
l0/EBBMgrPrimBoot.h
Expand Down
11 changes: 5 additions & 6 deletions l0/MemMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ typedef enum {EBB_MEM_LOCAL, EBB_MEM_LOCAL_PADDED,
EBB_MEM_GLOBAL, EBB_MEM_GLOBAL_PADDED,
EBB_MEM_DEFAULT = EBB_MEM_GLOBAL} EBB_MEM_POOL;

CObjInterface(EBBMemMgr) {
EBBRC (*init) (void *_self, void *rootRef, uintptr_t end);
EBBRC (*alloc) (void *_self, uintptr_t size, void *mem, EBB_MEM_POOL pool);
EBBRC (*free) (void * _self, void *mem);
};

CObject(EBBMemMgr) {
CObjInterface(EBBMemMgr) *ft;
};

CObjInterface(EBBMemMgr) {
EBBRC (*alloc) (EBBMemMgrRef _self, uintptr_t size, void **mem, EBB_MEM_POOL pool);
EBBRC (*free) (EBBMemMgrRef _self, void *mem);
};

typedef EBBMemMgrRef *EBBMemMgrId;

#endif
19 changes: 8 additions & 11 deletions l0/MemMgrPrim.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@

CObject(EBBMemMgrPrim) {
CObjInterface(EBBMemMgr) *ft;
void *myRoot;
CObjEBBRootMultiRef myRoot;
void *mem;
uintptr_t len;
};

static EBBRC
EBBMemMgrPrim_init(void *_self, void *rootRef, uintptr_t end)
init_rep(EBBMemMgrPrimRef self, CObjEBBRootMultiRef rootRef, uintptr_t end)
{
EBBMemMgrPrimRef self = _self;
self->mem = (void *)((uintptr_t)self + sizeof(*self));
self->len = end - (uintptr_t)self->mem;
self->myRoot = rootRef;
Expand All @@ -62,13 +61,13 @@ EBBMemMgrPrim_init(void *_self, void *rootRef, uintptr_t end)
//just grab from the beginning of the memory and move
//the pointer forward until we run out
static EBBRC
EBBMemMgrPrim_alloc(void *_self, uintptr_t size, void *mem, EBB_MEM_POOL pool)
EBBMemMgrPrim_alloc(EBBMemMgrRef _self, uintptr_t size, void **mem, EBB_MEM_POOL pool)
{
EBBMemMgrPrimRef self = _self;
EBBMemMgrPrimRef self = (EBBMemMgrPrimRef)_self;
if (size > self->len) {
*((void **)mem) = NULL; //Do I return some error code here??
*mem = NULL; //Do I return some error code here??
} else {
*((void **)mem) = self->mem;
*mem = self->mem;
self->mem += size;
self->len -= size;
}
Expand All @@ -77,12 +76,11 @@ EBBMemMgrPrim_alloc(void *_self, uintptr_t size, void *mem, EBB_MEM_POOL pool)

//freeing is a nop in this implementation
static EBBRC
EBBMemMgrPrim_free(void *_self, void *mem) {
EBBMemMgrPrim_free(EBBMemMgrRef _self, void *mem) {
return EBBRC_OK;
}

CObjInterface(EBBMemMgr) EBBMemMgrPrim_ftable = {
.init = EBBMemMgrPrim_init,
.alloc = EBBMemMgrPrim_alloc,
.free = EBBMemMgrPrim_free
};
Expand All @@ -98,7 +96,6 @@ MemMgrPrim_createRep(CObjEBBRootMultiRef _self)
return NULL;
}


EBBMemMgrRef *theEBBMemMgrPrimId;

EBBRC
Expand Down Expand Up @@ -131,7 +128,7 @@ EBBMemMgrPrimInit()

// initialize the rep memory
EBBMemMgrPrimSetFT(repRef);
repRef->ft->init(repRef, rootRef, lrt_mem_end());
init_rep(repRef, (CObjEBBRootMultiRef)rootRef, lrt_mem_end());

// manually install rep into local table so that memory allocations
// can work immediate without recursion
Expand Down
8 changes: 7 additions & 1 deletion l0/MemMgrPrim.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
extern EBBRC EBBMemMgrPrimInit(void);
#ifdef __cplusplus
}
#endif
extern EBBMemMgrId theEBBMemMgrPrimId;

static inline EBBRC
EBBPrimMalloc(uintptr_t size, void *mem, EBB_MEM_POOL pool) {
return COBJ_EBBCALL(theEBBMemMgrPrimId, alloc, size, mem, pool);
return COBJ_EBBCALL(theEBBMemMgrPrimId, alloc, size, (void **)mem, pool);
}

static inline EBBRC
Expand Down
6 changes: 6 additions & 0 deletions l0/lrt/ulnx/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

uintptr_t lrt_mem_start(void);
uintptr_t lrt_mem_end(void);
#ifdef __cplusplus
extern "C" {
#endif
intptr_t lrt_mem_init(void);
#ifdef __cplusplus
}
#endif

#endif
15 changes: 13 additions & 2 deletions l0/lrt/ulnx/pic.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,23 @@ volatile extern lrt_pic_id lrt_pic_lastid;
extern uintptr_t lrt_pic_getIPIvec(void);
extern uintptr_t lrt_pic_firstvec(void);
extern uintptr_t lrt_pic_numvec(void);
#ifdef __cplusplus
extern "C" {
#endif
extern intptr_t lrt_pic_init(lrt_pic_handler h);
#ifdef __cplusplus
}
#endif
extern intptr_t lrt_pic_loop(void);
extern intptr_t lrt_pic_allocvec(uintptr_t *vec);
extern intptr_t lrt_pic_mapvec(lrt_pic_src src, uintptr_t vec,
lrt_pic_handler h);
extern intptr_t lrt_pic_mapvec(lrt_pic_src src, uintptr_t vec, lrt_pic_handler h);
#ifdef __cplusplus
extern "C" {
#endif
extern intptr_t lrt_pic_add_core();
#ifdef __cplusplus
}
#endif
extern intptr_t lrt_pic_mapipi(lrt_pic_handler h);
extern intptr_t lrt_pic_mapreset(lrt_pic_handler h);
extern intptr_t lrt_pic_reset(lrt_pic_id targets);
Expand Down
6 changes: 6 additions & 0 deletions l0/lrt/ulnx/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ lrt_trans_lt2gt(struct lrt_trans *lt)
(uintptr_t)lt));
}

#ifdef __cplusplus
extern "C" {
#endif
void lrt_trans_init(void);
#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions l0/sys/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ typedef EBBTrans EBBGTrans;

extern EBBFunc EBBDefFT[EBB_TRANS_MAX_FUNCS];

#ifdef __cplusplus
extern "C" {
#endif
extern void trans_init(void);
#ifdef __cplusplus
}
#endif

extern uintptr_t myGTableSize(void);
extern EBBGTrans *myGTable(void);
extern uintptr_t myLTableSize(void);
Expand Down
26 changes: 26 additions & 0 deletions l0/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2011 by Project SESA, Boston University

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

l0_tests = l0/test/MemMgrPrim_SingleCoreTest

l0_test_MemMgrPrim_SingleCoreTest_SOURCES = \
l0/test/MemMgrPrim_SingleCoreTest.C $(ebbtest_SOURCES)
l0_test_MemMgrPrim_SingleCoreTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
l0_test_MemMgrPrim_SingleCoreTest_LDFLAGS = $(CPPUNIT_LIBS)
76 changes: 76 additions & 0 deletions l0/test/MemMgrPrim_SingleCoreTest.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2011 by Project SESA, Boston University
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include <config.h>
#include <stdint.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <l0/lrt/pic.h>
#include <l0/lrt/mem.h>
#include <l0/lrt/trans.h>
#include <l0/types.h>
#include <l0/sys/trans.h>
#include <l0/cobj/cobj.h>
#include <l0/cobj/CObjEBB.h>
#include <l0/MemMgr.h>
#include <l0/MemMgrPrim.h>

class MemMgrPrim_Test : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MemMgrPrim_Test);
CPPUNIT_TEST(test);
CPPUNIT_TEST_SUITE_END();
public:
//I have a static function as the reset function
// I have to do all my setup here because I cannot return back off a reset
// exit(0) will be intercepted by the test infrastructure and it will accept
// the test as successful. Unfortunately, I cannot run a second test because
// it will be in this address space, so a new file/runner
// would need to be created
static void do_test()
{
EBBRC rc;
int *i;
lrt_mem_init();
lrt_trans_init();
trans_init();
EBBMemMgrPrimInit();
rc = EBBPrimMalloc(sizeof(int), &i, EBB_MEM_DEFAULT);
CPPUNIT_ASSERT(EBBRC_SUCCESS(rc));
rc = EBBPrimFree(i);
CPPUNIT_ASSERT(EBBRC_SUCCESS(rc));
exit(0);
}

void test()
{
lrt_pic_init(do_test);
}

};

int
main ()
{
CppUnit::TextUi::TestRunner runner;
runner.addTest(MemMgrPrim_Test::suite());
return !runner.run();
}
4 changes: 0 additions & 4 deletions misc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
include misc/test/Makefile.am

misc_ctrprim_sources = misc/Ctr.h misc/CtrPrim.c misc/CtrPrim.h \
misc/CtrPrimDistributed.c misc/CtrPrimDistributed.h

misc_ctrcplus_sources = misc/CtrCPlus.C misc/CtrCPlus.H

misc_sources = $(misc_ctrprim_sources) $(misc_ctrcplus_sources)

misc_cppunit_sources = $(misc_test_cppunit_sources)
40 changes: 0 additions & 40 deletions misc/test/CPlusCounterTest.C

This file was deleted.

1 change: 0 additions & 1 deletion misc/test/Makefile.am

This file was deleted.

1 change: 0 additions & 1 deletion test/Makefile.am

This file was deleted.

Loading

0 comments on commit 6e83d36

Please sign in to comment.