Revision: 54131
http://brlcad.svn.sourceforge.net/brlcad/?rev=54131&view=rev
Author: popescuandrei
Date: 2013-01-04 08:33:45 +0000 (Fri, 04 Jan 2013)
Log Message:
-----------
added Arjun Govindjee's bu_vlb unit test
Modified Paths:
--------------
brlcad/trunk/include/bu.h
brlcad/trunk/include/pkg.h
brlcad/trunk/src/gtools/g_transfer.c
brlcad/trunk/src/libbu/htonf.c
brlcad/trunk/src/libbu/tests/CMakeLists.txt
brlcad/trunk/src/libbu/vlb.c
Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h 2013-01-03 22:15:58 UTC (rev 54130)
+++ brlcad/trunk/include/bu.h 2013-01-04 08:33:45 UTC (rev 54131)
@@ -5271,6 +5271,14 @@
BU_EXPORT extern size_t bu_vlb_buflen(struct bu_vlb *vlb);
/**
+ * Return the number of bytes allocated for the buffer of the bu_vlb structure
+ *
+ * @param vlb Pointer to the bu_vlb structure
+ * @return The number of bytes allocated for the buffer of the bu_vlb structure
+ */
+BU_EXPORT extern size_t bu_vlb_capacity(struct bu_vlb *vlb);
+
+/**
* Free the memory allocated for the byte array in the bu_vlb
* structure. Also uninitializes the structure.
*
Modified: brlcad/trunk/include/pkg.h
===================================================================
--- brlcad/trunk/include/pkg.h 2013-01-03 22:15:58 UTC (rev 54130)
+++ brlcad/trunk/include/pkg.h 2013-01-04 08:33:45 UTC (rev 54131)
@@ -107,6 +107,7 @@
/* neg->read new hdr, 0->all here, >0 ->more to come */
char *pkc_buf; /**< @brief start of dynamic
buf */
char *pkc_curpos; /**< @brief current position in
pkg_buf */
+ void *pkc_server_data; /**< @brief used to hold server
data for callbacks */
};
#define PKC_NULL ((struct pkg_conn *)0)
#define PKC_ERROR ((struct pkg_conn *)(-1L))
Modified: brlcad/trunk/src/gtools/g_transfer.c
===================================================================
--- brlcad/trunk/src/gtools/g_transfer.c 2013-01-03 22:15:58 UTC (rev
54130)
+++ brlcad/trunk/src/gtools/g_transfer.c 2013-01-04 08:33:45 UTC (rev
54131)
@@ -69,12 +69,27 @@
/* in-memory geometry database filled in by the server as it receives
* geometry from the client.
*/
-struct db_i *DBIP = NULL;
+/*
+ * Struct DBIP = null;
+ * srv_argc = 0;
+ * char **srv_argv = NULL;
+ */
+typedef struct _server_data_ {
+ struct db_i *DBIP;
+ /* used by server to stash what it should shoot at */
+ int srv_argc;
+ char **srv_argv;
+} server_data;
-/* used by server to stash what it should shoot at */
-int srv_argc = 0;
-char **srv_argv = NULL;
+server_data*
+init_srv_data () {
+ server_data *stash = bu_malloc(sizeof *stash, "server data
memory");
+ stash->DBIP = NULL;
+ stash->srv_argc = 0;
+ stash->srv_argv = NULL;
+ return stash;
+}
/** print a usage statement when invoked with bad, help, or no arguments
*/
@@ -111,18 +126,18 @@
}
void
-do_something() {
+do_something(server_data *stash) {
/* shoot a ray at some geometry just to show that we can */
struct application ap;
struct rt_i *rtip;
int i;
- if (!DBIP) {
+ if (!stash->DBIP) {
return;
}
RT_APPLICATION_INIT(&ap);
- rtip = rt_new_rti(DBIP); /* clone dbip */
+ rtip = rt_new_rti(stash->DBIP); /* clone dbip */
if (!rtip) {
bu_log("Unable to create a database instance off of the raytrace
instance\n");
return;
@@ -135,13 +150,13 @@
VSET(ap.a_ray.r_dir, 0, 0, -1);
/* shoot at any geometry specified */
- for (i = 0; i < srv_argc; i++) {
- if (rt_gettree(rtip, srv_argv[i]) != 0) {
- bu_log("Unable to validate %s for raytracing\n", srv_argv[i]);
+ for (i = 0; i < stash->srv_argc; i++) {
+ if (rt_gettree(rtip, stash->srv_argv[i]) != 0) {
+ bu_log("Unable to validate %s for raytracing\n",
stash->srv_argv[i]);
continue;
}
rt_prep(rtip);
- bu_log("Shooting at %s from (0, 0, 10000) in the (0, 0, -1)
direction\n", srv_argv[i]);
+ bu_log("Shooting at %s from (0, 0, 10000) in the (0, 0, -1)
direction\n", stash->srv_argv[i]);
(void)rt_shootray(&ap);
rt_clean(rtip);
}
@@ -161,36 +176,41 @@
void
-server_args(struct pkg_conn *UNUSED(connection), char *buf)
+server_args(struct pkg_conn *connection, char *buf)
{
/* updates the srv_argc and srv_argv application globals used to
* show that we can shoot at geometry in-memory.
*/
- srv_argc++;
- if (!srv_argv) {
- srv_argv = bu_calloc(1, srv_argc * sizeof(char *), "server_args()
srv_argv calloc");
+ server_data *stash;
+ stash = init_srv_data();
+ stash->srv_argc++;
+ if (!stash->srv_argv) {
+ stash->srv_argv = bu_calloc(1, stash->srv_argc * sizeof(char *),
"server_args() srv_argv calloc");
} else {
- srv_argv = bu_realloc(srv_argv, srv_argc * sizeof(char *),
"server_args() srv_argv realloc");
+ stash->srv_argv = bu_realloc(stash->srv_argv, stash->srv_argc *
sizeof(char *), "server_args() srv_argv realloc");
}
- srv_argv[srv_argc - 1] = bu_calloc(1, strlen(buf)+1, "server_args()
srv_argv[] calloc");
- bu_strlcpy(srv_argv[srv_argc - 1], buf, strlen(buf)+1);
+ stash->srv_argv[stash->srv_argc - 1] = bu_calloc(1, strlen(buf)+1,
"server_args() srv_argv[] calloc");
+ bu_strlcpy(stash->srv_argv[stash->srv_argc - 1], buf, strlen(buf)+1);
bu_log("Planning to shoot at %s\n", buf);
-
+ connection->pkc_server_data = stash;;
free(buf);
}
void
-server_geom(struct pkg_conn *UNUSED(connection), char *buf)
+server_geom(struct pkg_conn *connection, char *buf)
{
struct bu_external ext;
struct db5_raw_internal raw;
int flags;
- if (DBIP == NULL) {
+ server_data *stash;
+ stash =(server_data*) connection->pkc_server_data;
+
+ if (stash->DBIP == NULL) {
/* first geometry received, initialize */
- DBIP = db_open_inmem();
+ stash->DBIP = db_open_inmem();
}
if (db5_get_raw_internal_ptr(&raw, (const unsigned char *)buf) == NULL) {
@@ -206,27 +226,29 @@
ext.ext_buf = (uint8_t *)buf;
ext.ext_nbytes = raw.object_length;
flags = db_flags_raw_internal(&raw) | RT_DIR_INMEM;
- wdb_export_external(DBIP->dbi_wdbp, &ext, (const char *)raw.name.ext_buf,
flags, raw.minor_type);
+ wdb_export_external(stash->DBIP->dbi_wdbp, &ext, (const char
*)raw.name.ext_buf, flags, raw.minor_type);
bu_log("Received %s (MAJOR=%d, MINOR=%d)\n", raw.name.ext_buf,
raw.major_type, raw.minor_type);
}
void
-server_ciao(struct pkg_conn *UNUSED(connection), char *buf)
+server_ciao(struct pkg_conn* connection, char *buf)
{
+ server_data *stash;
+
bu_log("CIAO encountered\n");
-
+ stash = (server_data*) connection->pkc_server_data;
/* shoot some rays just to show that we can if server was
* invoked with specific geometry.
*/
- do_something();
+ do_something(stash);
- if (DBIP != NULL) {
+ if (stash->DBIP != NULL) {
/* uncomment to avoid an in-mem dbip close bug */
/* DBIP->dbi_fp = fopen("/dev/null", "rb");*/
- db_close(DBIP);
- DBIP = NULL;
+ db_close(stash->DBIP);
+ stash->DBIP = NULL;
}
free(buf);
Modified: brlcad/trunk/src/libbu/htonf.c
===================================================================
--- brlcad/trunk/src/libbu/htonf.c 2013-01-03 22:15:58 UTC (rev 54130)
+++ brlcad/trunk/src/libbu/htonf.c 2013-01-04 08:33:45 UTC (rev 54131)
@@ -28,78 +28,54 @@
#include "bu.h"
+/*
+ * a definition of convert_float: a function that takes a float and
+ * converts it to the format of the host/network
+ */
+HIDDEN void convert_float(register unsigned char *out, register const unsigned
char *in, size_t count)
+{
+ register size_t i;
+ assert(sizeof(float) == SIZEOF_NETWORK_FLOAT);
+ switch (bu_byteorder()) {
+ case BU_BIG_ENDIAN:
+ /*
+ * First, the case where the system already operates in
+ * IEEE format internally, using big-endian order. These
+ * are the lucky ones.
+ */
+ memcpy(out, in, count*SIZEOF_NETWORK_FLOAT);
+ return;
+ case BU_LITTLE_ENDIAN:
+ /*
+ * This machine uses IEEE, but in little-endian byte order
+ */
+ for (i=count; i > 0; i--) {
+ *out++ = in[3];
+ *out++ = in[2];
+ *out++ = in[1];
+ *out++ = in[0];
+ in += SIZEOF_NETWORK_FLOAT;
+ }
+ return;
+ default:
+ /* nada */
+ break;
+ }
+ bu_bomb("ntohf.c: ERROR, no NtoHD conversion for this machine type\n");
+}
+
void
htonf(register unsigned char *out, register const unsigned char *in, size_t
count)
{
- register size_t i;
-
- assert(sizeof(float) == SIZEOF_NETWORK_FLOAT);
-
- switch (bu_byteorder()) {
- case BU_BIG_ENDIAN:
- /*
- * First, the case where the system already operates in
- * IEEE format internally, using big-endian order. These
- * are the lucky ones.
- */
- memcpy(out, in, count*SIZEOF_NETWORK_FLOAT);
- return;
- case BU_LITTLE_ENDIAN:
- /*
- * This machine uses IEEE, but in little-endian byte order
- */
- for (i=count; i > 0; i--) {
- *out++ = in[3];
- *out++ = in[2];
- *out++ = in[1];
- *out++ = in[0];
- in += SIZEOF_NETWORK_FLOAT;
- }
- return;
- default:
- /* nada */
- break;
- }
-
- bu_bomb("ntohf.c: ERROR, no NtoHD conversion for this machine type\n");
+convert_float(out,in,count);
}
void
ntohf(register unsigned char *out, register const unsigned char *in, size_t
count)
{
- register size_t i;
-
- assert(sizeof(float) == SIZEOF_NETWORK_FLOAT);
-
- switch (bu_byteorder()) {
- case BU_BIG_ENDIAN:
- /*
- * First, the case where the system already operates in
- * IEEE format internally, using big-endian order. These
- * are the lucky ones.
- */
- memcpy(out, in, count*SIZEOF_NETWORK_FLOAT);
- return;
- case BU_LITTLE_ENDIAN:
- /*
- * This machine uses IEEE, but in little-endian byte order
- */
- for (i=count; i > 0; i--) {
- *out++ = in[3];
- *out++ = in[2];
- *out++ = in[1];
- *out++ = in[0];
- in += SIZEOF_NETWORK_FLOAT;
- }
- return;
- default:
- /* nada */
- break;
- }
-
- bu_bomb("ntohf.c: ERROR, no NtoHD conversion for this machine type\n");
+convert_float(out,in,count);
}
/*
Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-01-03 22:15:58 UTC (rev
54130)
+++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2013-01-04 08:33:45 UTC (rev
54131)
@@ -355,6 +355,32 @@
add_test(bu_vls_vprintf_test_56 tester_bu_vls_vprintf 56)
add_test(bu_vls_vprintf_test_57 tester_bu_vls_vprintf 57)
+#
+# ************ vlb.c tests *************
+#
+# For tester_bu_vlb the format is:
+#
+# tester_bu_vlb [-i initSize] size ...
+#
+# Where size is the size of a memory block to be added to the array
+# The blocks will be allocated sequentially and filled with random data.
+#
+# Adding the -i option will specify an initial size to be allocated when the
buffer is initialized.
+
+BRLCAD_ADDEXEC(tester_bu_vlb bu_vlb.c libbu NO_INSTALL LOCAL)
+
+add_test(bu_vlb_test_single tester_bu_vlb 1)
+add_test(bu_vlb_test_twice_single tester_bu_vlb 1 1)
+add_test(bu_vlb_test_3 tester_bu_vlb 1 2 3)
+add_test(bu_vlb_test_larger tester_bu_vlb 10 30)
+add_test(bu_vlb_test_very_large tester_bu_vlb 1000 2000 3000 4000
5000)
+add_test(bu_vlb_test_very_large_2 tester_bu_vlb 5000 4000 3000 2000 1000)
+add_test(bu_vlb_test_boundary_alloc tester_bu_vlb 511 1 1 256 255 512 1024)
+add_test(bu_vlb_test_many_writes tester_bu_vlb 128 128 128 128 128 128 128
128 128 128 128 128 128 128 128 128)
+
+add_test(bu_vlb_test_large_init tester_bu_vlb -i 2048 1000 2000
3000 4000)
+add_test(bu_vlb_test_large_init_2 tester_bu_vlb -i 6500 4000 3000 2000 1000)
+
# Local Variables:
# tab-width: 8
# mode: cmake
Modified: brlcad/trunk/src/libbu/vlb.c
===================================================================
--- brlcad/trunk/src/libbu/vlb.c 2013-01-03 22:15:58 UTC (rev 54130)
+++ brlcad/trunk/src/libbu/vlb.c 2013-01-04 08:33:45 UTC (rev 54131)
@@ -99,7 +99,14 @@
return vlb->nextByte;
}
+size_t
+bu_vlb_capacity(struct bu_vlb *vlb)
+{
+ BU_CKMAG(vlb, BU_VLB_MAGIC, "magic for bu_vlb");
+ return vlb->bufCapacity;
+}
+
void
bu_vlb_free(struct bu_vlb *vlb)
{
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits