1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/dist/testbed-support/Makefile.iotlab

106 lines
4.2 KiB
Makefile

.PHONY: iotlab-exp iotlab-flash iotlab-reset iotlab-term iotlab-check-exp
# There are several deprecated features used here and introduced between
# versions 2 and 3 of the IoT-LAB cli tools.
# For backward compatibility, we manage these changes here.
_CLI_TOOLS_MAJOR_VERSION ?= $(shell iotlab-experiment --version | cut -f1 -d.)
ifeq (2,$(_CLI_TOOLS_MAJOR_VERSION))
_NODES_LIST_OPTION = --resources
_NODES_ID_LIST_OPTION = --resources-id
_NODES_FLASH_OPTION = --update
else
_NODES_LIST_OPTION = --nodes
_NODES_ID_LIST_OPTION = --nodes-id
_NODES_FLASH_OPTION = --flash
endif
IOTLAB_NODES ?= 5
IOTLAB_DURATION ?= 30
IOTLAB_TYPE ?= m3:at86rf231
IOTLAB_AUTH ?= $(HOME)/.iotlabrc
IOTLAB_USER ?= $(shell cut -f1 -d: $(IOTLAB_AUTH))
IOTLAB_EXP_ID ?= $(shell iotlab-experiment get -l --state Running | grep -m 1 '"id"' | grep -Eo '[[:digit:]]+')
IOTLAB_EXP_NAME ?= RIOT_EXP
IOTLAB_DEBUG_PORT ?= 3333
IOTLAB_DEBUG_NODE ?= $(shell iotlab-experiment get -i $(IOTLAB_EXP_ID) $(_NODES_LIST_OPTION) | \
grep -m 1 "network_address" | sed 's/.*-\([0-9]*\)\..*/\1/')
IOTLAB_AUTHORITY = "$(IOTLAB_USER)@$(IOTLAB_SITE).iot-lab.info"
ifeq (,$(filter iotlab-exp,$(MAKECMDGOALS)))
# derive experiment site from IOTLAB_EXP_ID, if not given and not used with
# `iotlab_exp`
IOTLAB_SITE ?= $(shell iotlab-experiment --format=str --jmespath "keys(items[0])[0]" \
get $(_NODES_ID_LIST_OPTION) -i $(IOTLAB_EXP_ID))
endif
ifneq (,$(findstring m3,$(IOTLAB_TYPE)))
BINARY := $(ELFFILE)
else
BINARY := $(HEXFILE)
endif
ifdef IOTLAB_PHY_NODES
NODES_PARAM_BASE = -l$(IOTLAB_SITE),$(firstword $(subst :, ,$(IOTLAB_TYPE))),$(IOTLAB_PHY_NODES)
NODES_PARAM = "$(NODES_PARAM_BASE),$(BINARY),$(IOTLAB_PROFILE)"
endif
ifdef IOTLAB_EXCLUDE_NODES
EXCLUDE_PARAM := "-e$(IOTLAB_SITE),$(firstword $(subst :, ,$(IOTLAB_TYPE))),$(IOTLAB_EXCLUDE_NODES)"
endif
$(IOTLAB_AUTH):
iotlab-auth -u $(IOTLAB_USER)
iotlab-exp: $(IOTLAB_AUTH) all
$(eval IOTLAB_SITE ?= grenoble)
ifneq (RIOT_EXP,$(IOTLAB_EXP_NAME))
$(eval IOTLAB_EXP_NAME := RIOT_EXP_$(IOTLAB_EXP_NAME))
endif
ifndef NODES_PARAM
$(eval NODES_PARAM := "-l$(IOTLAB_NODES),archi=$(IOTLAB_TYPE)+site=$(IOTLAB_SITE),$(BINARY),$(IOTLAB_PROFILE)")
endif
ifeq (,$(Q))
@echo "iotlab-experiment submit -d $(IOTLAB_DURATION) $(NODES_PARAM) -n $(IOTLAB_EXP_NAME)"
endif
$(eval NEW_ID := $(shell iotlab-experiment submit -d $(IOTLAB_DURATION) $(NODES_PARAM) -n $(IOTLAB_EXP_NAME) | grep -Eo '[[:digit:]]+'))
$(Q)iotlab-experiment wait -i $(NEW_ID)
ifdef IOTLAB_LOGGING
$(Q)ssh -t $(IOTLAB_AUTHORITY) \
"$(if $(IOTLAB_TMUX),tmux new -d -s riot-$(NEW_ID),) \
'script -fac "'"'"serial_aggregator -i $(NEW_ID)"'"'"\
RIOT_LOG-$(IOTLAB_EXP_NAME)-$(NEW_ID)'"
endif
iotlab-flash: $(IOTLAB_AUTH) all
$(Q)iotlab-node $(_NODES_FLASH_OPTION) $(BINARY) -i $(IOTLAB_EXP_ID) $(NODES_PARAM_BASE) $(EXCLUDE_PARAM)
iotlab-reset: $(IOTLAB_AUTH)
$(Q)iotlab-node --reset -i $(IOTLAB_EXP_ID) $(NODES_PARAM_BASE) $(EXCLUDE_PARAM)
iotlab-debug-server: $(IOTLAB_AUTH)
$(eval DEBUG_TYPE := $(shell echo $(IOTLAB_TYPE) | cut -d: -f1))
$(eval DEBUG_NODE := $(shell echo $(IOTLAB_DEBUG_NODE) | sed 's/$(DEBUG_TYPE)-\([0-9]*\)/\1/'))
$(Q)iotlab-node --debug-start -i $(IOTLAB_EXP_ID) -l $(IOTLAB_SITE),$(DEBUG_TYPE),$(DEBUG_NODE)
@echo "Debug on node $(IOTLAB_DEBUG_NODE)"
$(Q)ssh -N -L $(IOTLAB_DEBUG_PORT):$(IOTLAB_DEBUG_NODE):3333 $(IOTLAB_AUTHORITY)
iotlab-stop: $(IOTLAB_AUTH)
$(Q)iotlab-experiment stop -i $(IOTLAB_EXP_ID)
# wait for flash if it is provided e.g. with `make iotlab-flash iotlab-term`
IOTLABTERMFLASHDEPS ?= $(filter iotlab-flash iotlab-exp,$(MAKECMDGOALS))
iotlab-term: $(IOTLABTERMFLASHDEPS)
$(Q)ssh -t $(IOTLAB_AUTHORITY) "iotlab-experiment get -i $(IOTLAB_EXP_ID) --print > /dev/null || iotlab-auth -u $(IOTLAB_USER)"
$(Q)ssh -t $(IOTLAB_AUTHORITY) \
"$(if $(IOTLAB_TMUX),tmux attach -t riot-$(IOTLAB_EXP_ID) || tmux new -s riot-$(IOTLAB_EXP_ID) ',) \
$(if $(IOTLAB_LOGGING), \
script -fac "'"'"serial_aggregator -i $(IOTLAB_EXP_ID) $(NODES_PARAM_BASE)"'"'" \
RIOT_LOG-$(IOTLAB_EXP_NAME)-$(IOTLAB_EXP_ID), \
serial_aggregator -i $(IOTLAB_EXP_ID) $(NODES_PARAM_BASE))$(if $(IOTLAB_TMUX),',)"