diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5eae512 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: required + +language: cpp # we run all tests in docker container so this can be anything + +services: + - docker + +before_install: + - make -C tai_mux docker-image + +script: + - TAI_DOCKER_CMD='make test' make -C tai_mux cmd diff --git a/tai_mux/Makefile b/tai_mux/Makefile index 5ad3616..0034bb7 100644 --- a/tai_mux/Makefile +++ b/tai_mux/Makefile @@ -12,6 +12,10 @@ ifndef TAI_META_LIBRARY TAI_META_LIBRARY := $(TAI_DIR)/meta/libmetatai.so endif +ifndef TAI_DOCKER_CMD + TAI_DOCKER_CMD := bash +endif + CFLAGS := -std=c++17 -g3 -shared -fPIC -DTAI_EXPOSE_PLATFORM -fno-gnu-unique INCLUDES := -I $(TAI_DIR)/inc -I $(TAI_DIR)/meta -I $(TAI_LIB_DIR) -include mux.hpp @@ -36,8 +40,23 @@ $(BUILDDIR)/%.o: %.cpp Makefile -include $(DEPS) +test: + $(MAKE) -C tests + +cmd: + TAI_DOCKER_CMD="$(TAI_DOCKER_CMD)" TAI_DOCKER_RUN_OPTION="--privileged --net=host -it --rm" TAI_DOCKER_MOUNT="`pwd`:/data" $(MAKE) -C $(TAI_DIR) $@ + +docker: + TAI_DOCKER_CMD="make" $(MAKE) cmd + +docker-image: + $(MAKE) -C $(TAI_DIR) $@ + +bash: + $(MAKE) cmd + clean: $(RM) -r $(BUILDDIR) $(TARGET) -bash: - TAI_DOCKER_RUN_OPTION="--privileged --net=host -it --rm" TAI_DOCKER_MOUNT="`pwd`:/data" $(MAKE) -C $(TAI_DIR) $@ +clean-all: clean + $(MAKE) -C $(TAI_DIR) clean diff --git a/tai_mux/oopt-tai b/tai_mux/oopt-tai index e2c0bbe..750b681 160000 --- a/tai_mux/oopt-tai +++ b/tai_mux/oopt-tai @@ -1 +1 @@ -Subproject commit e2c0bbeabc0e5ebfba1fc2c0fbe5e164eb9d033c +Subproject commit 750b6811828bae1eeba8770eabfe9bfef15f7c02 diff --git a/tai_mux/test/Makefile b/tai_mux/test/Makefile deleted file mode 100644 index 1b7dd78..0000000 --- a/tai_mux/test/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC := g++ -CFLAGS := -std=c++11 -INCLUDES := -I ../oopt-tai/inc - -test: test.cpp libtai.so libtai-stub.so libmetatai.so - $(CC) $(CFLAGS) $(INCLUDES) $^ -o $@ -L . -ltai -L ../oopt-tai/meta -lmetatai - -libtai.so: - ln -s ../libtai-mux.so $@ - -libmetatai.so: - $(MAKE) -C ../oopt-tai/meta/ - ln -s ../oopt-tai/meta/$@ $@ - -libtai-stub.so: - $(MAKE) -C ../oopt-tai/stub/ - ln -s ../oopt-tai/stub/libtai.so $@ - -clean: - -rm test diff --git a/tai_mux/test/run.sh b/tai_mux/test/run.sh deleted file mode 100755 index 4520522..0000000 --- a/tai_mux/test/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -LD_LIBRARY_PATH=. TAI_MUX_PLATFORM_ADAPTER=static TAI_MUX_STATIC_CONFIG_FILE=./static.json $1 ./test diff --git a/tai_mux/test/static.json b/tai_mux/test/static.json deleted file mode 100644 index 55e6909..0000000 --- a/tai_mux/test/static.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "1": "libtai-stub.so", - "2": "libtai-stub.so" -} diff --git a/tai_mux/test/test.cpp b/tai_mux/test/test.cpp deleted file mode 100644 index 5417163..0000000 --- a/tai_mux/test/test.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "unistd.h" - -#include "tai.h" - -tai_module_api_t *module_api; -tai_network_interface_api_t *netif_api; -tai_host_interface_api_t *hostif_api; - -int fd; -std::queue> q; -std::mutex m; - -class module { - public: - module(tai_object_id_t id) : m_id(id) { - std::vector list; - tai_attribute_t attr; - attr.id = TAI_MODULE_ATTR_NUM_HOST_INTERFACES; - list.push_back(attr); - attr.id = TAI_MODULE_ATTR_NUM_NETWORK_INTERFACES; - list.push_back(attr); - auto status = module_api->get_module_attributes(id, list.size(), list.data()); - if ( status != TAI_STATUS_SUCCESS ) { - throw std::runtime_error("faile to get attribute"); - } - std::cout << "num hostif: " << list[0].value.u32 << std::endl; - std::cout << "num netif: " << list[1].value.u32 << std::endl; - create_hostif(list[0].value.u32); - create_netif(list[1].value.u32); - } - private: - tai_object_id_t m_id; - std::vector netifs; - std::vector hostifs; - int create_hostif(uint32_t num); - int create_netif(uint32_t num); -}; - -int module::create_netif(uint32_t num) { - for ( int i = 0; i < num; i++ ) { - tai_object_id_t id; - std::vector list; - tai_attribute_t attr; - attr.id = TAI_NETWORK_INTERFACE_ATTR_INDEX; - attr.value.u32 = i; - list.push_back(attr); - auto status = netif_api->create_network_interface(&id, m_id, list.size(), list.data()); - if ( status != TAI_STATUS_SUCCESS ) { - throw std::runtime_error("failed to create network interface"); - } - std::cout << "netif: " << id << std::endl; - netifs.push_back(id); - - list.clear(); - - attr.id = TAI_NETWORK_INTERFACE_ATTR_TX_DIS; - attr.value.booldata = false; - list.push_back(attr); - - attr.id = TAI_NETWORK_INTERFACE_ATTR_TX_LASER_FREQ; - attr.value.u64 = 191300000000000; - list.push_back(attr); - - attr.id = TAI_NETWORK_INTERFACE_ATTR_TX_GRID_SPACING; - attr.value.u32 = TAI_NETWORK_INTERFACE_TX_GRID_SPACING_100_GHZ; - list.push_back(attr); - - attr.id = TAI_NETWORK_INTERFACE_ATTR_MODULATION_FORMAT; - attr.value.u32 = TAI_NETWORK_INTERFACE_MODULATION_FORMAT_DP_16_QAM; - list.push_back(attr); - - status = netif_api->set_network_interface_attributes(id, list.size(), list.data()); - if ( status != TAI_STATUS_SUCCESS ) { - throw std::runtime_error("failed to set netif attribute"); - } - } - return 0; -} - -int module::create_hostif(uint32_t num) { - for ( int i = 0; i < num; i++ ) { - tai_object_id_t id; - std::vector list; - tai_attribute_t attr; - attr.id = TAI_HOST_INTERFACE_ATTR_INDEX; - attr.value.u32 = i; - list.push_back(attr); - auto status = hostif_api->create_host_interface(&id, m_id, list.size(), list.data()); - if ( status != TAI_STATUS_SUCCESS ) { - throw std::runtime_error("failed to create host interface"); - } - std::cout << "hostif: " << id << std::endl; - hostifs.push_back(id); - } - return 0; -} - -std::map modules; - -void module_presence(bool present, char* location) { - uint64_t v; - std::lock_guard g(m); - q.push(std::pair(present, std::string(location))); - write(fd, &v, sizeof(uint64_t)); -} - -tai_status_t create_module(const std::string& location, tai_object_id_t& m_id) { - std::vector list; - tai_attribute_t attr; - attr.id = TAI_MODULE_ATTR_LOCATION; - attr.value.charlist.count = location.size(); - attr.value.charlist.list = (char*)location.c_str(); - list.push_back(attr); - return module_api->create_module(&m_id, list.size(), list.data()); -} - -int main() { - tai_log_set(tai_api_t(0), TAI_LOG_LEVEL_INFO); - - tai_service_method_table_t services; - - fd = eventfd(0, 0); - - services.module_presence = module_presence; - - auto status = tai_api_initialize(0, &services); - if ( status != TAI_STATUS_SUCCESS ) { - std::cout << "failed to init" << std::endl; - return 1; - } - - status = tai_api_query(TAI_API_MODULE, (void **)(&module_api)); - if ( status != TAI_STATUS_SUCCESS ) { - return 1; - } - - status = tai_api_query(TAI_API_NETWORKIF, (void **)(&netif_api)); - if ( status != TAI_STATUS_SUCCESS ) { - return 1; - } - - status = tai_api_query(TAI_API_HOSTIF, (void **)(&hostif_api)); - if ( status != TAI_STATUS_SUCCESS ) { - return 1; - } - - while (true) { - uint64_t v; - read(fd, &v, sizeof(uint64_t)); - { - std::lock_guard g(m); - while ( ! q.empty() ) { - auto p = q.front(); - std::cout << "present: " << p.first << ", loc: " << p.second << std::endl; - if ( p.first ) { - tai_object_id_t m_id = 0; - status = create_module(p.second, m_id); - if ( status != TAI_STATUS_SUCCESS ) { - std::cerr << "failed to create module: " << status << std::endl; - return 1; - } - std::cout << "module id: " << m_id << std::endl; - modules[m_id] = new module(m_id); - } - q.pop(); - } - } - } -} diff --git a/tai_mux/tests/Makefile b/tai_mux/tests/Makefile new file mode 100644 index 0000000..85a5505 --- /dev/null +++ b/tai_mux/tests/Makefile @@ -0,0 +1,16 @@ +ifndef TAI_DIR + TAI_DIR := ../oopt-tai +endif + +ifndef TAI_LIB_DIR + TAI_LIB_DIR := $(TAI_DIR)/tools/framework +endif + +all: ../libtai.so static.json $(TAI_LIB_DIR)/examples/basic/libtai.so + TAI_MUX_STATIC_CONFIG_FILE=$(abspath static.json) TAI_TEST_TARGET=$(abspath ../libtai.so) $(MAKE) -C $(TAI_DIR)/tests + +../libtai.so: + $(MAKE) -C $(@D) + +$(TAI_LIB_DIR)/examples/basic/libtai.so: + $(MAKE) -C $(@D) diff --git a/tai_mux/tests/static.json b/tai_mux/tests/static.json new file mode 100644 index 0000000..66b6598 --- /dev/null +++ b/tai_mux/tests/static.json @@ -0,0 +1,3 @@ +{ + "0": "../tools/framework/examples/basic/libtai.so" +}