From 5c3b39340d365f5ff37a79424956591e87b44816 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 26 Jun 2018 12:58:54 -0400 Subject: init --- test/.gitignore | 1 + test/CMakeLists.txt | 24 +++++++ test/Makefile | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_msg.cpp | 74 +++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 test/.gitignore create mode 100644 test/CMakeLists.txt create mode 100644 test/Makefile create mode 100644 test/test_msg.cpp (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..4cdad0d --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +test_msg diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..423229b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2018 Cornell University. +# +# Author: Ted Yin +# +# 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. + +add_executable(test_msg test_msg.cpp) +target_link_libraries(test_msg salticidae) diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..173f653 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,180 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.11 + +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/ymf/work/hot-stuff/code/salticidae + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/ymf/work/hot-stuff/code/salticidae + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# The main all target +all: cmake_check_build_system + cd /home/ymf/work/hot-stuff/code/salticidae && $(CMAKE_COMMAND) -E cmake_progress_start /home/ymf/work/hot-stuff/code/salticidae/CMakeFiles /home/ymf/work/hot-stuff/code/salticidae/test/CMakeFiles/progress.marks + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f CMakeFiles/Makefile2 test/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/ymf/work/hot-stuff/code/salticidae/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f CMakeFiles/Makefile2 test/clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f CMakeFiles/Makefile2 test/preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f CMakeFiles/Makefile2 test/preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + cd /home/ymf/work/hot-stuff/code/salticidae && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +# Convenience name for target. +test/CMakeFiles/test_msg.dir/rule: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f CMakeFiles/Makefile2 test/CMakeFiles/test_msg.dir/rule +.PHONY : test/CMakeFiles/test_msg.dir/rule + +# Convenience name for target. +test_msg: test/CMakeFiles/test_msg.dir/rule + +.PHONY : test_msg + +# fast build rule for target. +test_msg/fast: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f test/CMakeFiles/test_msg.dir/build.make test/CMakeFiles/test_msg.dir/build +.PHONY : test_msg/fast + +test_msg.o: test_msg.cpp.o + +.PHONY : test_msg.o + +# target to build an object file +test_msg.cpp.o: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f test/CMakeFiles/test_msg.dir/build.make test/CMakeFiles/test_msg.dir/test_msg.cpp.o +.PHONY : test_msg.cpp.o + +test_msg.i: test_msg.cpp.i + +.PHONY : test_msg.i + +# target to preprocess a source file +test_msg.cpp.i: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f test/CMakeFiles/test_msg.dir/build.make test/CMakeFiles/test_msg.dir/test_msg.cpp.i +.PHONY : test_msg.cpp.i + +test_msg.s: test_msg.cpp.s + +.PHONY : test_msg.s + +# target to generate assembly for a file +test_msg.cpp.s: + cd /home/ymf/work/hot-stuff/code/salticidae && $(MAKE) -f test/CMakeFiles/test_msg.dir/build.make test/CMakeFiles/test_msg.dir/test_msg.cpp.s +.PHONY : test_msg.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... rebuild_cache" + @echo "... test_msg" + @echo "... edit_cache" + @echo "... test_msg.o" + @echo "... test_msg.i" + @echo "... test_msg.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + cd /home/ymf/work/hot-stuff/code/salticidae && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/test/test_msg.cpp b/test/test_msg.cpp new file mode 100644 index 0000000..2d039e4 --- /dev/null +++ b/test/test_msg.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2018 Cornell University. + * + * Author: Ted Yin + * + * 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 "salticidae/msg.h" + +using salticidae::uint256_t; +using salticidae::DataStream; +using salticidae::get_hash; +using salticidae::get_hex; + +struct MsgTest: public salticidae::MsgBase<> { + void gen_testhashes(int cnt) { + DataStream s; + set_opcode(0x01); + s << (uint32_t)cnt; + for (int i = 0; i < cnt; i++) + { + uint256_t hash = get_hash(i); + printf("adding hash %s\n", get_hex(hash).c_str()); + s << hash; + } + set_payload(std::move(s)); + } + + void parse_testhashes() { + DataStream s(get_payload()); + uint32_t cnt; + s >> cnt; + printf("got %d hashes\n", cnt); + for (int i = 0; i < cnt; i++) + { + uint256_t hash; + s >> hash; + printf("got hash %s\n", get_hex(hash).c_str()); + } + } +}; + +int main() { + MsgTest msg; + msg.gen_ping(1234); + printf("%s\n", std::string(msg).c_str()); + msg.gen_testhashes(5); + printf("%s\n", std::string(msg).c_str()); + msg.parse_testhashes(); + try + { + msg.parse_testhashes(); + } catch (std::runtime_error &e) { + printf("caught: %s\n", e.what()); + } + return 0; +} -- cgit v1.2.3