Revision: 56260
http://sourceforge.net/p/brlcad/code/56260
Author: brlcad
Date: 2013-07-27 17:53:29 +0000 (Sat, 27 Jul 2013)
Log Message:
-----------
move the heap main() test harness into a preliminary unit test. doesn't do any
validation other than running 50M allocations with some random freeing.
Modified Paths:
--------------
brlcad/trunk/src/libbu/heap.c
brlcad/trunk/src/libbu/tests/CMakeLists.txt
Added Paths:
-----------
brlcad/trunk/src/libbu/tests/bu_heap.c
Modified: brlcad/trunk/src/libbu/heap.c
===================================================================
--- brlcad/trunk/src/libbu/heap.c 2013-07-27 17:53:05 UTC (rev 56259)
+++ brlcad/trunk/src/libbu/heap.c 2013-07-27 17:53:29 UTC (rev 56260)
@@ -208,63 +208,6 @@
}
-/* test driver application, intended to become part of unit test */
-#if 0
-
-int main (int ac, char *av[])
-{
- int i;
- void *ptr;
- size_t allocalls = 0;
- size_t freecalls = 0;
-
- srand(time(0));
-
- for (i=0; i<1024*1024*50; i++) {
- size_t sz = (((double)rand() / (double)(RAND_MAX-1)) *
(double)HEAP_BINS) + 1;
- bu_log("allocating %d: %zd\n", i, sz);
-#ifdef USE_MALLOC
- ptr = malloc(sz);
-#else
- ptr = bu_fastalloc(sz);
-#endif
- allocalls++;
-
- if (i%3==0) {
- bu_log("freeing sz=%zd allocation\n", sz);
-#ifdef USE_MALLOC
- free(ptr);
-#else
- bu_fastfree(ptr);
-#endif
- freecalls++;
- }
- if (i % (1024 * 1024) == 0) {
-#ifdef USE_MALLOC
- free(NULL);
-#else
- bu_fastfree(NULL);
-#endif
- freecalls++;
- }
-
- }
-
-#ifdef USE_MALLOC
- free(NULL);
-#else
- bu_fastfree(NULL);
-#endif
- freecalls++;
-
- bu_log("calls: %zd, free: %zd\n", allocalls, freecalls);
-
- return 0;
-}
-
-#endif
-
-
/* sanity */
#if HEAP_PAGESIZE < HEAP_BINS
# error "ERROR: heap page size cannot be smaller than bin range"
Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-07-27 17:53:05 UTC (rev
56259)
+++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-07-27 17:53:29 UTC (rev
56260)
@@ -236,6 +236,12 @@
add_test(bu_escape_roundtrip_3 tester_bu_escape 3 3) # "abc\\\\cba", "b"
add_test(bu_escape_roundtrip_4 tester_bu_escape 3 4) # "abc\\\\\\c\\ba\\"
+###
+# bu_heap memory allocation testing
+###
+BRLCAD_ADDEXEC(tester_bu_heap bu_heap.c libbu NO_INSTALL LOCAL)
+add_test(bu_heap_test_1 tester_bu_heap)
+
#
# ************ progname.c tests *************
#
Added: brlcad/trunk/src/libbu/tests/bu_heap.c
===================================================================
--- brlcad/trunk/src/libbu/tests/bu_heap.c (rev 0)
+++ brlcad/trunk/src/libbu/tests/bu_heap.c 2013-07-27 17:53:29 UTC (rev
56260)
@@ -0,0 +1,109 @@
+/* B U _ H E A P . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file bu_heap.c
+ *
+ * Brief description
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "bu.h"
+
+/* this should match what is in heap.c */
+#define HEAP_BINS 1024
+
+
+/*
+ * FIXME: this routine should compare heap with malloc and make sure
+ * it's always faster.
+ */
+int
+main (int ac, char *av[])
+{
+ int i;
+ void *ptr;
+ size_t allocalls = 0;
+ size_t freecalls = 0;
+
+ if (ac > 1) {
+ printf("Usage: %s\n", av[0]);
+ return 1;
+ }
+
+ srand(time(0));
+
+ for (i=0; i<1024*1024*50; i++) {
+ size_t sz = (((double)rand() / (double)(RAND_MAX-1)) *
(double)HEAP_BINS) + 1;
+ /* bu_log("allocating %d: %zd\n", i, sz); */
+#ifdef USE_MALLOC
+ ptr = malloc(sz);
+#else
+ ptr = bu_heap_get(sz);
+#endif
+ allocalls++;
+
+ if (i%3==0) {
+ /* bu_log("freeing sz=%zd allocation\n", sz); */
+#ifdef USE_MALLOC
+ free(ptr);
+#else
+ bu_heap_put(ptr, sz);
+#endif
+ freecalls++;
+ }
+ if (i % (1024 * 1024) == 0) {
+#ifdef USE_MALLOC
+ free(NULL);
+#else
+ bu_heap_put(NULL, 1);
+#endif
+ freecalls++;
+ }
+
+ }
+
+#ifdef USE_MALLOC
+ free(NULL);
+#else
+ bu_heap_put(NULL, 1);
+#endif
+ freecalls++;
+
+ /* bu_log("calls: %zd, free: %zd\n", allocalls, freecalls); */
+
+ return 0;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbu/tests/bu_heap.c
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits