Skip to content
Browse files

Fixed a problem in the 'test' command. Added the 'btreetest' target t…

…o the makefile.
  • Loading branch information...
1 parent dcd0422 commit 1b37ff5cdc320aa8d3edfde8f0f08c5b68f70d8e @darconeous committed Jun 16, 2012
Showing with 123 additions and 31 deletions.
  1. +5 −1 Makefile
  2. +1 −0 README.md
  3. +4 −0 SMCP.xcodeproj/project.pbxproj
  4. +90 −0 src/smcp/btree.c
  5. +1 −1 src/smcp/smcp-opts.h
  6. +2 −1 src/smcp/smcp-pairing.c
  7. +20 −28 src/smcpctl/cmd_test.c
View
6 Makefile
@@ -47,8 +47,12 @@ SMCPCTL_OBJECT_FILES=${addprefix $(SMCPCTL_SOURCE_PATH)/,${subst .c,.o,$(SMCPCTL
smcpctl: $(SMCPCTL_OBJECT_FILES) $(SMCP_OBJECT_FILES)
$(CXX) -o $@ $+ -lpthread $(LFLAGS)
+btreetest: src/smcp/btree.c
+ $(CC) -o $@ $+ -Wall -DBTREE_SELF_TEST=1
+ ./btreetest
+
clean:
- $(RM) $(SMCPCTL_OBJECT_FILES) $(SMCP_OBJECT_FILES) smcpctl
+ $(RM) $(SMCPCTL_OBJECT_FILES) $(SMCP_OBJECT_FILES) smcpctl btreetest
install: smcpctl
$(INSTALL) smcpctl $(PREFIX)/bin
View
1 README.md
@@ -12,6 +12,7 @@ environments. Features include:
URLs when a value chagnes.
* Supports retransmission of confirmable packets.
* CoAP-to-HTTP proxy, based on CuRL (incomplete, but kinda working)
+ * Supports more than 14 options in the header.
Features which are in progress:
View
4 SMCP.xcodeproj/project.pbxproj
@@ -50,6 +50,8 @@
/* Begin PBXFileReference section */
8DD76FB20486AB0100D96B5E /* smcpctl */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = smcpctl; sourceTree = BUILT_PRODUCTS_DIR; };
+ A60BF11B158D425F00D39B5C /* COPYING */ = {isa = PBXFileReference; lastKnownFileType = text; path = COPYING; sourceTree = "<group>"; };
+ A60BF11C158D425F00D39B5C /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
A61C873C1583C79400AFD8A1 /* sensor-node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "sensor-node.c"; sourceTree = "<group>"; };
A61C873E1583C79E00AFD8A1 /* sensor-node.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "sensor-node.h"; sourceTree = "<group>"; };
A61C873F1583C7AA00AFD8A1 /* led-node.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "led-node.h"; sourceTree = "<group>"; };
@@ -276,6 +278,8 @@
isa = PBXGroup;
children = (
C6A0FF2C0290799A04C91782 /* smcpctl.1 */,
+ A60BF11B158D425F00D39B5C /* COPYING */,
+ A60BF11C158D425F00D39B5C /* README.md */,
);
name = Documentation;
sourceTree = "<group>";
View
90 src/smcp/btree.c
@@ -640,6 +640,96 @@ main(void) {
reverse_traversal_test(root);
// Cleanup.
+ printf("Removing all nodes...\n");
+ while(root)
+ bt_remove((void**)&root,
+ root,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ printf("Adding more nodes...\n");
+ {
+ self_test_node_t new_node;
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, "proxy");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, ".p");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, "device");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, "timer");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, "async_response");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+
+ new_node = calloc(sizeof(struct self_test_node_s),1);
+ asprintf(&new_node->name, "lots_of_devices");
+ nodes_alive++;
+ bt_insert(
+ (void**)&root,
+ new_node,
+ (bt_compare_func_t)&self_test_node_compare,
+ (bt_delete_func_t)&self_test_node_delete,
+ &nodes_alive
+ );
+ }
+
+ forward_traversal_test(root);
+ reverse_traversal_test(root);
+
+ i = bt_rebalance((void**)&root);
+ printf("Rebalance operation took %u rotations\n", i);
+
+ forward_traversal_test(root);
+ reverse_traversal_test(root);
+
+ // Cleanup.
while(root)
bt_remove((void**)&root,
root,
View
2 src/smcp/smcp-opts.h
@@ -91,7 +91,7 @@
#endif
#ifndef SMCP_ADD_NEWLINES_TO_LIST_OUTPUT
-#define SMCP_ADD_NEWLINES_TO_LIST_OUTPUT 0
+#define SMCP_ADD_NEWLINES_TO_LIST_OUTPUT DEBUG
#endif
#ifndef SMCP_AVOID_PRINTF
View
3 src/smcp/smcp-pairing.c
@@ -521,6 +521,7 @@ smcp_trigger_event(
DEBUG_PRINTF("Event:%p: retain",event);
#if SMCP_CONF_PAIRING_STATS
+ // TODO: Trigger an event on the fire count, too?
iter->fire_count++;
#endif
}
@@ -764,7 +765,7 @@ smcp_pairing_path_request_handler(
uri[value_len] = 0;
}
- require_action(uri!=NULL,bail,"URI must be set by this point");
+ require_string(uri!=NULL,bail,"URI must be set by this point");
ret = smcp_pair_with_uri(
self,
View
48 src/smcpctl/cmd_test.c
@@ -242,11 +242,8 @@ tool_cmd_test(
smcp_t smcp;
smcp_t smcp2;
- //struct smcp_node_s device_node = {};
struct smcp_timer_node_s timer_node = {};
struct smcp_variable_node_s device_node = {};
- //struct smcp_variable_node_s action_node = {};
-// struct smcp_node_s sliced_post_node = {};
struct smcp_node_s async_response_node = {};
smcp2 = smcp_create(12345);
@@ -255,6 +252,8 @@ tool_cmd_test(
else
smcp = smcp_create(SMCP_DEFAULT_PORT);
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
#if HAS_LIBCURL
struct smcp_curl_proxy_node_s proxy_node = {};
curl_global_init(CURL_GLOBAL_ALL);
@@ -268,6 +267,8 @@ tool_cmd_test(
);
#endif
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
smcp_pairing_init(
smcp_get_root_node(smcp),
SMCP_PAIRING_DEFAULT_ROOT_PATH
@@ -278,55 +279,40 @@ tool_cmd_test(
SMCP_PAIRING_DEFAULT_ROOT_PATH
);
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
smcp_node_init_variable(
&device_node,
smcp_get_root_node(smcp),
"device"
);
device_node.func = device_func;
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
smcp_node_init_variable(
- &device_node,
+ NULL,
smcp_get_root_node(smcp2),
"device"
)->func = device_func;
-// smcp_node_init(
-// (smcp_node_t)&device_node,
-// smcp_get_root_node(smcp),
-// "device"
-// );
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
- smcp_timer_node_init(&timer_node,
+ smcp_timer_node_init(
+ &timer_node,
smcp_get_root_node(smcp),
"timer"
);
-// smcp_node_init((smcp_node_t)&sliced_post_node,
-// &device_node,
-// "sliced_post"
-// );
-// sliced_post_node.request_handler = &sliced_post_request_handler;
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
smcp_node_init((smcp_node_t)&async_response_node,
smcp_get_root_node(smcp),
"async_response"
);
async_response_node.request_handler = &async_request_handler;
-// smcp_node_init_variable(
-// &var_node,
-// (smcp_node_t)&device_node,
-// "loadavg"
-// );
-// var_node.get_func = loadavg_get_func;
-//
-// smcp_node_init_variable(
-// &action_node,
-// smcp_get_root_node(smcp2),
-// "action"
-// );
-// action_node.post_func = (void*)action_func;
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
#if 1
{
@@ -354,6 +340,8 @@ tool_cmd_test(
}
#endif
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
// Just adding some random nodes so we can browse thru them with another process...
{
smcp_node_t subdevice = smcp_node_init(NULL,
@@ -391,6 +379,8 @@ tool_cmd_test(
}
}
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
{
coap_transaction_id_t tid = smcp_get_next_tid(smcp2,NULL);
@@ -426,6 +416,8 @@ tool_cmd_test(
fprintf(stderr, " *** Sent LIST request...\n");
}
+ //printf(__FILE__":%d: root node child count = %d\n",__LINE__,(int)bt_count(&smcp_get_root_node(smcp)->children));
+
int i;
for(i = 0; i < 3000000; i++) {
#if 1

0 comments on commit 1b37ff5

Please sign in to comment.
Something went wrong with that request. Please try again.